Browse Source

1、直播优惠卷核销需求

yys 1 tháng trước cách đây
mục cha
commit
51bf00f031

+ 15 - 2
fs-service/src/main/java/com/fs/live/domain/LiveCouponUser.java

@@ -57,10 +57,23 @@ public class LiveCouponUser extends BaseEntity
     @Excel(name = "获取方式")
     private String type;
 
-    /** 状态(0:未使用,1:已使用, 2:已过期) */
-    @Excel(name = "状态", readConverterExp = "0=:未使用,1:已使用,,2=:已过期")
+    /** 状态(0:未核销,1:已核销, 2:已过期) */
+    @Excel(name = "状态", readConverterExp = "0=:未核销,1:已核销,,2=:已过期")
     private Integer status;
 
+    /** 核销码(用于扫码核销) */
+    @Excel(name = "核销码")
+    private String verifyCode;
+
+    /** 核销销售用户ID */
+    @Excel(name = "核销销售用户ID")
+    private Long verifyUserId;
+
+    /** 核销时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "核销时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date verifyTime;
+
     /** 是否有效 */
     @Excel(name = "是否有效")
     private Integer isFail;

+ 18 - 2
fs-service/src/main/java/com/fs/live/mapper/LiveCouponUserMapper.java

@@ -6,6 +6,7 @@ import com.fs.common.annotation.DataSource;
 import com.fs.common.enums.DataSourceType;
 import com.fs.live.domain.LiveCouponUser;
 import com.fs.live.param.CouponPO;
+import com.fs.live.vo.LiveCouponUserDetailVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
@@ -66,17 +67,32 @@ public interface LiveCouponUserMapper
      */
     public int deleteLiveCouponUserByIds(Long[] ids);
 
-    @Select("select lcu.* from live_coupon_user lcu  where lcu.user_id = #{coupon.userId}")
+    @Select("<script>" +
+            "select lcu.* from live_coupon_user lcu where lcu.user_id = #{coupon.userId} and lcu.is_del = 0" +
+            " <if test='coupon.status != null'> and lcu.status = #{coupon.status}</if>" +
+            " order by lcu.create_time desc" +
+            "</script>")
     List<LiveCouponUser> selectLiveCouponUserByCouponPO(@Param("coupon") CouponPO coupon);
 
     @Select("<script>" +
-            "select lcu.* from live_coupon_user lcu where lcu.user_id= #{coupon.userId} " +
+            "select lcu.* from live_coupon_user lcu where lcu.user_id= #{coupon.userId} and lcu.is_del = 0" +
+            " <if test='coupon.status != null'> and lcu.status = #{coupon.status}</if>" +
             " <if test='coupon.goodsId != null'>" +
             " and (lcu.goods_id= #{coupon.goodsId} or lcu.goods_id is null or lcu.goods_id = 0)" +
             " </if>" +
+            " order by lcu.create_time desc" +
             "</script>")
     @DataSource(DataSourceType.SLAVE)
     List<LiveCouponUser> curCoupon(@Param("coupon") CouponPO coupon);
 
+    @Select("select lcu.* from live_coupon_user lcu where lcu.verify_code = #{verifyCode} and lcu.is_del = 0 limit 1")
+    LiveCouponUser selectLiveCouponUserByVerifyCode(@Param("verifyCode") String verifyCode);
+
+    List<LiveCouponUserDetailVo> selectLiveCouponUserDetailList(CouponPO coupon);
+
+    LiveCouponUserDetailVo selectLiveCouponUserDetailById(@Param("id") Long id);
+
+    LiveCouponUserDetailVo selectLiveCouponUserDetailByVerifyCode(@Param("verifyCode") String verifyCode);
+
     int refundCoupon(Long couponUserId);
 }

+ 8 - 0
fs-service/src/main/java/com/fs/live/param/CouponPO.java

@@ -22,5 +22,13 @@ public class CouponPO {
     private Long userId;
     private Long goodsId;
 
+    /** 优惠券发放记录id */
+    private Long couponUserId;
+
+    /** 核销码 */
+    private String verifyCode;
+
+    /** 状态筛选(0:未核销,1:已核销,2:已过期) */
+    private Integer status;
 
 }

+ 17 - 0
fs-service/src/main/java/com/fs/live/service/ILiveCouponService.java

@@ -6,7 +6,9 @@ import java.util.Map;
 import com.fs.common.core.domain.R;
 import com.fs.live.domain.LiveCoupon;
 import com.fs.live.param.CouponPO;
+import com.fs.live.param.LiveCouponVerifyParam;
 import com.fs.live.vo.LiveCouponListVo;
+import com.fs.live.vo.LiveCouponUserDetailVo;
 
 
 /**
@@ -87,6 +89,21 @@ public interface ILiveCouponService
 
     R curCoupon(CouponPO coupon);
 
+    /**
+     * 用户优惠券详情列表(含核销码、状态等)
+     */
+    R userCouponDetailList(CouponPO coupon);
+
+    /**
+     * 优惠券详情(用户查看 / 销售扫码预览)
+     */
+    R couponDetail(CouponPO coupon);
+
+    /**
+     * 销售扫码核销优惠券
+     */
+    R verifyCoupon(LiveCouponVerifyParam param);
+
     List<LiveCoupon> listOn(Long liveId);
 
     /**

+ 9 - 0
fs-service/src/main/java/com/fs/live/service/ILiveCouponUserService.java

@@ -3,6 +3,7 @@ package com.fs.live.service;
 import java.util.List;
 import com.fs.live.domain.LiveCouponUser;
 import com.fs.live.param.CouponPO;
+import com.fs.live.vo.LiveCouponUserDetailVo;
 
 /**
  * 优惠券发放记录Service接口
@@ -63,4 +64,12 @@ public interface ILiveCouponUserService
     List<LiveCouponUser> selectLiveCouponUserByCouponPO(CouponPO coupon);
 
     List<LiveCouponUser> curCoupon(CouponPO coupon);
+
+    List<LiveCouponUserDetailVo> selectLiveCouponUserDetailList(CouponPO coupon);
+
+    LiveCouponUserDetailVo selectLiveCouponUserDetailById(Long id);
+
+    LiveCouponUserDetailVo selectLiveCouponUserDetailByVerifyCode(String verifyCode);
+
+    LiveCouponUser selectLiveCouponUserByVerifyCode(String verifyCode);
 }

+ 120 - 2
fs-service/src/main/java/com/fs/live/service/impl/LiveCouponServiceImpl.java

@@ -15,8 +15,10 @@ import com.fs.live.mapper.LiveCouponIssueMapper;
 import com.fs.live.mapper.LiveCouponIssueUserMapper;
 import com.fs.live.mapper.LiveMapper;
 import com.fs.live.param.CouponPO;
+import com.fs.live.param.LiveCouponVerifyParam;
 import com.fs.live.service.*;
 import com.fs.live.vo.LiveCouponListVo;
+import com.fs.live.vo.LiveCouponUserDetailVo;
 
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -350,6 +352,7 @@ public class LiveCouponServiceImpl implements ILiveCouponService
         userRecord.setIsDel(0);
         userRecord.setGoodsId(coupon.getGoodsId());
         userRecord.setType("live-"+coupon.getLiveId());
+        userRecord.setVerifyCode(generateVerifyCode());
         //库存 remain_count
         issue.setRemainCount(issue.getRemainCount()-1);
         liveCouponIssueService.updateLiveCouponIssue(issue);
@@ -376,8 +379,7 @@ public class LiveCouponServiceImpl implements ILiveCouponService
 
     @Override
     public R userCouponList(CouponPO coupon) {
-        List<LiveCouponUser> list = liveCouponUserService.selectLiveCouponUserByCouponPO(coupon);
-        return R.ok().put("data", list);
+        return userCouponDetailList(coupon);
     }
 
     @Override
@@ -386,6 +388,122 @@ public class LiveCouponServiceImpl implements ILiveCouponService
         return R.ok().put("data", list);
     }
 
+    @Override
+    public R userCouponDetailList(CouponPO coupon) {
+        List<LiveCouponUserDetailVo> list = liveCouponUserService.selectLiveCouponUserDetailList(coupon);
+        list.forEach(this::fillCouponStatusName);
+        return R.ok().put("data", list);
+    }
+
+    @Override
+    public R couponDetail(CouponPO coupon) {
+        LiveCouponUserDetailVo detail;
+        if (StringUtils.isNotEmpty(coupon.getVerifyCode())) {
+            detail = liveCouponUserService.selectLiveCouponUserDetailByVerifyCode(coupon.getVerifyCode());
+        } else if (coupon.getCouponUserId() != null) {
+            detail = liveCouponUserService.selectLiveCouponUserDetailById(coupon.getCouponUserId());
+        } else {
+            return R.error("优惠券参数不能为空");
+        }
+        if (detail == null) {
+            return R.error("优惠券不存在");
+        }
+        if (coupon.getUserId() != null && detail.getUserId() != null
+                && !coupon.getUserId().equals(Long.valueOf(detail.getUserId()))) {
+            return R.error("无权查看该优惠券");
+        }
+        fillCouponStatusName(detail);
+        ensureVerifyCode(detail);
+        return R.ok().put("data", detail);
+    }
+
+    @Override
+    @Transactional
+    public R verifyCoupon(LiveCouponVerifyParam param) {
+        if (param.getVerifyUserId() == null) {
+            return R.error("销售未登录");
+        }
+        if (StringUtils.isEmpty(param.getVerifyCode()) && param.getCouponUserId() == null) {
+            return R.error("核销码不能为空");
+        }
+
+        LiveCouponUser couponUser;
+        if (StringUtils.isNotEmpty(param.getVerifyCode())) {
+            couponUser = liveCouponUserService.selectLiveCouponUserByVerifyCode(param.getVerifyCode());
+        } else {
+            couponUser = liveCouponUserService.selectLiveCouponUserById(param.getCouponUserId());
+        }
+        if (couponUser == null || Objects.equals(couponUser.getIsDel(), 1)) {
+            return R.error("优惠券不存在");
+        }
+
+        Date now = DateUtils.getNowDate();
+        if (couponUser.getStatus() != null && couponUser.getStatus() == 1) {
+            return R.error("优惠券已核销");
+        }
+        if (couponUser.getStatus() != null && couponUser.getStatus() == 2) {
+            return R.error("优惠券已过期");
+        }
+        if (couponUser.getLimitTime() != null && couponUser.getLimitTime().before(now)) {
+            LiveCouponUser expired = new LiveCouponUser();
+            expired.setId(couponUser.getId());
+            expired.setStatus(2);
+            expired.setIsFail(0);
+            expired.setUpdateTime(now);
+            liveCouponUserService.updateLiveCouponUser(expired);
+            return R.error("优惠券已过期");
+        }
+
+        LiveCouponUser update = new LiveCouponUser();
+        update.setId(couponUser.getId());
+        update.setStatus(1);
+        update.setUseTime(now);
+        update.setVerifyTime(now);
+        update.setVerifyUserId(param.getVerifyUserId());
+        update.setUpdateTime(now);
+        if (StringUtils.isEmpty(couponUser.getVerifyCode())) {
+            update.setVerifyCode(generateVerifyCode());
+        }
+        liveCouponUserService.updateLiveCouponUser(update);
+
+        LiveCouponUserDetailVo detail = liveCouponUserService.selectLiveCouponUserDetailById(couponUser.getId());
+        fillCouponStatusName(detail);
+        return R.ok("核销成功").put("data", detail);
+    }
+
+    private void fillCouponStatusName(LiveCouponUserDetailVo detail) {
+        if (detail == null || detail.getStatus() == null) {
+            return;
+        }
+        switch (detail.getStatus()) {
+            case 1:
+                detail.setStatusName("已核销");
+                break;
+            case 2:
+                detail.setStatusName("已过期");
+                break;
+            default:
+                detail.setStatusName("未核销");
+                break;
+        }
+    }
+
+    private void ensureVerifyCode(LiveCouponUserDetailVo detail) {
+        if (detail == null || StringUtils.isNotEmpty(detail.getVerifyCode())) {
+            return;
+        }
+        LiveCouponUser update = new LiveCouponUser();
+        update.setId(detail.getId());
+        update.setVerifyCode(generateVerifyCode());
+        update.setUpdateTime(DateUtils.getNowDate());
+        liveCouponUserService.updateLiveCouponUser(update);
+        detail.setVerifyCode(update.getVerifyCode());
+    }
+
+    private String generateVerifyCode() {
+        return "LC" + System.currentTimeMillis() + (int) (Math.random() * 1000);
+    }
+
     @Override
     public List<LiveCoupon> listOn(Long liveId) {
         return liveCouponMapper.listOn(liveId);

+ 21 - 0
fs-service/src/main/java/com/fs/live/service/impl/LiveCouponUserServiceImpl.java

@@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
 import com.fs.live.mapper.LiveCouponUserMapper;
 import com.fs.live.domain.LiveCouponUser;
 import com.fs.live.service.ILiveCouponUserService;
+import com.fs.live.vo.LiveCouponUserDetailVo;
 
 /**
  * 优惠券发放记录Service业务层处理
@@ -105,4 +106,24 @@ public class LiveCouponUserServiceImpl implements ILiveCouponUserService
     public List<LiveCouponUser> curCoupon(CouponPO coupon) {
         return liveCouponUserMapper.curCoupon(coupon);
     }
+
+    @Override
+    public List<LiveCouponUserDetailVo> selectLiveCouponUserDetailList(CouponPO coupon) {
+        return liveCouponUserMapper.selectLiveCouponUserDetailList(coupon);
+    }
+
+    @Override
+    public LiveCouponUserDetailVo selectLiveCouponUserDetailById(Long id) {
+        return liveCouponUserMapper.selectLiveCouponUserDetailById(id);
+    }
+
+    @Override
+    public LiveCouponUserDetailVo selectLiveCouponUserDetailByVerifyCode(String verifyCode) {
+        return liveCouponUserMapper.selectLiveCouponUserDetailByVerifyCode(verifyCode);
+    }
+
+    @Override
+    public LiveCouponUser selectLiveCouponUserByVerifyCode(String verifyCode) {
+        return liveCouponUserMapper.selectLiveCouponUserByVerifyCode(verifyCode);
+    }
 }

+ 1 - 1
fs-service/src/main/resources/application-druid-tyt.yml

@@ -245,6 +245,6 @@ wechat:
         appid: wxd7c1e221622a0ccf
         secret: 70d3ed4f8eb68cca0cf525b8ce07405d
         redirectUri: https://admin.tyt.com/prod-api/callback
-        isNeedScan: true
+        isNeedScan: false
 
 

+ 70 - 1
fs-service/src/main/resources/mapper/live/LiveCouponUserMapper.xml

@@ -20,10 +20,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isFail"    column="is_fail"    />
         <result property="isDel"    column="is_del"    />
         <result property="goodsId"    column="goods_id"    />
+        <result property="verifyCode"    column="verify_code"    />
+        <result property="verifyUserId"    column="verify_user_id"    />
+        <result property="verifyTime"    column="verify_time"    />
+    </resultMap>
+
+    <resultMap type="com.fs.live.vo.LiveCouponUserDetailVo" id="LiveCouponUserDetailVoResult">
+        <result property="id" column="id"/>
+        <result property="couponId" column="coupon_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="couponTitle" column="coupon_title"/>
+        <result property="couponPrice" column="coupon_price"/>
+        <result property="useMinPrice" column="use_min_price"/>
+        <result property="limitTime" column="limit_time"/>
+        <result property="useTime" column="use_time"/>
+        <result property="type" column="type"/>
+        <result property="status" column="status"/>
+        <result property="isFail" column="is_fail"/>
+        <result property="goodsId" column="goods_id"/>
+        <result property="verifyCode" column="verify_code"/>
+        <result property="verifyUserId" column="verify_user_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="nickname" column="nickname"/>
+        <result property="phone" column="phone"/>
+        <result property="verifyUserName" column="verify_user_name"/>
     </resultMap>
 
     <sql id="selectLiveCouponUserVo">
-        select id, coupon_id, user_id, coupon_title, coupon_price, use_min_price, create_time, update_time, limit_time, use_time, type, status, is_fail, is_del,goods_id from live_coupon_user
+        select id, coupon_id, user_id, coupon_title, coupon_price, use_min_price, create_time, update_time, limit_time, use_time, type, status, is_fail, is_del, goods_id, verify_code, verify_user_id, verify_time from live_coupon_user
+    </sql>
+
+    <sql id="selectLiveCouponUserDetailSql">
+        select lcu.id, lcu.coupon_id, lcu.user_id, lcu.coupon_title, lcu.coupon_price, lcu.use_min_price,
+               lcu.create_time, lcu.limit_time, lcu.use_time, lcu.type, lcu.status, lcu.is_fail, lcu.goods_id,
+               lcu.verify_code, lcu.verify_user_id, u.nick_name as nickname, u.phone as phone,
+               cu.nick_name as verify_user_name
+        from live_coupon_user lcu
+        left join fs_user u on lcu.user_id = u.user_id
+        left join company_user cu on lcu.verify_user_id = cu.user_id
     </sql>
 
     <select id="selectLiveCouponUserList" parameterType="LiveCouponUser" resultMap="LiveCouponUserResult">
@@ -47,7 +81,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isFail != null "> and is_fail = #{isFail}</if>
             <if test="isDel != null "> and is_del = #{isDel}</if>
             <if test="goodsId != null "> and goods_id = #{goodsId}</if>
+            <if test="verifyCode != null and verifyCode != ''"> and verify_code = #{verifyCode}</if>
+            <if test="verifyUserId != null "> and verify_user_id = #{verifyUserId}</if>
+        </where>
+    </select>
+
+    <select id="selectLiveCouponUserDetailList" parameterType="com.fs.live.param.CouponPO" resultMap="LiveCouponUserDetailVoResult">
+        <include refid="selectLiveCouponUserDetailSql"/>
+        <where>
+            lcu.is_del = 0
+            <if test="userId != null"> and lcu.user_id = #{userId}</if>
+            <if test="status != null"> and lcu.status = #{status}</if>
+            <if test="goodsId != null">
+                and (lcu.goods_id = #{goodsId} or lcu.goods_id is null or lcu.goods_id = 0)
+            </if>
         </where>
+        order by lcu.create_time desc
+    </select>
+
+    <select id="selectLiveCouponUserDetailById" parameterType="Long" resultMap="LiveCouponUserDetailVoResult">
+        <include refid="selectLiveCouponUserDetailSql"/>
+        where lcu.id = #{id} and lcu.is_del = 0
+    </select>
+
+    <select id="selectLiveCouponUserDetailByVerifyCode" parameterType="String" resultMap="LiveCouponUserDetailVoResult">
+        <include refid="selectLiveCouponUserDetailSql"/>
+        where lcu.verify_code = #{verifyCode} and lcu.is_del = 0
+        limit 1
     </select>
 
     <select id="selectLiveCouponUserById" parameterType="Long" resultMap="LiveCouponUserResult">
@@ -72,6 +132,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isFail != null">is_fail,</if>
             <if test="isDel != null">is_del,</if>
             <if test="goodsId != null">goods_id,</if>
+            <if test="verifyCode != null and verifyCode != ''">verify_code,</if>
+            <if test="verifyUserId != null">verify_user_id,</if>
+            <if test="verifyTime != null">verify_time,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="couponId != null">#{couponId},</if>
@@ -88,6 +151,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isFail != null">#{isFail},</if>
             <if test="isDel != null">#{isDel},</if>
             <if test="goodsId != null">#{goodsId},</if>
+            <if test="verifyCode != null and verifyCode != ''">#{verifyCode},</if>
+            <if test="verifyUserId != null">#{verifyUserId},</if>
+            <if test="verifyTime != null">#{verifyTime},</if>
          </trim>
     </insert>
 
@@ -108,6 +174,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isFail != null">is_fail = #{isFail},</if>
             <if test="isDel != null">is_del = #{isDel},</if>
             <if test="goodsId != null">goods_id = #{goodsId},</if>
+            <if test="verifyCode != null and verifyCode != ''">verify_code = #{verifyCode},</if>
+            <if test="verifyUserId != null">verify_user_id = #{verifyUserId},</if>
+            <if test="verifyTime != null">verify_time = #{verifyTime},</if>
         </trim>
         where id = #{id}
     </update>

+ 37 - 2
fs-user-app/src/main/java/com/fs/app/controller/live/LiveCouponController.java

@@ -4,7 +4,10 @@ import com.fs.app.annotation.Login;
 import com.fs.app.controller.AppBaseController;
 import com.fs.app.facade.LiveFacadeService;
 import com.fs.common.core.domain.R;
+import com.fs.company.domain.CompanyUser;
+import com.fs.company.service.ICompanyUserService;
 import com.fs.live.param.CouponPO;
+import com.fs.live.param.LiveCouponVerifyParam;
 import com.fs.live.service.ILiveCouponService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -20,6 +23,8 @@ public class LiveCouponController extends AppBaseController {
     private ILiveCouponService liveCouponService;
     @Autowired
     private LiveFacadeService liveFacadeService;
+    @Autowired
+    private ICompanyUserService companyUserService;
 
     /**
      * 领取优惠券
@@ -32,13 +37,43 @@ public class LiveCouponController extends AppBaseController {
     }
 
     /**
-     * 用户优惠券列表
+     * 用户优惠券详情列表(含核销码、状态)
      */
     @Login
     @PostMapping("/list")
     public R list(@RequestBody CouponPO coupon) {
         coupon.setUserId(Long.parseLong(getUserId()));
-        return liveCouponService.userCouponList(coupon);
+        return liveCouponService.userCouponDetailList(coupon);
+    }
+
+    /**
+     * 优惠券详情(用户查看 / 销售扫码预览)
+     */
+    @Login
+    @PostMapping("/detail")
+    public R detail(@RequestBody CouponPO coupon) {
+        if (coupon.getCouponUserId() == null && coupon.getVerifyCode() == null) {
+            return R.error("参数不能为空");
+        }
+        if (coupon.getCouponUserId() != null) {
+            coupon.setUserId(Long.parseLong(getUserId()));
+        }
+        return liveCouponService.couponDetail(coupon);
+    }
+
+    /**
+     * 销售扫码核销优惠券
+     */
+    @Login
+    @PostMapping("/verify")
+    public R verify(@RequestBody LiveCouponVerifyParam param) {
+        Long companyUserId = getCompanyUserId();
+        CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
+        if (companyUser == null) {
+            return R.error("销售不存在");
+        }
+        param.setVerifyUserId(companyUserId);
+        return liveCouponService.verifyCoupon(param);
     }
 
     /**