| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; |
| | | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | |
| | | import cn.hutool.core.date.DateField; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final MallAchieveRecordMapper mallAchieveRecordMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void staticProfit() { |
| | | public void staticProfit(Date profitDate) { |
| | | log.info("#####静态分红开始运行:{}#####", new Date()); |
| | | List<MallMember> members = mallMemberMapper.selectList(null); |
| | | if (CollUtil.isEmpty(members)) { |
| | | return; |
| | | } |
| | | |
| | | Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | if (profitDate == null) { |
| | | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | // 套餐业绩 |
| | | // BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); |
| | | // 普通商品业绩 |
| | |
| | | } |
| | | |
| | | BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP); |
| | | if (income.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | for (MallMember agentMember : agentMemberList) { |
| | | // int reduce = walletService.reduce(income, agentMember.getId(), "score"); |
| | |
| | | Page<MallMember> page = new Page<>(1, 5); |
| | | MallMember query = new MallMember(); |
| | | query.setQuery("2"); |
| | | |
| | | Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | query.setCreatedTime(profitDate); |
| | | IPage<MallMember> rankListInPage = mallMemberMapper.selectRankListInPage(page, query); |
| | |
| | | // BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2); |
| | | // 普通商品业绩 |
| | | // BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1); |
| | | BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); |
| | | BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("M", profitDate); |
| | | |
| | | List<DataDictionaryCustom> rankAward = dataDictionaryCustomMapper.selectDicByType("RANK_AWARD"); |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANK_BONUS.getType(), DataDictionaryEnum.RANK_BONUS.getCode()); |
| | |
| | | * 拿推荐人的收益(代理,直推,排名)的10%加权平分给下面直推 |
| | | */ |
| | | @Override |
| | | public void thankfulProfit() { |
| | | public void thankfulProfit(Date date) { |
| | | log.info("######==感恩奖==start==####"); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectMemberListHasChild(); |
| | | if (CollUtil.isEmpty(mallMembers)) { |
| | | return; |
| | | } |
| | | if (date == null) { |
| | | date = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.THANKFUL_BONUS.getType(), DataDictionaryEnum.THANKFUL_BONUS.getCode()); |
| | | // 感恩奖比例 |
| | | BigDecimal prop = new BigDecimal(dic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); |
| | | |
| | | Date date = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); |
| | | for (MallMember mallMember : mallMembers) { |
| | | BigDecimal income = mallMoneyFlowMapper.selectThankfulCommission(date, mallMember.getId()); |
| | | List<MallMember> children = mallMemberMapper.selectMemberDirectForHasLevel(mallMember.getInviteId()); |
| | |
| | | } |
| | | log.info("#####==店补/董事==end==######"); |
| | | } |
| | | |
| | | @Override |
| | | public void syAppOrderPayDoneQueue(String orderNo) { |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectByOrderNo(orderNo); |
| | | if(ObjectUtil.isEmpty(orderInfo)){ |
| | | return; |
| | | } |
| | | if (OrderStatusEnum.FINISH.getValue() == orderInfo.getStatus()) { |
| | | return; |
| | | } |
| | | orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); |
| | | // orderInfo.setPayResult(1); |
| | | orderInfo.setPayTime(DateUtil.date()); |
| | | mallOrderInfoMapper.updateById(orderInfo); |
| | | |
| | | if(ObjectUtil.isEmpty(orderInfo.getMemberId())){ |
| | | return; |
| | | } |
| | | Long memberId = orderInfo.getMemberId(); |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | if(ObjectUtil.isEmpty(mallMemberWallet)){ |
| | | return; |
| | | } |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId()); |
| | | if(ObjectUtil.isEmpty(mallOrderItemList)){ |
| | | return; |
| | | } |
| | | /** |
| | | * 会员增加积分 |
| | | * (现价-成本价)/现价*支付的金额 = 这个商品可以得到的积分 |
| | | * 然后累加得到总增加的积分数量 |
| | | */ |
| | | BigDecimal totalScoreAdd = BigDecimal.ZERO; |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | Long goodsId = mallOrderItem.getGoodsId(); |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(goodsId); |
| | | if(ObjectUtil.isEmpty(mallGoods)){ |
| | | continue; |
| | | } |
| | | BigDecimal presentPrice = new BigDecimal(mallGoods.getPresentPrice()); |
| | | BigDecimal costPrice = mallGoods.getCostPrice(); |
| | | BigDecimal subtractPrice = presentPrice.subtract(costPrice);//现价和成本价之间的差价 |
| | | if(subtractPrice.compareTo(BigDecimal.ZERO) <= 0){ |
| | | continue; |
| | | } |
| | | BigDecimal multiply = subtractPrice.divide(presentPrice, 2, BigDecimal.ROUND_DOWN).multiply(mallOrderItem.getAmount()); |
| | | totalScoreAdd = totalScoreAdd.add(multiply); |
| | | } |
| | | if(totalScoreAdd.compareTo(BigDecimal.ZERO) <= 0){ |
| | | return; |
| | | } |
| | | BigDecimal bigDecimal = totalScoreAdd.add(mallMemberWallet.getScore()).setScale(2, BigDecimal.ROUND_DOWN); |
| | | mallMemberWallet.setScore(bigDecimal); |
| | | mallMemberWallet.setBalance(mallMemberWallet.getBalance()); |
| | | mallMemberWalletMapper.updateBalanceScoreWithId(mallMemberWallet); |
| | | } |
| | | } |