Administrator
2025-05-16 9265a439968f7df5b93a9435f2dc958d8a9c45a3
src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
@@ -3,7 +3,9 @@
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.enumerates.*;
import cc.mrbird.febs.common.properties.XcxProperties;
import cc.mrbird.febs.common.utils.MallUtils;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.common.utils.ShareCodeUtil;
import cc.mrbird.febs.common.utils.SpringContextHolder;
import cc.mrbird.febs.mall.dto.RechargeWalletMessageSendDto;
import cc.mrbird.febs.mall.entity.*;
@@ -18,10 +20,13 @@
import cc.mrbird.febs.pay.util.Util;
import cc.mrbird.febs.pay.util.WechatConfigure;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wechat.pay.contrib.apache.httpclient.notification.NotificationRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -47,6 +52,7 @@
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@@ -56,6 +62,7 @@
public class XcxPayController {
    private final HappyActivityOrderMapper happyActivityOrderMapper;
    private final HappyActivityOrderItemMapper happyActivityOrderItemMapper;
    private final MallOrderInfoMapper mallOrderInfoMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final MallMemberWalletMapper mallMemberWalletMapper;
@@ -140,62 +147,72 @@
                            mallMoneyFlow.setStatus(2);
                            mallMoneyFlowMapper.updateById(mallMoneyFlow);
                            /**
                             * 充值赠送金额
                             */
                            DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                                    DataDictionaryEnum.GIVE_STATE.getType(),
                                    DataDictionaryEnum.GIVE_STATE.getCode());
                            mallMoneyFlowService.addMoneyFlow(
                                    memberId,
                                    payMoney,
                                    ScoreFlowTypeEnum.RECHARGE_ING.getValue(),
                                    rechargeNo,
                                    FlowTypeEnum.BALANCE.getValue(),
                                    StrUtil.format(ScoreFlowTypeEnum.RECHARGE.getDesc(),payMoney),
                                    2
                            );
                            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);
//                            /**
//                             * 充值赠送金额
//                             */
//                            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);
@@ -314,17 +331,41 @@
                            order.setPayOrderNo(transaction_id);
                            mallOrderInfoMapper.updateById(order);
                            //先支付积分部分
                            if(order.getScoreAmount().compareTo(BigDecimal.ZERO) > 0){
                                memberWalletService.reduce(order.getScoreAmount(), order.getMemberId(), "prizeScore");
                                mallMoneyFlowService.addMoneyFlow(
                                        order.getMemberId(),
                                        order.getScoreAmount().negate(),
                                        ScoreFlowTypeEnum.PAY.getValue(),
                                        order.getOrderNo(),
                                        FlowTypeEnum.PRIZE_SCORE.getValue(),
                                        StrUtil.format(ScoreFlowTypeEnum.PAY.getDesc(),order.getScoreAmount()),
                                        2
                                );
                            }
                            agentProducer.sendOrderCoupon(order.getId());
//                            agentProducer.sendGetScoreMsg(order.getId());
                            mallMoneyFlowService.addMoneyFlow(
                                    order.getMemberId(),
                                    order.getAmount().negate(),
                                    MoneyFlowTypeEnum.WECHAT_PAY.getValue(),
                                    ScoreFlowTypeEnum.WECHAT_PAY.getValue(),
                                    order.getOrderNo(),
                                    FlowTypeEnum.WECHAT.getValue(),
                                    "微信支付",
                                    2);
                                    FlowTypeEnum.BALANCE.getValue(),
                                    StrUtil.format(ScoreFlowTypeEnum.WECHAT_PAY.getDesc(),order.getAmount()),
                                    2
                            );
//                            mallMoneyFlowService.addMoneyFlow(
//                                    order.getMemberId(),
//                                    order.getAmount().negate(),
//                                    MoneyFlowTypeEnum.WECHAT_PAY.getValue(),
//                                    order.getOrderNo(),
//                                    FlowTypeEnum.WECHAT.getValue(),
//                                    "微信支付",
//                                    2);
                            threadResult.success().message("支付成功");
                        } else {
                            log.info("订单状态不为待付款,order status=", order.getStatus());
@@ -422,6 +463,18 @@
                            happyActivityOrder.setWxOrderNo(transaction_id);
                            happyActivityOrderMapper.updateById(happyActivityOrder);
                            List<HappyActivityOrderItem> items = happyActivityOrderItemMapper.selectList(
                                    new LambdaQueryWrapper<HappyActivityOrderItem>()
                                            .eq(HappyActivityOrderItem::getOrderId, orderId)
                            );
                            if (CollUtil.isNotEmpty(items)) {
                                for (HappyActivityOrderItem item : items) {
                                    String code = ShareCodeUtil.toSerialCode(item.getOrderId()) + MallUtils.getRandomNum(10);
                                    item.setCode(code);
                                    happyActivityOrderItemMapper.updateById(item);
                                }
                            }
                            mallMoneyFlowService.addMoneyFlow(
                                    happyActivityOrder.getMemberId(),
                                    happyActivityOrder.getAmount().negate(),