Browse Source

直播的优惠卷 -改为 发 课程优惠卷

三七 5 ngày trước cách đây
mục cha
commit
00505d95e0

+ 10 - 0
fs-service/src/main/java/com/fs/his/domain/FsCourseCouponUser.java

@@ -58,4 +58,14 @@ public class FsCourseCouponUser {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @TableField(fill = FieldFill.INSERT_UPDATE)
     private Date updateTime;
+
+
+    /** 类型  1课程发的 2直播发的 */
+    @Excel(name = "类型  1课程发的 2直播发的")
+    private Integer sendType;
+
+
+    /** 直播间id */
+    @Excel(name = "直播间id")
+    private Long liveId;
 }

+ 8 - 7
fs-service/src/main/java/com/fs/his/service/impl/FsCourseCouponServiceImpl.java

@@ -30,7 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 课程优惠券Service业务层处理
- * 
+ *
  * @author fs
  * @date 2026-05-13
  */
@@ -53,7 +53,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
     private FsCourseWatchLogMapper courseWatchLogMapper;
     /**
      * 查询课程优惠券
-     * 
+     *
      * @param id 课程优惠券主键
      * @return 课程优惠券
      */
@@ -65,7 +65,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
 
     /**
      * 查询课程优惠券列表
-     * 
+     *
      * @param fsCourseCoupon 课程优惠券
      * @return 课程优惠券
      */
@@ -77,7 +77,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
 
     /**
      * 新增课程优惠券
-     * 
+     *
      * @param fsCourseCoupon 课程优惠券
      * @return 结果
      */
@@ -91,7 +91,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
 
     /**
      * 修改课程优惠券
-     * 
+     *
      * @param fsCourseCoupon 课程优惠券
      * @return 结果
      */
@@ -104,7 +104,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
 
     /**
      * 批量删除课程优惠券
-     * 
+     *
      * @param ids 需要删除的课程优惠券主键
      * @return 结果
      */
@@ -116,7 +116,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
 
     /**
      * 删除课程优惠券信息
-     * 
+     *
      * @param id 课程优惠券主键
      * @return 结果
      */
@@ -371,6 +371,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
             couponUser.setLimitTime(fsCourseCoupon.getLimitTime());
             couponUser.setCreateTime(new Date());
             couponUser.setLogId(log.getLogId());
+            couponUser.setSendType(1);
             int i = courseCouponUserMapper.insertFsCourseCouponUser(couponUser);
 
             if (i > 0) {

+ 68 - 6
fs-service/src/main/java/com/fs/live/service/impl/LiveRedPacketLogServiceImpl.java

@@ -26,9 +26,9 @@ import com.fs.course.domain.*;
 import com.fs.course.mapper.BalanceRollbackErrorMapper;
 import com.fs.course.param.FsCourseSendRewardUParam;
 import com.fs.course.service.impl.FsUserCourseVideoServiceImpl;
-import com.fs.his.domain.FsUser;
-import com.fs.his.domain.FsUserIntegralLogs;
-import com.fs.his.domain.FsUserWx;
+import com.fs.his.domain.*;
+import com.fs.his.mapper.FsCourseCouponMapper;
+import com.fs.his.mapper.FsCourseCouponUserMapper;
 import com.fs.his.mapper.FsUserIntegralLogsMapper;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.param.WxSendRedPacketParam;
@@ -121,6 +121,12 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
     @Autowired
     private ILiveCouponUserService liveCouponUserService;
 
+    @Autowired
+    private FsCourseCouponMapper fsCourseCouponMapper;
+
+    @Autowired
+    private FsCourseCouponUserMapper courseCouponUserMapper;
+
 
     /**
      * 查询直播红包 记录
@@ -487,9 +493,9 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
             hasReward = true;
             combinedRewardType |= 2;
         }
-        // 核销卷
+        // 课程优惠卷(核销卷
         if (matched.getRewardTypes() != null && matched.getRewardTypes().contains("3")) {
-            sendIssueCoupon(param.getLiveId(),user.getUserId(),matched.getCouponId(),watchUser);
+            sendIssueCourseCoupon(param.getLiveId(),user.getUserId(),matched.getCouponId(),watchUser);
             hasReward = true;
             combinedRewardType |= 4;
         }
@@ -528,7 +534,7 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
     }
 
     /**
-    * 发放优惠
+    * 发放直播核销
     */
     public R sendIssueCoupon(Long liveId, Long userId, Long couponId,LiveWatchUser watchUser) {
 
@@ -602,6 +608,62 @@ public class LiveRedPacketLogServiceImpl extends ServiceImpl<LiveRedPacketLogMap
         return R.ok();
     }
 
+    /**
+     * 发放直播-课程优惠卷卷
+     */
+    public R sendIssueCourseCoupon(Long liveId, Long userId, Long couponId,LiveWatchUser watchUser) {
+
+        //优惠券
+        FsCourseCoupon fsCourseCoupon = fsCourseCouponMapper.selectFsCourseCouponById(couponId);
+
+        if (fsCourseCoupon == null) {
+            watchUser.setRemark("核销卷不存在-发放失败");
+            watchUserMapper.updateLiveWatchUser(watchUser);
+            return  R.ok();
+        }
+
+        if (fsCourseCoupon.getStatus() != 1) {
+            watchUser.setRemark("核销卷已停用-发放失败");
+            watchUserMapper.updateLiveWatchUser(watchUser);
+            return  R.ok();
+        }
+
+        if (fsCourseCoupon.getRemainNumber() <= 0) {
+            watchUser.setRemark("核销卷剩余数量不足-发放失败");
+            watchUserMapper.updateLiveWatchUser(watchUser);
+            return  R.ok();
+        }
+
+        //用户领取优惠券总数
+        Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, couponId);
+        if (count >= fsCourseCoupon.getLimitCount()) {
+            watchUser.setRemark("该核销卷领取达到上限,发放失败");
+            watchUserMapper.updateLiveWatchUser(watchUser);
+            return  R.ok();
+        }
+
+        //发放优惠券
+        FsCourseCouponUser couponUser = new FsCourseCouponUser();
+        couponUser.setCouponId(couponId);
+        couponUser.setUserId(userId);
+        couponUser.setStartTime(new Date());
+        couponUser.setLimitTime(fsCourseCoupon.getLimitTime());
+        couponUser.setCreateTime(new Date());
+        couponUser.setLiveId(liveId);
+        couponUser.setSendType(2);
+        int i = courseCouponUserMapper.insertFsCourseCouponUser(couponUser);
+
+        //扣库存
+        if (i > 0) {
+            FsCourseCoupon coupon = new FsCourseCoupon();
+            coupon.setId(couponId);
+            coupon.setRemainNumber(fsCourseCoupon.getRemainNumber() - 1);
+            fsCourseCouponMapper.updateFsCourseCoupon(coupon);
+        }
+
+        return R.ok();
+    }
+
     @Override
     public R syncLiveRedPacket(String outBatchNo, String batchId) {
         LiveRedPacketLog log = redPacketLogMapper.selectLiveRedPacketLogByBatchNo(outBatchNo);

+ 17 - 0
fs-service/src/main/resources/db/changelog/changes/20260613-live-user-add-is-del.sql

@@ -48,3 +48,20 @@ ALTER TABLE live_coupon_user
 ALTER TABLE live_coupon_user
     ADD COLUMN verify_time DATETIME DEFAULT NULL COMMENT '核销时间';
 --rollback ALTER TABLE live_coupon_user DROP COLUMN verify_time;
+
+
+--changeset sgw:20260618-fs_course_coupon_user_type
+--preconditions onFail:MARK_RAN
+--precondition-sql-check expectedResult:1 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'fs_course_coupon_user'
+--precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'fs_course_coupon_user' AND column_name = 'send_type'
+ALTER TABLE fs_course_coupon_user
+    ADD COLUMN send_type integer DEFAULT NULL COMMENT '类型  1课程发的 2直播发的';
+--rollback ALTER TABLE fs_course_coupon_user DROP COLUMN send_type;
+
+--changeset sgw:20260618-fs_course_coupon_user_live_id
+--preconditions onFail:MARK_RAN
+--precondition-sql-check expectedResult:1 SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'fs_course_coupon_user'
+--precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'fs_course_coupon_user' AND column_name = 'live_id'
+ALTER TABLE fs_course_coupon_user
+    ADD COLUMN live_id BIGINT DEFAULT NULL COMMENT '直播间id';
+--rollback ALTER TABLE fs_course_coupon_user DROP COLUMN type;

+ 18 - 8
fs-service/src/main/resources/mapper/his/FsCourseCouponUserMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fs.his.mapper.FsCourseCouponUserMapper">
-    
+
     <resultMap type="FsCourseCouponUser" id="FsCourseCouponUserResult">
         <result property="id"    column="id"    />
         <result property="couponId"    column="coupon_id"    />
@@ -14,29 +14,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateTime"    column="update_time"    />
         <result property="status"    column="status"    />
         <result property="logId"    column="log_id"    />
+        <result property="sendType"    column="send_type"    />
+        <result property="liveId"    column="live_id"    />
     </resultMap>
 
     <sql id="selectFsCourseCouponUserVo">
-        select id, coupon_id, user_id, limit_time, start_time, create_time, update_time, status, log_id from fs_course_coupon_user
+        select id, coupon_id, user_id, limit_time, start_time, create_time, update_time, status, log_id,send_type,live_id from fs_course_coupon_user
     </sql>
 
     <select id="selectFsCourseCouponUserList" parameterType="FsCourseCouponUser" resultMap="FsCourseCouponUserResult">
         <include refid="selectFsCourseCouponUserVo"/>
-        <where>  
+        <where>
             <if test="couponId != null "> and coupon_id = #{couponId}</if>
             <if test="userId != null "> and user_id = #{userId}</if>
             <if test="limitTime != null "> and limit_time = #{limitTime}</if>
             <if test="startTime != null "> and start_time = #{startTime}</if>
             <if test="status != null "> and status = #{status}</if>
-             <if test="logId != null "> and log_id = #{logId}</if>
+            <if test="logId != null "> and log_id = #{logId}</if>
+            <if test="sendType != null "> and send_type = #{sendType}</if>
+            <if test="liveId != null "> and live_id = #{liveId}</if>
         </where>
     </select>
-    
+
     <select id="selectFsCourseCouponUserById" parameterType="Long" resultMap="FsCourseCouponUserResult">
         <include refid="selectFsCourseCouponUserVo"/>
         where id = #{id}
     </select>
-        
+
     <insert id="insertFsCourseCouponUser" parameterType="FsCourseCouponUser" useGeneratedKeys="true" keyProperty="id">
         insert into fs_course_coupon_user
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -48,6 +52,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">update_time,</if>
             <if test="status != null">status,</if>
             <if test="logId != null">log_id,</if>
+            <if test="sendType != null">send_type,</if>
+            <if test="liveId != null">live_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="couponId != null">#{couponId},</if>
@@ -58,6 +64,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">#{updateTime},</if>
             <if test="status != null">#{status},</if>
             <if test="logId != null">#{logId},</if>
+            <if test="sendType != null">#{sendType},</if>
+            <if test="liveId != null">#{live_id},</if>
          </trim>
     </insert>
 
@@ -72,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="status != null">status = #{status},</if>
             <if test="logId != null">log_id = #{logId},</if>
+            <if test="sendType != null">send_type = #{sendType},</if>
+            <if test="liveId != null">live_id = #{liveId},</if>
         </trim>
         where id = #{id}
     </update>
@@ -81,9 +91,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteFsCourseCouponUserByIds" parameterType="String">
-        delete from fs_course_coupon_user where id in 
+        delete from fs_course_coupon_user where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
-</mapper>
+</mapper>