KKSU
2024-01-16 15d223c549e0d94316db344f2f6337b605fffbae
src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
@@ -6,39 +6,27 @@
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.common.utils.SpringContextHolder;
import cc.mrbird.febs.mall.dto.RechargeWalletMessageSendDto;
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
import cc.mrbird.febs.mall.entity.MallMemberWallet;
import cc.mrbird.febs.mall.entity.MallMoneyFlow;
import cc.mrbird.febs.mall.entity.MallOrderInfo;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IApiMallMemberService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.pay.model.NotifyData;
import cc.mrbird.febs.pay.model.OrderStateDto;
import cc.mrbird.febs.pay.model.OrderStateMsgVo;
import cc.mrbird.febs.pay.model.WxTemplateData;
import cc.mrbird.febs.pay.service.IPayService;
import cc.mrbird.febs.pay.service.IXcxPayService;
import cc.mrbird.febs.pay.util.PayThreadPool;
import cc.mrbird.febs.pay.util.Signature;
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.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.thymeleaf.engine.TemplateData;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@@ -73,6 +61,10 @@
    private IApiMallMemberWalletService memberWalletService;
    @Autowired
    private IApiMallMemberService mallMemberService;
    @Autowired
    private MallAgentRecordMapper mallAgentRecordMapper;
    @Autowired
    private AgentProducer agentProducer;
    @Autowired
    private IXcxPayService iXcxPayService;
@@ -115,6 +107,7 @@
                String rechargeNo = (String) jsonObject.get("rechargeNo");
                Integer type = (Integer) jsonObject.get("type");
                Long memberId = Long.parseLong(jsonObject.get("memberId").toString());
                Long agentApplyId = Long.parseLong(jsonObject.get("agentApplyId").toString());
                // 检验订单状态
                MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectOneByOrderNoAndMemberId(rechargeNo,memberId);
                // 校验签名
@@ -137,8 +130,11 @@
                        if (ObjectUtil.isNotEmpty(mallMoneyFlow)) {
                            log.debug("检查支付金额payMoney={},mallMoneyFlow.getPayMoney()={}", payMoney, mallMoneyFlow.getAmount());
                            //合伙人申请的充值,要更新会员状态为FIRST_LEVEL
                            if(2 == type){
                                mallMemberService.updateMemberAgent(memberId);
                                log.info("微信充值回调" + agentApplyId);
                                MallAgentRecord mallAgentRecord = mallAgentRecordMapper.selectById(agentApplyId);
                                mallMemberService.updateMemberAgent(agentApplyId,mallAgentRecord.getAgentLevel());
                            }
                            memberWalletService.addBalance(payMoney,memberId);
                            mallMoneyFlow.setStatus(2);
@@ -154,21 +150,39 @@
                            DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                                    DataDictionaryEnum.GIVE_AMOUNT.getType(),
                                    DataDictionaryEnum.GIVE_AMOUNT.getCode());
                            if(ObjectUtil.isNotEmpty(giveStateDic)
                                && "1" == giveStateDic.getValue()
                                    && ObjectUtil.isNotEmpty(giveAmountDic)){
                            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);
                                mallMoneyFlowService.addMoneyFlow(
                                        memberId,
                                        giveAmount,
                                        MoneyFlowTypeEnum.RECHARGE_SEND.getValue(),
                                        rechargeNo+"ZS",
                                        FlowTypeEnum.BALANCE.getValue());
                                memberWalletService.addBalance(giveAmount,memberId);
                                    memberWalletService.addBalance(giveAmount,memberId);
                                }
                            }
                            RechargeWalletMessageSendDto rechargeWalletMessageSendDto = new RechargeWalletMessageSendDto();
@@ -222,6 +236,19 @@
//        System.out.println(memberId);
//        System.out.println(rechargeNo);
//    }
    /**
     * 微信电子发票回调接口
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @RequestMapping(value = "/fapiaoCallBack")
    public Map<Object, Object> fapiaoCallBack(HttpServletResponse response, HttpServletRequest request) throws IOException {
        log.info("微信电子发票回调接口....");
        Map<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("code","SUCCESS");
        objectObjectHashMap.put("message","");
        return objectObjectHashMap;
    }
    /**
     * 微信支付回调接口
     */
@@ -284,6 +311,17 @@
                            order.setPayTime(new Date());
                            order.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue());
                            mallOrderInfoMapper.updateById(order);
                            agentProducer.sendOrderCoupon(order.getId());
                            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());