plf před 3 roky
rodič
revize
04fe7998cf

+ 63 - 0
base-module/src/main/java/com/caimei/module/base/entity/po/CouponClubPo.java

@@ -0,0 +1,63 @@
+package com.caimei.module.base.entity.po;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : plf
+ * @date : 2021/8/16
+ */
+@Data
+public class CouponClubPo {
+    private Integer id;
+
+    /**
+     * 机构用户Id
+     */
+    private Integer userId;
+
+    /**
+     * 优惠券id
+     */
+    private Integer couponId;
+
+    /**
+     * 订单id
+     */
+    private Integer orderId;
+
+    /**
+     * 退款id,订单退回时有效
+     */
+    private Integer returnedId;
+
+
+    /**
+     * 领取渠道:1网站 2小程序 3订单退回
+     */
+    private Integer source;
+
+    /**
+     * 使用状态 1未使用 2已使用
+     */
+    private String status;
+
+    /**
+     * 领取时间
+     */
+    private Date createDate;
+
+    /**
+     * 使用时间
+     */
+    private Date useDate;
+
+    /**
+     * 删除标记 0否 其余是
+     */
+    private String delFlag;
+
+}

+ 49 - 0
base-module/src/main/java/com/caimei/module/base/entity/po/CouponRedemptionCodePo.java

@@ -0,0 +1,49 @@
+package com.caimei.module.base.entity.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : plf
+ * @date : 2021/8/12
+ */
+@Data
+public class CouponRedemptionCodePo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Integer id;
+
+    /**
+     * 优惠券id
+     */
+    private Integer couponId;
+
+    /**
+     * 用户关联优惠券id(对应cm_coupon_club)
+     */
+    private Integer clubCouponId;
+
+    /**
+     * 兑换码(16位)
+     */
+    private String redemptionCode;
+
+    /**
+     * 兑换状态:1未兑换 2已兑换
+     */
+    private Integer status;
+
+    /**
+     * 兑换时间
+     */
+    private Date redemptionTime;
+
+    /**
+     * 添加时间
+     */
+    private Date addTime;
+}

+ 25 - 0
pay/src/main/java/com/caimei/module/pay/dao/PayDao.java

@@ -1,5 +1,7 @@
 package com.caimei.module.pay.dao;
 
+import com.caimei.module.base.entity.po.CouponClubPo;
+import com.caimei.module.base.entity.po.CouponRedemptionCodePo;
 import com.caimei.module.base.entity.po.SeconHandProduct;
 import com.caimei.module.base.entity.po.UserBeansHistoryPo;
 import com.caimei.module.base.entity.vo.*;
@@ -206,4 +208,27 @@ public interface PayDao {
      * @param num
      */
     void updateSendNum(@Param("markId") int markId, @Param("num") int num);
+
+    /**
+     * 查询一张未使用兑换码券
+     *
+     * @param couponId
+     * @return
+     */
+    CouponRedemptionCodePo findRedemptionCode(int couponId);
+
+    /**
+     * 保存优惠券用户关联表
+     *
+     * @param couponClub
+     */
+    void insertCouponClub(CouponClubPo couponClub);
+
+    /**
+     * 更新兑换状态
+     *
+     * @param id           兑换码id
+     * @param clubCouponId 用户关联优惠券id
+     */
+    void updateRedemptionCode(@Param("id") Integer id, @Param("clubCouponId") Integer clubCouponId);
 }

+ 8 - 0
pay/src/main/java/com/caimei/module/pay/service/PayService.java

@@ -3,6 +3,7 @@ package com.caimei.module.pay.service;
 import com.caimei.module.base.entity.bo.JsonModel;
 import com.caimei.module.base.entity.bo.Payment;
 import com.caimei.module.base.entity.vo.OrderPayLinkVo;
+import com.caimei.module.base.entity.vo.OrderVo;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -108,4 +109,11 @@ public interface PayService {
      * @return SUCCESS告诉第三方回调成功
      */
     String delayedSplittingCallback(String data);
+
+    /**
+     * 针对商品productId:6898,做兑换券操作(couponId:15)
+     *
+     * @param order
+     */
+    void saveCouponClub(OrderVo order);
 }

+ 36 - 0
pay/src/main/java/com/caimei/module/pay/service/impl/PayServiceImpl.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.module.base.entity.bo.JsonModel;
 import com.caimei.module.base.entity.bo.Payment;
+import com.caimei.module.base.entity.po.CouponClubPo;
+import com.caimei.module.base.entity.po.CouponRedemptionCodePo;
 import com.caimei.module.base.entity.po.SeconHandProduct;
 import com.caimei.module.base.entity.po.UserBeansHistoryPo;
 import com.caimei.module.base.entity.vo.*;
@@ -521,6 +523,8 @@ public class PayServiceImpl implements PayService {
         log.info(">>>>>>>>>>>>>>>>>>>>>>>保存付款金额到收款记录," + amount);
         //判断是否是充值商品
         getRechargeGoods(order, amount);
+        //针对商品productId:6898,做兑换券操作(couponId:15)
+        saveCouponClub(order);
         //线上支付与自主下单送豆
         UserVo user = payDao.findUser(order.getUserID());
         if (user != null && "3".equals(order.getReceiptStatus()) && "0".equals(order.getSecondHandOrderFlag())) {
@@ -589,6 +593,38 @@ public class PayServiceImpl implements PayService {
         return "SUCCESS";
     }
 
+    /**
+     * 针对商品productId:6898,做兑换券操作(couponId:15)
+     */
+    @Override
+    public void saveCouponClub(OrderVo order) {
+        if ("3".equals(order.getReceiptStatus())) {
+            List<OrderProductVo> orderProductList = payDao.fandAllOrderProduct(order.getOrderID().intValue());
+            if (orderProductList != null && orderProductList.size() > 0) {
+                for (OrderProductVo orderProduct : orderProductList) {
+                    if (orderProduct.getProductID().equals(6898)) {
+                        Integer num = orderProduct.getNum();
+                        for (int i = 0; i < num; i++) {
+                            CouponRedemptionCodePo redemptionCode = payDao.findRedemptionCode(15);
+                            if (redemptionCode != null) {
+                                CouponClubPo couponClub = new CouponClubPo();
+                                couponClub.setCouponId(redemptionCode.getCouponId());
+                                couponClub.setUserId(order.getUserID().intValue());
+                                couponClub.setSource(5);
+                                couponClub.setStatus("1");
+                                couponClub.setCreateDate(new Date());
+                                couponClub.setDelFlag("0");
+                                payDao.insertCouponClub(couponClub);
+                                payDao.updateRedemptionCode(redemptionCode.getId(), couponClub.getId());
+                            }
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
     public String getShortLink(int length, int markId, String url) {
         String shortLink = RandomCodeGenerator.generateShortLink(length);
         Integer id = payDao.findBYShortLink(shortLink);

+ 55 - 0
pay/src/main/resources/com-caimei-module-pay/PayMapper.xml

@@ -624,4 +624,59 @@
     <update id="updateSendNum">
         UPDATE cm_sms_statistics SET sendNum = (sendNum + #{num}) WHERE markId = #{markId}
     </update>
+
+    <select id="findRedemptionCode" resultType="com.caimei.module.base.entity.po.CouponRedemptionCodePo">
+        SELECT
+          `id`,
+          `couponId`,
+          `clubCouponId`,
+          `redemptionCode`,
+          `status`,
+          `redemptionTime`,
+          `addTime`
+        FROM
+          cm_coupon_redemption_code
+        WHERE
+          couponId = #{couponId}
+          AND STATUS = 1
+        ORDER BY
+          id
+        LIMIT
+          1
+    </select>
+
+    <insert id="insertCouponClub" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+        INSERT INTO `cm_coupon_club` (
+          `userId`,
+          `couponId`,
+          `orderId`,
+          `source`,
+          `status`,
+          `createDate`,
+          `useDate`,
+          `delFlag`
+        )
+        VALUES
+          (
+            #{userId},
+            #{couponId},
+            #{orderId},
+            #{source},
+            #{status},
+            #{createDate},
+            #{useDate},
+            #{delFlag}
+          )
+    </insert>
+
+    <update id="updateRedemptionCode">
+        UPDATE
+          cm_coupon_redemption_code
+        SET
+          STATUS = 2,
+          redemptionTime = NOW(),
+          clubCouponId = #{clubCouponId}
+        WHERE
+          id = #{id}
+    </update>
 </mapper>