| | |
| | | import cc.mrbird.febs.mall.service.IMemberProfitService; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateField; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | /** |
| | | * 直推20%,隔代收益为直推奖励金额的30%,a_b_c_d,d购买1000套餐,c得200,b得200*30%=60元,a得60*30%=18元。。。 |
| | | * 以此类推,结算到一元为止。 |
| | | * |
| | | * @param orderId |
| | | */ |
| | | @Override |
| | | public void dynamicProfit(Long orderId) { |
| | | log.info("######直推奖励, 订单ID:{}######", orderId); |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId); |
| | | if (orderInfo.getOrderType() == 2) { |
| | | log.info("积分订单无返利"); |
| | | return; |
| | | } |
| | | |
| | | MallMember member = mallMemberMapper.selectById(orderInfo.getMemberId()); |
| | | |
| | | if (StrUtil.isBlank(member.getReferrerId())) { |
| | |
| | | String parent = member.getReferrerId(); |
| | | List<MallOrderItem> items = mallOrderInfoMapper.getMallOrderItemByOrderId(orderId); |
| | | for (MallOrderItem item : items) { |
| | | BigDecimal dynamicProfit = item.getAmount().multiply(BigDecimal.valueOf(item.getCnt())).divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); |
| | | // 减去成本后算收益 |
| | | BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt())); |
| | | |
| | | BigDecimal dynamicProfit = amount.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); |
| | | |
| | | List<String> parents = StrUtil.split(member.getReferrerIds(), ','); |
| | | List<MallMember> members = mallMemberMapper.selectByInviteIds(parents); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void agentProfit() { |
| | | public void agentProfit(Date profitDate) { |
| | | log.info("#####==代理分红==#####"); |
| | | Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountForDate(profitDate, null); |
| | | if (profitDate == null) { |
| | | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D"); |
| | | |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode()); |
| | | BigDecimal profit = totalIncome.divide(new BigDecimal(dic.getValue()),2, RoundingMode.HALF_UP); |
| | | BigDecimal profit = totalIncome.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); |
| | | BigDecimal preProfit = profit.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); |
| | | |
| | | List<MallMember> agentMembers = mallMemberMapper.selectByIdAndNoLevel(null, AgentLevelEnum.FIRST_LEVEL.name()); |
| | |
| | | for (MallMember agentMember : agentMembers) { |
| | | DataDictionaryCustom agentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL_REQUIRE, agentMember.getLevel()); |
| | | |
| | | // TODO |
| | | if (agentDic == null) { |
| | | continue; |
| | | } |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(agentDic.getValue()); |
| | | BigDecimal profitProp = jsonObject.getBigDecimal("profitProp"); |
| | | BigDecimal income = preProfit.multiply(profitProp); |
| | | |
| | | try { |
| | | walletService.reduce(income, agentMember.getId(), "score"); |
| | | } catch (Exception e) { |
| | | log.info("直推奖励异常:{}, {}", income, agentMember.getId()); |
| | | continue; |
| | | } |
| | | walletService.add(income, agentMember.getId(), "commission"); |
| | | |
| | | moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void rankProfit() { |
| | | log.info("######==排名分红==####"); |
| | | |
| | | } |
| | | |
| | | public static void main(String[] args) { |