Administrator
2025-05-16 9265a439968f7df5b93a9435f2dc958d8a9c45a3
refactor(mall): 重构充值相关代码

- 修改充值流程中的资金流向记录方式
- 优化佣金转余额和积分的处理逻辑
- 更新充值相关的枚举类型和描述
- 移除不必要的注释代码
- 调整充值成功后的处理逻辑
6 files modified
160 ■■■■■ changed files
src/main/java/cc/mrbird/febs/common/enumerates/ScoreFlowTypeEnum.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/dto/ApiRechargeWalletDto.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/dto/CommissionChangeDto.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberWalletServiceImpl.java 27 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java 114 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/common/enumerates/ScoreFlowTypeEnum.java
@@ -6,6 +6,12 @@
public enum ScoreFlowTypeEnum {
    COMMISSION_TO_PRIZE_SCORE(20,"划转{}佣金到积分"),
    COMMISSION_TO_BALANCE(19,"划转{}佣金到余额"),
    RECHARGE(18,"成功充值{}"),
    RECHARGE_ING(17,"正在充值{}"),
    WECHAT_PAY(16,"微信支付{}"),
    WECHAT_REFUND(15,"退款{}到微信"),
    REFUND(14, "退款{}到余额"),
src/main/java/cc/mrbird/febs/mall/dto/ApiRechargeWalletDto.java
@@ -13,13 +13,14 @@
    @ApiModelProperty(value = "1:普通充值 2:合伙人充值", example = "10")
    private Integer type;
    @ApiModelProperty(value = "代理申请ID", example = "10")
    @ApiModelProperty(hidden = true)
    private Long agentApplyId;
    @ApiModelProperty(value = "充值金额", example = "10")
    private BigDecimal amount;
    @ApiModelProperty(value = "充值单号", example = "10")
    @ApiModelProperty(hidden = true)
    private String rechargeNo;
    @ApiModelProperty(hidden = true)
src/main/java/cc/mrbird/febs/mall/dto/CommissionChangeDto.java
@@ -19,7 +19,7 @@
    @NotNull(message = "请输入划转金额")
    private BigDecimal amount;
    @ApiModelProperty(value = "类型 1-to余额 2-to竞猜积分", example = "1")
    @ApiModelProperty(value = "类型 1-to余额 2-to积分", example = "1")
    @NotNull(message = "参数错误")
    private Integer type;
}
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -919,10 +919,12 @@
        mallMoneyFlowService.addMoneyFlow(
                memberId,
                amount,
                MoneyFlowTypeEnum.RECHARGE.getValue(),
                ScoreFlowTypeEnum.RECHARGE_ING.getValue(),
                rechargeNo,
                FlowTypeEnum.BALANCE.getValue(),
                "余额充值",1);
                StrUtil.format(ScoreFlowTypeEnum.RECHARGE_ING.getDesc(),amount),
                1
        );
        String wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData);
        String payResultStr = brandWCPayRequestData.getPrepay_id();
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberWalletServiceImpl.java
@@ -2,8 +2,10 @@
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.exception.FebsException;
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.entity.MallMember;
import cc.mrbird.febs.mall.entity.MallMemberWallet;
@@ -248,20 +250,37 @@
        // 佣金转余额
        if (commissionChange.getType() == 1) {
            type = MoneyFlowTypeEnum.COMMISSION_TO_BALANCE.getValue();
            type = ScoreFlowTypeEnum.COMMISSION_TO_BALANCE.getValue();
            flowType = FlowTypeEnum.BALANCE.getValue();
            this.add(commissionChange.getAmount(), member.getId(), "balance");
            // 佣金转竞猜积分
        } else if (commissionChange.getType() == 2){
            type = MoneyFlowTypeEnum.COMMISSION_TO_PRIZESCORE.getValue();
            type = ScoreFlowTypeEnum.COMMISSION_TO_PRIZE_SCORE.getValue();
            flowType = FlowTypeEnum.PRIZE_SCORE.getValue();
            this.add(commissionChange.getAmount(), member.getId(), "prizeScore");
        } else {
            throw new FebsException("参数错误");
        }
        moneyFlowService.addMoneyFlow(member.getId(), commissionChange.getAmount().negate(), type, null,  FlowTypeEnum.COMMISSION.getValue());
        moneyFlowService.addMoneyFlow(member.getId(), commissionChange.getAmount(), type, null,  flowType);
        moneyFlowService.addMoneyFlow(
                member.getId(),
                commissionChange.getAmount().negate(),
                type,
                MallUtils.getOrderNum(),
                FlowTypeEnum.COMMISSION.getValue(),
                String.format(ScoreFlowTypeEnum.getDescByValue(type), commissionChange.getAmount()),
                2
        );
        moneyFlowService.addMoneyFlow(
                member.getId(),
                commissionChange.getAmount(),
                type,
                MallUtils.getOrderNum(),
                flowType,
                String.format(ScoreFlowTypeEnum.getDescByValue(type), commissionChange.getAmount()),
                2
        );
    }
}
src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
@@ -147,62 +147,72 @@
                            mallMoneyFlow.setStatus(2);
                            mallMoneyFlowMapper.updateById(mallMoneyFlow);
                            /**
                             * 充值赠送金额
                             */
                            DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                                    DataDictionaryEnum.GIVE_STATE.getType(),
                                    DataDictionaryEnum.GIVE_STATE.getCode());
                            DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                                    DataDictionaryEnum.GIVE_AMOUNT.getType(),
                                    DataDictionaryEnum.GIVE_AMOUNT.getCode());
                            DataDictionaryCustom chargeAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                                    DataDictionaryEnum.CHARGE_AMOUNT.getType(),
                                    DataDictionaryEnum.CHARGE_AMOUNT.getCode());
                            /**
                             * 普通充值
                             * 开启了充值赠送
                             * 系统设置的赠送金额和充值金额不为空
                             * 充值金额大于等于系统设置的充值金额
                             */
                            if(1 == type
                                    && ObjectUtil.isNotEmpty(giveStateDic)
                                    && "1".equals(giveStateDic.getValue())
                                    && ObjectUtil.isNotEmpty(giveAmountDic)
                                    && ObjectUtil.isNotEmpty(chargeAmountDic)){
                                BigDecimal giveAmount = ObjectUtil.isEmpty(giveAmountDic.getValue()) ?
                                        BigDecimal.ZERO :
                                        new BigDecimal(giveAmountDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
                                BigDecimal chargeAmount = ObjectUtil.isEmpty(chargeAmountDic.getValue()) ?
                                        BigDecimal.ZERO :
                                        new BigDecimal(chargeAmountDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
                                if(payMoney.compareTo(chargeAmount) >= 0){
                                    mallMoneyFlowService.addMoneyFlow(
                                            memberId,
                                            giveAmount,
                                            MoneyFlowTypeEnum.RECHARGE_SEND.getValue(),
                                            rechargeNo+"ZS",
                                    payMoney,
                                    ScoreFlowTypeEnum.RECHARGE_ING.getValue(),
                                    rechargeNo,
                                            FlowTypeEnum.BALANCE.getValue(),
                                            "充值赠送金额",
                                            2);
                                    StrUtil.format(ScoreFlowTypeEnum.RECHARGE.getDesc(),payMoney),
                                    2
                            );
                                    memberWalletService.addBalance(giveAmount,memberId);
                                }
                            }
                            RechargeWalletMessageSendDto rechargeWalletMessageSendDto = new RechargeWalletMessageSendDto();
                            rechargeWalletMessageSendDto.setRechargeNo(rechargeNo);
                            rechargeWalletMessageSendDto.setRechargeAmount(payMoney.toString());
                            MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
                            rechargeWalletMessageSendDto.setBalance(mallMemberWallet.getBalance().toString());
                            rechargeWalletMessageSendDto.setCreateTime(DateUtil.now());
                            rechargeWalletMessageSendDto.setOpenId(mallMemberMapper.selectById(memberId).getOpenId());
                            DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WX_TEMPLATE_ID_TWO.getType(), DataDictionaryEnum.WX_TEMPLATE_ID_TWO.getCode());
                            rechargeWalletMessageSendDto.setTemplateId(dataDictionaryCustom.getValue());
                            iXcxPayService.rechargeWalletMessageSend(rechargeWalletMessageSendDto);
//                            /**
//                             * 充值赠送金额
//                             */
//                            DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//                                    DataDictionaryEnum.GIVE_STATE.getType(),
//                                    DataDictionaryEnum.GIVE_STATE.getCode());
//
//                            DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//                                    DataDictionaryEnum.GIVE_AMOUNT.getType(),
//                                    DataDictionaryEnum.GIVE_AMOUNT.getCode());
//
//                            DataDictionaryCustom chargeAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//                                    DataDictionaryEnum.CHARGE_AMOUNT.getType(),
//                                    DataDictionaryEnum.CHARGE_AMOUNT.getCode());
//                            /**
//                             * 普通充值
//                             * 开启了充值赠送
//                             * 系统设置的赠送金额和充值金额不为空
//                             * 充值金额大于等于系统设置的充值金额
//                             */
//                            if(1 == type
//                                    && ObjectUtil.isNotEmpty(giveStateDic)
//                                    && "1".equals(giveStateDic.getValue())
//                                    && ObjectUtil.isNotEmpty(giveAmountDic)
//                                    && ObjectUtil.isNotEmpty(chargeAmountDic)){
//                                BigDecimal giveAmount = ObjectUtil.isEmpty(giveAmountDic.getValue()) ?
//                                        BigDecimal.ZERO :
//                                        new BigDecimal(giveAmountDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
//                                BigDecimal chargeAmount = ObjectUtil.isEmpty(chargeAmountDic.getValue()) ?
//                                        BigDecimal.ZERO :
//                                        new BigDecimal(chargeAmountDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
//                                if(payMoney.compareTo(chargeAmount) >= 0){
//                                    mallMoneyFlowService.addMoneyFlow(
//                                            memberId,
//                                            giveAmount,
//                                            MoneyFlowTypeEnum.RECHARGE_SEND.getValue(),
//                                            rechargeNo+"ZS",
//                                            FlowTypeEnum.BALANCE.getValue(),
//                                            "充值赠送金额",
//                                            2);
//
//                                    memberWalletService.addBalance(giveAmount,memberId);
//                                }
//                            }
//
//                            RechargeWalletMessageSendDto rechargeWalletMessageSendDto = new RechargeWalletMessageSendDto();
//                            rechargeWalletMessageSendDto.setRechargeNo(rechargeNo);
//                            rechargeWalletMessageSendDto.setRechargeAmount(payMoney.toString());
//
//                            MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
//                            rechargeWalletMessageSendDto.setBalance(mallMemberWallet.getBalance().toString());
//                            rechargeWalletMessageSendDto.setCreateTime(DateUtil.now());
//                            rechargeWalletMessageSendDto.setOpenId(mallMemberMapper.selectById(memberId).getOpenId());
//                            DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WX_TEMPLATE_ID_TWO.getType(), DataDictionaryEnum.WX_TEMPLATE_ID_TWO.getCode());
//                            rechargeWalletMessageSendDto.setTemplateId(dataDictionaryCustom.getValue());
//                            iXcxPayService.rechargeWalletMessageSend(rechargeWalletMessageSendDto);
                            threadResult.success().message("充值成功");
                        } else {
                            log.info("充值失败", attrStr);