فهرست منبع

优惠券微信/支付宝/网银购买接口

zhijiezhao 3 سال پیش
والد
کامیت
6e5b0beafd

+ 87 - 0
src/main/java/com/caimei365/order/controller/PayNonOrderApi.java

@@ -2,6 +2,7 @@ package com.caimei365.order.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.dto.PayCouponDto;
 import com.caimei365.order.model.dto.PaySecondDto;
 import com.caimei365.order.model.dto.PayVipDto;
 import com.caimei365.order.service.PayNonOrderService;
@@ -205,4 +206,90 @@ public class PayNonOrderApi {
         }
         return payNonOrderService.superVipOnlineRefund(payVipDto);
     }
+
+    /**
+     * 升级超级会员-微信线上支付
+     * @param payCouponDto {
+     *                  couponId      购买优惠券Id
+     *                  userId        userId
+     *                  returnUrl     页面回调地址
+     *                  code          微信小程序code
+     *                  state         微信公众号state参数
+     * }
+     */
+    @ApiOperation("购买价值优惠券-微信线上支付")
+    @PostMapping("/coupon/wechat")
+    public ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers){
+        if (null == payCouponDto.getCouponId()) {
+            return ResponseJson.error("优惠券Id不能为空!", null);
+        }
+        if (null == payCouponDto.getUserId()) {
+            return ResponseJson.error("userId不能为空!", null);
+        }
+        if (StringUtils.isEmpty(payCouponDto.getCode())) {
+            return ResponseJson.error("微信code不能为空!", null);
+        }
+        return payNonOrderService.payCouponByWeChat(payCouponDto, headers);
+    }
+
+    /**
+     * 购买价值优惠券-支付宝线上支付
+     * @param payCouponDto {
+     *                 couponId      购买优惠券Id
+     *                 userId        userId
+     *                 returnUrl     页面回调地址
+     * }
+     */
+    @ApiOperation("购买价值优惠券-支付宝线上支付")
+    @PostMapping("/coupon/alipay")
+    public ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers){
+        if (null == payCouponDto.getCouponId()) {
+            return ResponseJson.error("优惠券Id不能为空!", null);
+        }
+        if (StringUtils.isEmpty(payCouponDto.getReturnUrl())) {
+            return ResponseJson.error("回调地址不能为空!", null);
+        }
+        return payNonOrderService.payCouponByAlipay(payCouponDto, headers);
+    }
+
+    /**
+     * 购买价值优惠券-银联线上支付
+     * @param payCouponDto {
+     *               couponId      购买优惠券Id
+     *               returnUrl     页面回调地址
+     *               bankCode      银行编码(银联支付使用)
+     *               userType      用户类型(银联支付使用)企业:ENTERPRISE,个人:USER
+     * }
+     */
+    @ApiOperation("购买价值优惠券-银联线上支付")
+    @PostMapping("/coupon/union")
+    public ResponseJson<JSONObject> payCouponByUnionPay(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers){
+        if (null == payCouponDto.getCouponId()) {
+            return ResponseJson.error("优惠券Id不能为空!", null);
+        }
+        if (StringUtils.isEmpty(payCouponDto.getReturnUrl())) {
+            return ResponseJson.error("回调地址不能为空!", null);
+        }
+        if (StringUtils.isEmpty(payCouponDto.getBankCode())) {
+            return ResponseJson.error("银行编码不能为空!", null);
+        }
+        if (StringUtils.isEmpty(payCouponDto.getUserType())) {
+            return ResponseJson.error("银行用户类型不能为空!", null);
+        }
+        return payNonOrderService.payCouponUnionPay(payCouponDto, headers);
+    }
+
+    /**
+     * 购买优惠券-支付回调
+     */
+    @ApiOperation("购买优惠券-支付回调")
+    @GetMapping("/coupon/callback")
+    public String couponCallback(String data) throws NoSuchAlgorithmException, InvalidKeySpecException {
+        if (StringUtils.isBlank(data)) {
+            return "回调参数失败";
+        }
+        return payNonOrderService.couponCallback(data);
+    }
+
+
 }

+ 8 - 0
src/main/java/com/caimei365/order/mapper/PayOrderMapper.java

@@ -186,4 +186,12 @@ public interface PayOrderMapper {
      * @return
      */
     List<OrderReceiptRelationPo> getOnlineBalance(String currentTime);
+
+    Double getCouponPrice(Integer couponId);
+
+    void insertCouponRecord(CouponRecordPo cr);
+
+    OrderPayLinkVo getCouponPayLink(Integer recordId, Double amount);
+
+    void updateCouponRecord(Integer recordId);
 }

+ 8 - 0
src/main/java/com/caimei365/order/model/bo/PayParamBo.java

@@ -30,6 +30,10 @@ public class PayParamBo implements Serializable {
      * 会员购买记录Id
      */
     private Integer vipRecordId;
+    /**
+     * 优惠券购买记录id
+     */
+    private Integer couponRecordId;
     /**
      * 会员套餐id
      */
@@ -81,4 +85,8 @@ public class PayParamBo implements Serializable {
      * 个人:USER
      */
     private String userType;
+    /**
+     * 购买优惠券id
+     */
+    private Integer couponId;
 }

+ 48 - 0
src/main/java/com/caimei365/order/model/dto/PayCouponDto.java

@@ -0,0 +1,48 @@
+package com.caimei365.order.model.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class PayCouponDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 购买优惠券Id
+     */
+    @ApiModelProperty("购买优惠券Id")
+    private Integer couponId;
+    /**
+     * userId
+     */
+    @ApiModelProperty("userId")
+    private Integer userId;
+    /**
+     * 页面回调地址
+     */
+    @ApiModelProperty("页面回调地址")
+    private String returnUrl;
+    /**
+     * 微信小程序code,微信小程序支付使用
+     */
+    @ApiModelProperty("微信小程序code")
+    private String code;
+    /**
+     * 微信公众号state参数
+     */
+    @ApiModelProperty("微信公众号state参数")
+    private String state;
+    /**
+     * 银行编码(银联支付使用)
+     */
+    @ApiModelProperty("银行编码(银联支付使用)")
+    private String bankCode;
+    /**
+     * 用户类型(银联支付使用)
+     * 企业:ENTERPRISE
+     * 个人:USER
+     */
+    @ApiModelProperty("用户类型(银联支付使用)企业:ENTERPRISE,个人:USER")
+    private String userType;
+}

+ 15 - 0
src/main/java/com/caimei365/order/model/po/CouponRecordPo.java

@@ -0,0 +1,15 @@
+package com.caimei365.order.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class CouponRecordPo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Integer id;
+    private Integer couponId;
+    private Integer payStatus;
+    private Integer userId;
+}

+ 1 - 1
src/main/java/com/caimei365/order/model/po/DiscernReceiptPo.java

@@ -27,7 +27,7 @@ public class DiscernReceiptPo implements Serializable {
      */
     private Integer payType;
     /**
-     * 收款款项类型:1订单款,2非订单款,3返佣款 , 5供应商退款,6超级会员款 ,7二手商品上架费
+     * 收款款项类型:1订单款,2非订单款,3返佣款 , 5供应商退款,6超级会员款 ,7二手商品上架费,8优惠券购买费
      */
     private Integer receiptType;
     /**

+ 4 - 0
src/main/java/com/caimei365/order/model/po/OrderReceiptRelationPo.java

@@ -37,6 +37,10 @@ public class OrderReceiptRelationPo implements Serializable {
      *  超级会员购买记录Id
      */
     private Integer vipRecordId;
+    /**
+     * 优惠券购买记录id
+     */
+    private Integer couponRecordId;
     /**
      * 删除标记 0 否,其余是
      */

+ 4 - 0
src/main/java/com/caimei365/order/model/po/SplitAccountPo.java

@@ -36,6 +36,10 @@ public class SplitAccountPo implements Serializable {
      * 超级会员套餐id
      */
     private Integer vipRecordId;
+    /**
+     * 优惠券购买记录id
+     */
+    private Integer couponRecordId;
     /**
      * 分账类型:1公账-专票,2私账-无票,3公账-普票,4供应商子商户,5佣金账户
      */

+ 4 - 0
src/main/java/com/caimei365/order/model/vo/OrderPayLinkVo.java

@@ -25,6 +25,10 @@ public class OrderPayLinkVo implements Serializable {
      * 会员购买记录Id
      */
     private Integer vipRecordId;
+    /**
+     * 优惠券购买记录id
+     */
+    private Integer couponRecordId;
     /**
      * 会员套餐包月数
      */

+ 15 - 0
src/main/java/com/caimei365/order/service/PayNonOrderService.java

@@ -2,6 +2,7 @@ package com.caimei365.order.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.dto.PayCouponDto;
 import com.caimei365.order.model.dto.PaySecondDto;
 import com.caimei365.order.model.dto.PayVipDto;
 import org.springframework.http.HttpHeaders;
@@ -89,4 +90,18 @@ public interface PayNonOrderService {
      * }
      */
     ResponseJson<JSONObject> superVipOnlineRefund(PayVipDto payVipDto) throws NoSuchAlgorithmException, InvalidKeySpecException;
+
+    /**
+     * 微信购买优惠券
+     * @param payCouponDto
+     * @param headers
+     * @return
+     */
+    ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, HttpHeaders headers);
+
+    String couponCallback(String data) throws NoSuchAlgorithmException, InvalidKeySpecException;
+
+    ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, HttpHeaders headers);
+
+    ResponseJson<JSONObject> payCouponUnionPay(PayCouponDto payCouponDto, HttpHeaders headers);
 }

+ 265 - 4
src/main/java/com/caimei365/order/service/impl/PayNonOrderServiceImpl.java

@@ -3,17 +3,16 @@ package com.caimei365.order.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei365.order.components.WeChatService;
 import com.caimei365.order.mapper.BaseMapper;
+import com.caimei365.order.mapper.OrderClubMapper;
 import com.caimei365.order.mapper.OrderCommonMapper;
 import com.caimei365.order.mapper.PayOrderMapper;
 import com.caimei365.order.model.ResponseJson;
 import com.caimei365.order.model.bo.PayParamBo;
 import com.caimei365.order.model.bo.VipRecordBo;
+import com.caimei365.order.model.dto.PayCouponDto;
 import com.caimei365.order.model.dto.PaySecondDto;
 import com.caimei365.order.model.dto.PayVipDto;
-import com.caimei365.order.model.po.DiscernReceiptPo;
-import com.caimei365.order.model.po.OrderReceiptRelationPo;
-import com.caimei365.order.model.po.SplitAccountPo;
-import com.caimei365.order.model.po.UserVipPo;
+import com.caimei365.order.model.po.*;
 import com.caimei365.order.model.vo.DiscernReceiptVo;
 import com.caimei365.order.model.vo.OrderPayLinkVo;
 import com.caimei365.order.service.PayNonOrderService;
@@ -52,11 +51,15 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
     @Resource
     private OrderCommonMapper orderCommonMapper;
     @Resource
+    private OrderClubMapper orderClubMapper;
+    @Resource
     private WeChatService weChatService;
     @Value("${pay.second-notify-url}")
     private String secondHandUrl;
     @Value("${pay.vip-notify-url}")
     private String superVipUrl;
+
+    private String couponUrl;
     @Resource
     private RemoteCallService remoteCallService;
 
@@ -730,4 +733,262 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
         log.info("【线上退款】成功>>>>>>>vipRecordId:" + payVipDto.getVipRecordId());
         return ResponseJson.success(result);
     }
+
+    /**
+     * 微信买优惠券
+     * @param payCouponDto
+     * @param headers
+     * @return
+     */
+    @Override
+    public ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, HttpHeaders headers) {
+        PayParamBo tempParam = new PayParamBo();
+        // payDto -> payParam
+        BeanUtils.copyProperties(payCouponDto, tempParam);
+        ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
+        if (-1 == jsonParam.getCode()) {
+            return ResponseJson.error(jsonParam.getMsg(), null);
+        }
+        PayParamBo payParam = jsonParam.getData();
+        // 获取优惠券价格
+        Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
+        payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
+        payParam.setNotifyUrl(couponUrl);
+        CouponRecordPo cr = new CouponRecordPo();
+        cr.setCouponId(payCouponDto.getCouponId());
+        cr.setUserId(payCouponDto.getUserId());
+        payOrderMapper.insertCouponRecord(cr);
+        payParam.setCouponRecordId(cr.getId());
+        log.info("【购买价值优惠券微信支付】>>>>>>>>>>>couponId:" + payParam.getCouponId() + ",获取openId:" + payParam.getOpenId());
+        return toPayCoupon(payParam, headers);
+    }
+
+    /**
+     * 支付宝买优惠券
+     *
+     * @param headers
+     */
+    @Override
+    public ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, HttpHeaders headers) {
+        PayParamBo payParam = new PayParamBo();
+        // payDto -> payParam
+        BeanUtils.copyProperties(payCouponDto, payParam);
+        //支付宝支付
+        payParam.setPayWay("ALIPAY");
+        payParam.setPayType("ALIPAY_H5");
+        // 获取优惠券价格
+        Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
+        payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
+        payParam.setNotifyUrl(couponUrl);
+        CouponRecordPo cr = new CouponRecordPo();
+        cr.setCouponId(payCouponDto.getCouponId());
+        cr.setUserId(payCouponDto.getUserId());
+        payOrderMapper.insertCouponRecord(cr);
+        payParam.setCouponRecordId(cr.getId());
+        log.info("【购买价值优惠券支付宝支付】>>>>>>>>>>>couponId:" + payParam.getCouponId());
+        return toPayCoupon(payParam, headers);
+    }
+
+    @Override
+    public ResponseJson<JSONObject> payCouponUnionPay(PayCouponDto payCouponDto, HttpHeaders headers) {
+        PayParamBo payParam = new PayParamBo();
+        // payDto -> payParam
+        BeanUtils.copyProperties(payCouponDto, payParam);
+        // 银联支付
+        payParam.setPayWay("UNIONPAY");
+        payParam.setPayType("GATEWAY_UNIONPAY");
+        // 获取会员套餐价格
+        Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
+        payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
+        payParam.setNotifyUrl(couponUrl);
+        CouponRecordPo cr = new CouponRecordPo();
+        cr.setCouponId(payCouponDto.getCouponId());
+        cr.setUserId(payCouponDto.getUserId());
+        payOrderMapper.insertCouponRecord(cr);
+        payParam.setCouponRecordId(cr.getId());
+        log.info("【购买价值优惠券银联线上支付】>>>>>>>>>>>vipRecordId:" + payParam.getVipRecordId());
+        return toPayCoupon(payParam, headers);
+    }
+
+
+    private ResponseJson<JSONObject> toPayCoupon(PayParamBo payParam, HttpHeaders headers) {
+        // 定义支付请求结果
+        JSONObject result = null;
+        try {
+            // 时间戳
+            long time = System.currentTimeMillis() / 1000;
+            // 设置支付基础参数
+            JSONObject json = getPayJsonObject(payParam, headers, time);
+            // 支付环境
+            String environment = "";
+            if (payParam.getNotifyUrl().contains("18002")) {
+                environment = "DEV";
+            } else if (payParam.getNotifyUrl().contains("core-b")) {
+                environment = "BETA";
+            }
+            // 商户订单号
+            String orderId = payParam.getUserId() + "C" + payParam.getCouponId() + "R" + payParam.getCouponRecordId() + "T" + time + environment;
+            json.put("orderId", orderId);
+            //商品名称
+            String product = "采美订单" + orderId;
+            json.put("product", product);
+            //支付类型
+            String payType = PayUtil.getPayTypeId(payParam.getPayType(), payParam.getUserType());
+            String attach = payParam.getCouponId() + "," + payParam.getUserId() + "," + payParam.getCouponRecordId() + "," + payType;
+            json.put("attach", attach);
+            // 价值优惠券默认公账专票,彩美信息
+            List<Map<String, String>> list = new ArrayList<>();
+            Map<String, String> map = new HashMap<>(3);
+            map.put("subUserNo", PayUtil.publicAccountNo);
+            // 1按比例分账
+            map.put("splitBillType", "1");
+            // 1比例值总额
+            map.put("splitBillValue", "1");
+            list.add(map);
+            String splitBillDetail = JSONObject.toJSONString(list);
+            json.put("splitBillDetail", splitBillDetail);
+            String sign = PayUtil.getPaySign(json, PayUtil.merKey);
+            json.put("sign", sign);
+            // 私钥加密
+            String data = RSAUtil.privateEncrypt(json.toJSONString(), PayUtil.merKey);
+            // 提交
+            result = PayUtil.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", PayUtil.merAccount, data);
+        } catch (Exception e) {
+            log.error("错误信息", e);
+            return ResponseJson.error("支付失败!", null);
+        }
+        String code = result.getString("code");
+        if (!"000000".equals(code)) {
+            String msg = result.getString("msg");
+            log.info("第三方支付失败>>>>>>>msg:" + msg);
+            return ResponseJson.error(msg, null);
+        }
+        // 保存购买优惠券分账参数
+        JSONObject data = result.getJSONObject("data");
+        SplitAccountPo splitAccount = new SplitAccountPo();
+        splitAccount.setCouponRecordId(payParam.getCouponRecordId());
+        // 优惠券 公账-专票
+        splitAccount.setType(1);
+        // 待分账总金额
+        double splitAmount = MathUtil.div(payParam.getPayAmount(), 100).doubleValue();
+        // 总手续费
+        double procedureFee;
+        if ("UNIONPAY".equals(payParam.getPayWay())) {
+            procedureFee = 8.00;
+        } else {
+            //手续费
+            procedureFee = MathUtil.mul(splitAmount, 0.0038, 2).doubleValue();
+            if (MathUtil.compare(procedureFee, 0) == 0) {
+                procedureFee = 0.01;
+            }
+        }
+        splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
+        splitAccount.setSplitAccount(splitAmount);
+        splitAccount.setMbOrderId(data.getString("mbOrderId"));
+        splitAccount.setOrderRequestNo(data.getString("orderId"));
+        splitAccount.setPayStatus(0);
+        // 保存分账详情
+        payOrderMapper.insertSplitAccount(splitAccount);
+        log.info("【购买优惠券支付成功!】>>>>>>>>>>>couponRecordId:" + payParam.getCouponRecordId() + ",data:" + data.toJSONString());
+        return ResponseJson.success(result);
+    }
+
+    @Override
+    public String couponCallback(String data) throws NoSuchAlgorithmException, InvalidKeySpecException {
+        log.info("******************** 购买优惠券异步回调 start *******************");
+        // 公钥解密
+        JSONObject json = PayUtil.publicKeyDecrypt(data, PayUtil.publicKey);
+        log.info("【购买优惠券异步回调】>>>>>>>>>>>公钥解密:" + json);
+        // 公钥验签
+        String signaa = json.getString("sign");
+        json.remove("sign");
+        String signbb = PayUtil.getPaySign(json, PayUtil.publicKey);
+        if (!signaa.equals(signbb)) {
+            return "验签失败";
+        }
+        // 订单状态
+        String orderStatus = json.getString("orderStatus");
+        // 平台唯一流水号
+        String mbOrderId = json.getString("mbOrderId");
+        // 商户唯一订单号
+        String orderRequestNo = json.getString("orderId");
+        // 金额,以元为单位
+        Double amount = json.getDouble("amount");
+        String payFormData = json.toJSONString();
+        log.info("【购买优惠券异步回调】>>>>>>>>>>>支付订单状态:" + orderStatus);
+        if ("FAILED".equals(orderStatus)) {
+            return "支付失败";
+        }
+        log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>本次支付金额:" + amount);
+        // 附加数据,支付时若有传输则原样返回(vipId,userId,recordId,payType),下单时为空,则不返回该数据
+        String attach = json.getString("attach");
+        String[] split = attach.split(",");
+        int couponId = 0;
+        int userId = 0;
+        int recordId = 0;
+        int payType = 0;
+        try {
+            // 优惠券Id
+            couponId = Integer.parseInt(split[0]);
+            // 用户Id
+            userId = Integer.parseInt(split[1]);
+            // 购买历史记录Id
+            recordId = Integer.parseInt(split[2]);
+            // 支付方式
+            payType = Integer.parseInt(split[3]);
+        } catch (NumberFormatException e) {
+            log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>获取回调参数解析失败!");
+        }
+        //cm_coupon_club数据库修改
+        CouponClubPo couponClubPo = new CouponClubPo();
+        couponClubPo.setUserId(userId);
+        couponClubPo.setCouponId(couponId);
+        couponClubPo.setStatus("1");
+        couponClubPo.setDelFlag("0");
+        orderClubMapper.insertCouponClub(couponClubPo);
+        // 改历史记录支付状态
+        payOrderMapper.updateCouponRecord(recordId);
+        //todo 修改支付链接状态
+        OrderPayLinkVo orderPayLink = payOrderMapper.getCouponPayLink(recordId, amount);
+        if (null != orderPayLink && (12 == payType || 17 == payType)) {
+            orderPayLink.setPayStatus(1);
+            payOrderMapper.updateOrderPayLinkStatus(orderPayLink);
+        }
+        Date date = new Date();
+        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+        // 保存收款记录
+        DiscernReceiptPo discernReceipt = new DiscernReceiptPo();
+        discernReceipt.setPayWay(1);
+        discernReceipt.setPayType(payType);
+        discernReceipt.setReceiptType(8);
+        discernReceipt.setReceiptStatus(3);
+        discernReceipt.setReceiptAmount(amount);
+        discernReceipt.setConfirmType(4);
+        discernReceipt.setRePayFlag(1);
+        discernReceipt.setFormData(payFormData);
+        discernReceipt.setReceiptDate(curDateStr);
+        discernReceipt.setConfirmDate(curDateStr);
+        discernReceipt.setReviewDate(curDateStr);
+        discernReceipt.setUpdateDate(curDateStr);
+        discernReceipt.setDelFlag(0);
+        // 保存 收款记录
+        baseMapper.insertDiscernReceipt(discernReceipt);
+        log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>保存识别款项(insert[cm_discern_receipt])id:" + discernReceipt.getId() + ",vipRecordId:" + recordId);
+        // 收款项和订单关系表
+        OrderReceiptRelationPo relation = new OrderReceiptRelationPo();
+        relation.setReceiptId(discernReceipt.getId());
+        relation.setCouponRecordId(recordId);
+        relation.setAssociateAmount(amount);
+        relation.setMbOrderId(mbOrderId);
+        relation.setOrderRequestNo(orderRequestNo);
+        relation.setSplitStatus(1);
+        relation.setRelationType(6);
+        relation.setDelFlag(0);
+        // 保存 收款项和订单关系
+        baseMapper.insertOrderReceiptRelation(relation);
+        log.info("【购买优惠券异步回调】>>>>>>>>>>>收款项和购买历史关系(insert[cm_receipt_order_relation])id:" + relation.getId() + ",vipRecordId:" + recordId);
+        //修改分账付款状态
+        payOrderMapper.updateSplitAccountByPay(mbOrderId);
+        return "SUCCESS";
+    }
 }

+ 35 - 2
src/main/resources/mapper/PayOrderMapper.xml

@@ -37,9 +37,9 @@
         VALUES (#{orderId}, #{vipRecordId}, #{vipMonth}, #{linkLogo}, #{unpaidAmount}, #{generateTime}, #{effectiveTime}, #{payStatus}, #{payType}, #{delFlag})
     </insert>
     <insert id="insertSplitAccount" keyColumn="id" keyProperty="id"  parameterType="com.caimei365.order.model.po.SplitAccountPo">
-        INSERT INTO cm_split_account (orderId, productId, orderProductId, shopId, vipRecordId, type, subUserNo, splitAccount,
+        INSERT INTO cm_split_account (orderId, productId, orderProductId, shopId, couponRecordId,vipRecordId, type, subUserNo, splitAccount,
                                         mbOrderId, orderRequestNo,payStatus, productType, splitTime)
-        VALUES (#{orderId}, #{productId}, #{orderProductId}, #{shopId},#{vipRecordId}, #{type}, #{subUserNo}, #{splitAccount},
+        VALUES (#{orderId}, #{productId}, #{orderProductId}, #{shopId},#{couponRecordId},#{vipRecordId}, #{type}, #{subUserNo}, #{splitAccount},
                 #{mbOrderId}, #{orderRequestNo}, #{payStatus}, #{productType}, NOW());
     </insert>
     <insert id="insertPayShop" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.PayShopPo">
@@ -58,6 +58,9 @@
         INSERT INTO cm_svip_user(userId, beginTime, endTime, delFlag, updateTime)
         VALUES (#{userId}, #{beginTime}, #{endTime}, #{delFlag}, #{updateTime})
     </insert>
+    <insert id="insertCouponRecord" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.CouponOrderRecordPo">
+        INSERT INTO cm_coupon_buyrecord (couponId, userId) VALUES (#{couponId},#{userId})
+    </insert>
     <update id="updateUserVipInfo">
         UPDATE cm_svip_user set userId=#{userId}, beginTime=#{beginTime}, endTime=#{endTime}, delFlag=#{delFlag}, updateTime=#{updateTime}
         WHERE userId = #{userId}
@@ -109,6 +112,11 @@
         ableUserMoney = #{ableUserMoney}
         WHERE userID = #{userId}
     </update>
+    <update id="updateCouponRecord">
+        update cm_coupon_buyrecord
+        set payStatus = 1
+        where id = #{recordId}
+    </update>
     <select id="getPayOnLineSwitch" resultType="java.lang.Integer">
         SELECT STATUS FROM cm_pay_online_switch WHERE id=1
     </select>
@@ -288,4 +296,29 @@
           AND cubr.balanceType = 10
           AND cror.associateAmount > 0.01
     </select>
+    <select id="getCouponPrice" resultType="java.lang.Double">
+        select moneyCouponPrice from cm_coupon where id = #{couponId}
+    </select>
+    <select id="getCouponPayLink" resultType="com.caimei365.order.model.vo.OrderPayLinkVo">
+        SELECT
+        id,
+        orderId,
+        vipRecordId,
+        couponRecordId,
+        linkLogo,
+        unpaidAmount,
+        generateTime,
+        effectiveTime,
+        payStatus,
+        payType,
+        delFlag
+        FROM
+        cm_order_pay_link
+        WHERE vipRecordId = #{vipRecordId}
+        <if test="amount != null">
+            AND unpaidAmount = #{amount}
+        </if>
+        AND delFlag = '0' AND payStatus = '0'
+        ORDER BY id DESC LIMIT 1
+    </select>
 </mapper>