| | |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberService; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.ICommonService; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cc.mrbird.febs.mall.vo.*; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.crypto.asymmetric.KeyType; |
| | | import cn.hutool.crypto.asymmetric.RSA; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private final MallShoppingCartMapper mallShoppingCartMapper; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final IApiMallMemberWalletService walletService; |
| | | private final IMallMoneyFlowService moneyFlowService; |
| | | private final MallMemberPaymentMapper mallMemberPaymentMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallShopApplyMapper mallShopApplyMapper; |
| | |
| | | @Override |
| | | public FebsResponse redBag() { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectByMemberIdAndTypeAndStatusAndDate(member.getId(), MoneyFlowTypeEnum.SCORE_POOL.getValue(), 1, new Date()); |
| | | if(CollUtil.isEmpty(mallMoneyFlows)){ |
| | | throw new FebsException("没有红包"); |
| | | } |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | for(MallMoneyFlow mallMoneyFlow : mallMoneyFlows){ |
| | | mallMoneyFlow.setStatus(2); |
| | | mallMoneyFlowMapper.updateById(mallMoneyFlow); |
| | | QueryWrapper<MallMember> formalMember = new QueryWrapper<>(); |
| | | formalMember.ne("level", AgentLevelEnum.ZERO_LEVEL.name()); |
| | | List<MallMember> mallMembers = this.baseMapper.selectList(formalMember); |
| | | BigDecimal outCome = BigDecimal.ZERO; |
| | | if(CollUtil.isNotEmpty(mallMembers)){ |
| | | |
| | | amount = mallMoneyFlow.getAmount().abs(); |
| | | BigDecimal scorePoolToDay = new BigDecimal(redisUtils.get(AppContants.SCORE_POOL_TODAY).toString()); |
| | | BigDecimal income = new BigDecimal(scorePoolToDay.divide(new BigDecimal(mallMembers.size()), 2, RoundingMode.HALF_UP).intValue()); |
| | | if(income.compareTo(BigDecimal.ZERO) < 1){ |
| | | throw new FebsException("没有红包"); |
| | | } |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); |
| | | if(mallMemberWallet.getScore().compareTo(BigDecimal.ZERO) < 1){ |
| | | throw new FebsException("没有红包"); |
| | | } |
| | | if(mallMemberWallet.getScore().compareTo(income) < 0){ |
| | | outCome = new BigDecimal(mallMemberWallet.getScore().intValue()); |
| | | }else{ |
| | | outCome = income; |
| | | } |
| | | |
| | | outCome = new BigDecimal(RandomUtil.randomBigDecimal(BigDecimal.ZERO,outCome).intValue()).setScale(2,BigDecimal.ROUND_DOWN); |
| | | /* |
| | | 平分成佣金,一比一减少赠送积分 |
| | | 如果没有赠送积分,则平分0 |
| | | */ |
| | | moneyFlowService.addMoneyFlow(member.getId(), outCome, MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(member.getId(), outCome.negate(), MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | walletService.add(outCome, member.getId(), "commission"); |
| | | walletService.reduce(outCome.negate(), member.getId(), "score"); |
| | | |
| | | } |
| | | walletService.add(amount, member.getId(), "commission"); |
| | | walletService.reduce(amount.negate(), member.getId(), "score"); |
| | | return new FebsResponse().success().data(amount); |
| | | return new FebsResponse().success().data(outCome); |
| | | } |
| | | } |