|
@@ -0,0 +1,110 @@
|
|
|
+package com.miaxis.extension.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.miaxis.common.core.domain.Response;
|
|
|
+import com.miaxis.common.core.domain.entity.SysDictData;
|
|
|
+import com.miaxis.extension.domain.WxExtensionIncome;
|
|
|
+import com.miaxis.extension.mapper.WxExtensionIncomeMapper;
|
|
|
+import com.miaxis.extension.service.IWxExtensionIncomeService;
|
|
|
+import com.miaxis.spread.domain.WxSpreadRelation;
|
|
|
+import com.miaxis.spread.service.IWxSpreadRelationService;
|
|
|
+import com.miaxis.system.service.ISysDictDataService;
|
|
|
+import com.miaxis.system.service.ISysDictTypeService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分成收益Service业务层处理
|
|
|
+ * @author wwl
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2021/11/4 14:38
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class WxExtensionIncomeServiceImpl extends ServiceImpl<WxExtensionIncomeMapper, WxExtensionIncome> implements IWxExtensionIncomeService {
|
|
|
+
|
|
|
+
|
|
|
+ private final WxExtensionIncomeMapper wxExtensionIncomeMapper;
|
|
|
+
|
|
|
+ private final IWxSpreadRelationService wxSpreadRelationService;
|
|
|
+
|
|
|
+ private final ISysDictTypeService dictTypeService;
|
|
|
+
|
|
|
+ private final ISysDictDataService dictDataService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询分成收益列表
|
|
|
+ *
|
|
|
+ * @param wxExtensionIncome 分成收益
|
|
|
+ * @return 分成收益
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<WxExtensionIncome> selectWxExtensionIncomeList(WxExtensionIncome wxExtensionIncome){
|
|
|
+ return wxExtensionIncomeMapper.selectWxExtensionIncomeList(wxExtensionIncome);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增收益信息
|
|
|
+ * @param sourceId 订单id
|
|
|
+ * @param sourceOpenid 用户openid
|
|
|
+ * @param sourcePrice 订单金额
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Response addExtensionIncomeBySourceId(Long sourceId, String sourceOpenid, BigDecimal sourcePrice) {
|
|
|
+
|
|
|
+ //查找一二级绑定关系
|
|
|
+ WxSpreadRelation oneRelation = wxSpreadRelationService.getOne(new QueryWrapper<WxSpreadRelation>().eq("openid", sourceOpenid));
|
|
|
+ if (oneRelation == null){
|
|
|
+ log.info(sourceOpenid+": 此用户不存在绑定关系");
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ WxSpreadRelation twoRelation = wxSpreadRelationService.getOne(new QueryWrapper<WxSpreadRelation>().eq("openid", oneRelation.getParentOpenid()));
|
|
|
+
|
|
|
+ //根据字典获取分成百分比
|
|
|
+ List<SysDictData> dictDatas = dictTypeService.selectDictDataByType("sys_divide_percent");
|
|
|
+
|
|
|
+ List<WxExtensionIncome> extensionIncomes = new ArrayList<>();
|
|
|
+ dictDatas.forEach(d -> {
|
|
|
+ if ("一级".equals(d.getDictLabel())){
|
|
|
+ BigDecimal decimal = BigDecimal.valueOf(Double.parseDouble(d.getDictValue()));//百分比
|
|
|
+ WxExtensionIncome income = new WxExtensionIncome();
|
|
|
+ income.setSourceId(sourceId);
|
|
|
+ income.setBeneficiaryOpenid(oneRelation.getParentOpenid());
|
|
|
+ income.setSourceOpenid(sourceOpenid);
|
|
|
+ income.setHierarchy("1");
|
|
|
+ income.setPercentage(decimal);
|
|
|
+ income.setProfitPrice(sourcePrice.multiply(decimal));
|
|
|
+ extensionIncomes.add(income);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (twoRelation != null){
|
|
|
+ if ("二级".equals(d.getDictLabel())){
|
|
|
+ BigDecimal decimal = BigDecimal.valueOf(Double.parseDouble(d.getDictValue()));//百分比
|
|
|
+ WxExtensionIncome income = new WxExtensionIncome();
|
|
|
+ income.setSourceId(sourceId);
|
|
|
+ income.setBeneficiaryOpenid(twoRelation.getParentOpenid());
|
|
|
+ income.setSourceOpenid(sourceOpenid);
|
|
|
+ income.setHierarchy("2");
|
|
|
+ income.setPercentage(decimal);
|
|
|
+ income.setProfitPrice(sourcePrice.multiply(decimal));
|
|
|
+ extensionIncomes.add(income);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //保存分成收益信息
|
|
|
+ this.saveBatch(extensionIncomes);
|
|
|
+
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|