| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Override |
| | | public void dynamicProfit(Long orderId) { |
| | | return; |
| | | // dynamicProfit(orderId, 2); |
| | | // return; |
| | | dynamicProfit(orderId, 2); |
| | | } |
| | | |
| | | /** |
| | | * 直推收益 |
| | | * |
| | | * 1、直推收益 1:20;2:30;3:40 返利,隔代奖拿直推收益20% |
| | | * 2、若非代理推代理,只拿10%,往上找代理给15%,再往上找代理给15%,往上找连续两层。股东套餐同理 |
| | | * 3、代理推代理按照第1点结算 |
| | | * |
| | | * @param orderId |
| | | */ |
| | | @Override |
| | | public void directProfit(Long orderId) { |
| | | log.info("######直推奖励, 订单ID:{}######", orderId); |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId); |
| | | if (orderInfo.getOrderType() == 2) { |
| | | log.info("积分订单无返利"); |
| | | return; |
| | | } |
| | | BigDecimal indirectPer = BigDecimal.valueOf(0.2); |
| | | BigDecimal indirectPer2 = BigDecimal.valueOf(0.15); |
| | | |
| | | MallMember member = mallMemberMapper.selectById(orderInfo.getMemberId()); |
| | | |
| | | // 父级会员 |
| | | MallMember parentMember = mallMemberMapper.selectInfoByInviteId(member.getReferrerId()); |
| | | |
| | | // 父级会员直推人数 |
| | | Integer directCnt = mallMemberMapper.selectOwnCntByInviteId(parentMember.getInviteId()); |
| | | List<DataDictionaryCustom> dataDices = dataDictionaryCustomMapper.selectDicByType(DataDictionaryEnum.DIRECT_BONUS_SETTING.getType()); |
| | | |
| | | directCnt = directCnt == null ? 0 : directCnt; |
| | | List<MallOrderItem> items = mallOrderInfoMapper.getMallOrderItemByOrderId(orderId); |
| | | |
| | | if (CollUtil.isEmpty(items)) { |
| | | return; |
| | | } |
| | | |
| | | for (MallOrderItem item : items) { |
| | | // 减去成本后算收益 |
| | | BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt())); |
| | | if (amount.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | // 直推返利比例 |
| | | BigDecimal profitPer = BigDecimal.ZERO; |
| | | int isSameLevel = 0; |
| | | // 普通商品 -- 直推上级可拿百分比直推奖励 |
| | | if (item.getIsNormal() == 1) { |
| | | profitPer = new BigDecimal(item.getNormalPer()); |
| | | |
| | | // 套餐商品 |
| | | } else { |
| | | |
| | | // 判断上级是否与自己购买的套餐符合,若符合则走3级直推逻辑,若不符合则另外一个 |
| | | if (parentMember.getAccountLevel().equals(item.getGoodsLevel()) || AccountLevelEnums.VIP.getLevel().equals(parentMember.getAccountLevel())) { |
| | | |
| | | for (DataDictionaryCustom dataDic : dataDices) { |
| | | JSONObject jsonObject = JSONObject.parseObject(dataDic.getValue()); |
| | | if (directCnt >= jsonObject.getInteger("pushCnt")) { |
| | | profitPer = jsonObject.getBigDecimal("prop"); |
| | | } |
| | | } |
| | | isSameLevel = 1; |
| | | // 非代理推代理/非股东推股东 |
| | | } else { |
| | | profitPer = BigDecimal.valueOf(0.1); |
| | | isSameLevel = 2; |
| | | } |
| | | } |
| | | |
| | | // 直推奖 |
| | | BigDecimal profit = amount.multiply(profitPer.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)); |
| | | changeScoreAndCommission(parentMember.getId(), profit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo()); |
| | | |
| | | // 代理推代理 |
| | | if (isSameLevel == 1) { |
| | | MallMember doubleParentMember = mallMemberMapper.selectInfoByInviteId(parentMember.getReferrerId()); |
| | | if (doubleParentMember == null) { |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal doubleParentProfit = profit.multiply(indirectPer); |
| | | changeScoreAndCommission(doubleParentMember.getId(), doubleParentProfit, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo()); |
| | | } |
| | | |
| | | // 非代理推代理 |
| | | if (isSameLevel == 2) { |
| | | List<MallMember> mallMembers = mallMemberMapper.selectParentMemberList(StrUtil.split(parentMember.getReferrerIds(), ','), parentMember.getReferrerId(), 2); |
| | | if (CollUtil.isEmpty(mallMembers)) { |
| | | continue; |
| | | } |
| | | |
| | | for (MallMember mallMember : mallMembers) { |
| | | if (!item.getGoodsLevel().equals(mallMember.getAccountLevel())) { |
| | | break; |
| | | } |
| | | |
| | | BigDecimal doubleParentProfit = profit.multiply(indirectPer2); |
| | | changeScoreAndCommission(mallMember.getId(), doubleParentProfit, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void dynamicProfit(Long orderId, Integer isNormal) { |
| | | log.info("######直推奖励, 订单ID:{}######", orderId); |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId); |
| | | if (orderInfo.getOrderType() == 2) { |
| | | log.info("积分订单无返利"); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void agentProfit(Date profitDate) { |
| | | log.info("#####==代理分红==start==#####"); |
| | | if (profitDate == null) { |
| | | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | // 套餐业绩 |
| | | // BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); |
| | | // 普通商品业绩 |
| | | // BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); |
| | | |
| | | BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode()); |
| | |
| | | * 每次拿重试次数大于零 |
| | | * 按ID asc排序的十条数据 |
| | | */ |
| | | List<MallMqRecord> mallMqRecords = mallMqRecordMapper.selectByStateLimitTen(2); |
| | | if(CollUtil.isEmpty(mallMqRecords)){ |
| | | return; |
| | | } |
| | | for(MallMqRecord mallMqRecord : mallMqRecords){ |
| | | Integer retryTimes = mallMqRecord.getRetryTimes(); |
| | | if(retryTimes <= 0){ |
| | | continue; |
| | | } |
| | | retryTimes = retryTimes - 1; |
| | | mallMqRecord.setRetryTimes(retryTimes); |
| | | mallMqRecordMapper.updateById(mallMqRecord); |
| | | |
| | | Long orderId = mallMqRecord.getOrderId(); |
| | | agentProducer.sendPerkMoneyMsg(orderId); |
| | | } |
| | | // List<MallMqRecord> mallMqRecords = mallMqRecordMapper.selectByStateLimitTen(2); |
| | | // if(CollUtil.isEmpty(mallMqRecords)){ |
| | | // return; |
| | | // } |
| | | // DateTime dateTime = DateUtil.offsetMinute(new Date(), -5); |
| | | // for(MallMqRecord mallMqRecord : mallMqRecords){ |
| | | // if(DateUtil.compare(dateTime,mallMqRecord.getCreateTime()) <= 0){ |
| | | // continue; |
| | | // } |
| | | // Integer retryTimes = mallMqRecord.getRetryTimes(); |
| | | // if(retryTimes <= 0){ |
| | | // continue; |
| | | // } |
| | | // retryTimes = retryTimes - 1; |
| | | // mallMqRecord.setRetryTimes(retryTimes); |
| | | // mallMqRecordMapper.updateById(mallMqRecord); |
| | | // |
| | | // Long orderId = mallMqRecord.getOrderId(); |
| | | // if(mallMqRecord.getState() == 2){ |
| | | // agentProducer.sendPerkMoneyMsg(orderId); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 获取每日最大产生的凭证数量 |
| | | * 改成每日产出固定值 |
| | | */ |
| | | BigDecimal achieveDailyRelease = getAchieveDailyRelease(); |
| | | // BigDecimal achieveDailyRelease = getAchieveDailyRelease(); |
| | | DataDictionaryCustom achieveReleaseDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | GreenScoreEnum.ACHIEVE_RELEASE.getType(), |
| | | GreenScoreEnum.ACHIEVE_RELEASE.getCode() |
| | | ); |
| | | BigDecimal achieveDailyRelease = new BigDecimal(achieveReleaseDic.getValue() == null ? "0" : achieveReleaseDic.getValue()); |
| | | if(achieveDailyRelease.compareTo(BigDecimal.ZERO) <= 0){ |
| | | return; |
| | | } |
| | | |
| | | if(achieveTotal.compareTo(achieveMax) < 0){ |
| | | BigDecimal divide = achieveTotal.divide(achieveMax, 2, BigDecimal.ROUND_DOWN); |
| | |
| | | mallScoreAchieveRelease.setReleaseNo(scoreNo); |
| | | mallScoreAchieveRelease.setVoucherExpect(achieveDailyRelease); |
| | | mallScoreAchieveRelease.setVoucherReal(achieveDailyReleaseReal); |
| | | mallScoreAchieveReleaseMapper.updateById(mallScoreAchieveRelease); |
| | | mallScoreAchieveReleaseMapper.insert(mallScoreAchieveRelease); |
| | | |
| | | } |
| | | |
| | |
| | | voucherAmountAdd, |
| | | MoneyFlowTypeEnum.VOUCHER_SALE.getValue(), |
| | | voucherNo, |
| | | FlowTypeEnum.VOUCHER_AMOUNT.getValue()); |
| | | FlowTypeEnum.BALANCE.getValue()); |
| | | } |
| | | |
| | | //增加积分凭证池的凭证数量 |