zhijiezhao 3 years ago
parent
commit
10a698bc16

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

@@ -214,12 +214,26 @@ public class PayNonOrderApi {
         return payNonOrderService.superVipOnlineRefund(payVipDto);
     }
 
+
+    @ApiOperation("购买价值优惠券-获取购买记录id")
+    @PostMapping("/coupon/record")
+    public ResponseJson<PayCouponDto> payCouponGetRecord(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers) {
+        if (null == payCouponDto.getCouponId()) {
+            return ResponseJson.error("优惠券Id不能为空!", null);
+        }
+        if (null == payCouponDto.getUserId()) {
+            return ResponseJson.error("userId不能为空!", null);
+        }
+        return payNonOrderService.getCouponRecord(payCouponDto, headers);
+    }
+
     /**
      * 升级超级会员-微信线上支付
      *
      * @param payCouponDto {
      *                     couponId      购买优惠券Id
      *                     userId        userId
+     *                     couponRecordId  购买记录id
      *                     returnUrl     页面回调地址
      *                     code          微信小程序code
      *                     state         微信公众号state参数
@@ -228,6 +242,9 @@ public class PayNonOrderApi {
     @ApiOperation("购买价值优惠券-微信线上支付")
     @PostMapping("/coupon/wechat")
     public ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers) {
+        if (null == payCouponDto.getCouponRecordId()) {
+            return ResponseJson.error("购买记录id不能为空!", null);
+        }
         if (null == payCouponDto.getSource()) {
             return ResponseJson.error("领取渠道不能为空!", null);
         }
@@ -247,6 +264,7 @@ public class PayNonOrderApi {
      * 购买价值优惠券-支付宝线上支付
      *
      * @param payCouponDto {
+     *                     couponRecordId  购买记录id
      *                     couponId      购买优惠券Id
      *                     userId        userId
      *                     returnUrl     页面回调地址
@@ -255,6 +273,9 @@ public class PayNonOrderApi {
     @ApiOperation("购买价值优惠券-支付宝线上支付")
     @PostMapping("/coupon/alipay")
     public ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers) {
+        if (null == payCouponDto.getCouponRecordId()) {
+            return ResponseJson.error("购买记录id不能为空!", null);
+        }
         if (null == payCouponDto.getSource()) {
             return ResponseJson.error("领取渠道不能为空!", null);
         }
@@ -271,6 +292,7 @@ public class PayNonOrderApi {
      * 购买价值优惠券-银联线上支付
      *
      * @param payCouponDto {
+     *                     couponRecordId  购买记录id
      *                     userID        用户id
      *                     couponId      购买优惠券Id
      *                     returnUrl     页面回调地址
@@ -281,6 +303,9 @@ public class PayNonOrderApi {
     @ApiOperation("购买价值优惠券-银联线上支付")
     @PostMapping("/coupon/union")
     public ResponseJson<JSONObject> payCouponByUnionPay(PayCouponDto payCouponDto, @RequestHeader HttpHeaders headers) {
+        if (null == payCouponDto.getCouponRecordId()) {
+            return ResponseJson.error("购买记录id不能为空!", null);
+        }
         if (null == payCouponDto.getSource()) {
             return ResponseJson.error("领取渠道不能为空!", null);
         }
@@ -302,6 +327,19 @@ public class PayNonOrderApi {
         return payNonOrderService.payCouponUnionPay(payCouponDto, headers);
     }
 
+    /**
+     * 购买优惠券-查询是否购买成功
+     */
+    @ApiOperation("购买优惠券-查询是否购买成功")
+    @GetMapping("/coupon/check")
+    public ResponseJson couponCheck(Integer couponRecordId) {
+        if (null == couponRecordId) {
+            return ResponseJson.error("购买记录id不能为空!", null);
+        }
+        return payNonOrderService.couponCheck(couponRecordId);
+    }
+
+
     /**
      * 购买优惠券-支付回调
      */
@@ -314,4 +352,16 @@ public class PayNonOrderApi {
         return payNonOrderService.couponCallback(data);
     }
 
+    /**
+     * 购买优惠券-查询是否购买成功
+     */
+    @ApiOperation("购买超级会员-查询是否购买成功")
+    @GetMapping("/vip/check")
+    public ResponseJson vipCheck(Integer recordId) {
+        if (null == recordId) {
+            return ResponseJson.error("购买记录id不能为空!", null);
+        }
+        return payNonOrderService.vipCheck(recordId);
+    }
+
 }

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

@@ -192,4 +192,6 @@ public interface PayOrderMapper {
     void insertCouponRecord(CouponRecordPo cr);
 
     void updateCouponRecord(Integer recordId);
+
+    Integer findPayStatus(Integer recordId);
 }

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

@@ -18,6 +18,11 @@ public class PayCouponDto implements Serializable {
      */
     @ApiModelProperty("userId")
     private Integer userId;
+    /**
+     * 购买记录id
+     */
+    @ApiModelProperty("购买记录id")
+    private Integer couponRecordId;
     /**
      * 页面回调地址
      */

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

@@ -104,4 +104,10 @@ public interface PayNonOrderService {
     ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, HttpHeaders headers);
 
     ResponseJson<JSONObject> payCouponUnionPay(PayCouponDto payCouponDto, HttpHeaders headers);
+
+    ResponseJson<PayCouponDto> getCouponRecord(PayCouponDto payCouponDto, HttpHeaders headers);
+
+    ResponseJson couponCheck(Integer recordId);
+
+    ResponseJson vipCheck(Integer recordId);
 }

+ 43 - 14
src/main/java/com/caimei365/order/service/impl/PayNonOrderServiceImpl.java

@@ -745,6 +745,10 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
      */
     @Override
     public ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, HttpHeaders headers) {
+        Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
+        if (null != status && 1 == status) {
+            return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
+        }
         PayParamBo tempParam = new PayParamBo();
         // payDto -> payParam
         BeanUtils.copyProperties(payCouponDto, tempParam);
@@ -757,11 +761,7 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
         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());
+        payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
         log.info("【购买价值优惠券微信支付】>>>>>>>>>>>couponId:" + payParam.getCouponId() + ",获取openId:" + payParam.getOpenId());
         return toPayCoupon(payParam, headers);
     }
@@ -773,6 +773,10 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
      */
     @Override
     public ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, HttpHeaders headers) {
+        Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
+        if (null != status && 1 == status) {
+            return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
+        }
         PayParamBo payParam = new PayParamBo();
         // payDto -> payParam
         BeanUtils.copyProperties(payCouponDto, payParam);
@@ -783,17 +787,17 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
         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());
+        payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
         log.info("【购买价值优惠券支付宝支付】>>>>>>>>>>>couponId:" + payParam.getCouponId());
         return toPayCoupon(payParam, headers);
     }
 
     @Override
     public ResponseJson<JSONObject> payCouponUnionPay(PayCouponDto payCouponDto, HttpHeaders headers) {
+        Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
+        if (null != status && 1 == status) {
+            return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
+        }
         PayParamBo payParam = new PayParamBo();
         // payDto -> payParam
         BeanUtils.copyProperties(payCouponDto, payParam);
@@ -807,13 +811,38 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
         }
         payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
         payParam.setNotifyUrl(couponUrl);
+        payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
+        log.info("【购买价值优惠券银联线上支付】>>>>>>>>>>>RecordId:" + payCouponDto.getCouponRecordId());
+        return toPayCoupon(payParam, headers);
+    }
+
+    @Override
+    public ResponseJson<PayCouponDto> getCouponRecord(PayCouponDto payCouponDto, HttpHeaders headers) {
         CouponRecordPo cr = new CouponRecordPo();
         cr.setCouponId(payCouponDto.getCouponId());
         cr.setUserId(payCouponDto.getUserId());
         payOrderMapper.insertCouponRecord(cr);
-        payParam.setCouponRecordId(cr.getId());
-        log.info("【购买价值优惠券银联线上支付】>>>>>>>>>>>RecordId:" + cr.getId());
-        return toPayCoupon(payParam, headers);
+        payCouponDto.setCouponRecordId(cr.getId());
+        return ResponseJson.success(payCouponDto);
+    }
+
+    @Override
+    public ResponseJson couponCheck(Integer recordId) {
+        Integer status = payOrderMapper.findPayStatus(recordId);
+        if (null != status && 1 == status) {
+            return ResponseJson.success("支付成功", null);
+        }
+        return ResponseJson.error("支付失败", null);
+    }
+
+    @Override
+    public ResponseJson vipCheck(Integer recordId) {
+        // 获取会员套餐记录
+        VipRecordBo record = payOrderMapper.getVipPackageRecord(recordId);
+        if (null != record.getPayStatus() && 1 == record.getPayStatus()) {
+            return ResponseJson.success("支付成功!", null);
+        }
+        return ResponseJson.error("支付失败", null);
     }
 
 
@@ -945,7 +974,7 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
             // 支付方式
             payType = Integer.parseInt(split[3]);
             //购买渠道
-            source=Integer.parseInt(split[4]);
+            source = Integer.parseInt(split[4]);
         } catch (NumberFormatException e) {
             log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>获取回调参数解析失败!");
         }

+ 3 - 0
src/main/resources/mapper/PayOrderMapper.xml

@@ -299,4 +299,7 @@
     <select id="getCouponPrice" resultType="java.lang.Double">
         select moneyCouponPrice from cm_coupon where id = #{couponId}
     </select>
+    <select id="findPayStatus" resultType="java.lang.Integer">
+        select payStatus from cm_coupon_buyrecord where id = #{recordId}
+    </select>
 </mapper>