| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | 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.ScoreFlowTypeEnum; |
| | |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.mall.dto.CommissionChangeDto; |
| | | import cc.mrbird.febs.mall.dto.ScoreSettingDto; |
| | | import cc.mrbird.febs.mall.entity.DataDictionaryCustom; |
| | | import cc.mrbird.febs.mall.entity.MallMember; |
| | | import cc.mrbird.febs.mall.entity.MallMemberWallet; |
| | | import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper; |
| | | import cc.mrbird.febs.mall.mapper.MallMemberWalletMapper; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberService; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | public class ApiMallMemberWalletServiceImpl extends ServiceImpl<MallMemberWalletMapper, MallMemberWallet> implements IApiMallMemberWalletService { |
| | | |
| | | private final IMallMoneyFlowService moneyFlowService; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Override |
| | | public void addBalance(BigDecimal amount, Long memberId) { |
| | |
| | | flag = false; |
| | | } else { |
| | | if (i > 2) { |
| | | throw new FebsException("余额修改失败"); |
| | | throw new FebsException("操作失败"); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void commissionChange(CommissionChangeDto commissionChange) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | BigDecimal amount = commissionChange.getAmount(); |
| | | if (amount.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new FebsException("参数错误"); |
| | | } |
| | | MallMemberWallet mallMemberWallet = this.baseMapper.selectWalletByMemberId(member.getId()); |
| | | if (mallMemberWallet.getCommission().compareTo(amount) < 0) { |
| | | throw new FebsException("佣金不足"); |
| | | } |
| | | |
| | | BigDecimal scorePercent = BigDecimal.ONE; |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_SIGN_SETTING.getType(), |
| | | DataDictionaryEnum.SCORE_SIGN_SETTING.getCode()); |
| | | if (dic != null) { |
| | | ScoreSettingDto scoreSettingDto = JSONObject.parseObject(dic.getValue(), ScoreSettingDto.class); |
| | | BigDecimal bigDecimal = ObjectUtil.isEmpty(scoreSettingDto.getScorePercent()) ? BigDecimal.ONE : new BigDecimal(scoreSettingDto.getScorePercent()); |
| | | if (bigDecimal.compareTo(BigDecimal.ZERO) > 0) { |
| | | scorePercent = bigDecimal; |
| | | } |
| | | } |
| | | |
| | | // TODO 判断是否开启了划转 |
| | | |
| | | int type; |
| | | int flowType; |
| | | String desc = null; |
| | | BigDecimal addAmount = BigDecimal.ZERO; |
| | | this.reduce(commissionChange.getAmount(), member.getId(), "commission"); |
| | | |
| | | // 佣金转余额 |
| | | if (commissionChange.getType() == 1) { |
| | | type = ScoreFlowTypeEnum.COMMISSION_TO_BALANCE.getValue(); |
| | | flowType = FlowTypeEnum.BALANCE.getValue(); |
| | | this.add(commissionChange.getAmount(), member.getId(), "balance"); |
| | | addAmount = commissionChange.getAmount(); |
| | | desc = StrUtil.format(ScoreFlowTypeEnum.COMMISSION_TO_BALANCE.getDesc(), commissionChange.getAmount()); |
| | | |
| | | // 佣金转竞猜积分 |
| | | this.add(addAmount, member.getId(), "balance"); |
| | | |
| | | // 佣金转积分 |
| | | } else if (commissionChange.getType() == 2){ |
| | | type = ScoreFlowTypeEnum.COMMISSION_TO_PRIZE_SCORE.getValue(); |
| | | flowType = FlowTypeEnum.PRIZE_SCORE.getValue(); |
| | | this.add(commissionChange.getAmount(), member.getId(), "prizeScore"); |
| | | desc = StrUtil.format(ScoreFlowTypeEnum.COMMISSION_TO_PRIZE_SCORE.getDesc(), commissionChange.getAmount()); |
| | | addAmount = commissionChange.getAmount().multiply(scorePercent).setScale(0, RoundingMode.HALF_DOWN); |
| | | |
| | | this.add(addAmount, member.getId(), "prizeScore"); |
| | | } else { |
| | | throw new FebsException("参数错误"); |
| | | throw new FebsException("操作失败"); |
| | | } |
| | | |
| | | moneyFlowService.addMoneyFlow( |
| | |
| | | type, |
| | | MallUtils.getOrderNum(), |
| | | FlowTypeEnum.COMMISSION.getValue(), |
| | | String.format(ScoreFlowTypeEnum.getDescByValue(type), commissionChange.getAmount()), |
| | | desc, |
| | | 2 |
| | | ); |
| | | |
| | | moneyFlowService.addMoneyFlow( |
| | | member.getId(), |
| | | commissionChange.getAmount(), |
| | | addAmount, |
| | | type, |
| | | MallUtils.getOrderNum(), |
| | | flowType, |
| | | String.format(ScoreFlowTypeEnum.getDescByValue(type), commissionChange.getAmount()), |
| | | StrUtil.format(ScoreFlowTypeEnum.getDescByValue(type), commissionChange.getAmount()), |
| | | 2 |
| | | ); |
| | | } |