Просмотр исходного кода

商家端代金券好友证券代码提交

wuchen 2 месяцев назад
Родитель
Сommit
a1626a1fe8

+ 7 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeDiscountCouponUser.java

@@ -85,6 +85,13 @@ public class LifeDiscountCouponUser extends Model<LifeDiscountCouponUser> {
      @TableField("welfare_id")
      private Integer welfareId;
 
+    /**
+     * 代金券id(代金券时使用,对应 life_coupon.id)
+     */
+    @ApiModelProperty(value = "代金券id")
+    @TableField("voucher_id")
+    private String voucherId;
+
     @Override
     protected Serializable pkVal() {
         return this.id;

+ 4 - 4
alien-entity/src/main/java/shop/alien/entity/storePlatform/vo/DiscountCouponPlatformVo.java

@@ -6,15 +6,15 @@ import lombok.Data;
 import shop.alien.entity.store.vo.LifeDiscountCouponVo;
 
 /**
- * 优惠券
+ * 优惠券/代金券列表(统一用 LifeDiscountCouponVo 格式,代金券 type=4)
  */
 @Data
 @JsonInclude
 public class DiscountCouponPlatformVo {
 
-    // 代金券列表
-    public IPage<LifeCouponPlatformDto> couponList;
-    // 优惠券列表
+    /** 代金券列表(couponType=1 时返回,与优惠券同结构,type=4) */
+    public IPage<LifeDiscountCouponVo> couponList;
+    /** 优惠券列表(couponType!=1 时返回) */
     public IPage<LifeDiscountCouponVo> discountList;
 
 }

+ 2 - 0
alien-entity/src/main/java/shop/alien/mapper/LifeDiscountCouponMapper.java

@@ -1,5 +1,6 @@
 package shop.alien.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -7,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
+import shop.alien.entity.store.LifeCoupon;
 import shop.alien.entity.store.LifeDiscountCoupon;
 import shop.alien.entity.store.vo.LifeDiscountCouponPlatformVo;
 import shop.alien.entity.store.vo.LifeDiscountCouponVo;

+ 1 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/LifeCouponPlatformController.java

@@ -261,7 +261,7 @@ public class LifeCouponPlatformController {
         }
         DiscountCouponPlatformVo vo = new DiscountCouponPlatformVo();
         if (lifeCouponPlatformVo.getCouponType() == 1) {
-            vo.setCouponList(lifeCouponService.getCouponList(lifeCouponPlatformVo.getPageNum(), lifeCouponPlatformVo.getPageSize(), lifeCouponPlatformVo.getStoreId(),
+            vo.setCouponList(lifeCouponService.getCouponListAsDiscountVo(lifeCouponPlatformVo.getPageNum(), lifeCouponPlatformVo.getPageSize(), lifeCouponPlatformVo.getStoreId(),
                     lifeCouponPlatformVo.getStatus(), lifeCouponPlatformVo.getName()));
         } else {
             vo.setDiscountList(lifeDiscountCouponPlatformService.getStoreAllCouponList(lifeCouponPlatformVo.getStoreId(), userLoginInfo,

+ 6 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/LifeCouponPlatformService.java

@@ -6,6 +6,7 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.EssentialHolidayComparison;
 import shop.alien.entity.store.LifeCoupon;
 import shop.alien.entity.store.vo.LifeCouponStatusVo;
+import shop.alien.entity.store.vo.LifeDiscountCouponVo;
 import shop.alien.entity.storePlatform.vo.LifeCouponPlatformDto;
 
 import java.util.Map;
@@ -70,6 +71,11 @@ public interface LifeCouponPlatformService extends IService<LifeCoupon> {
     IPage<LifeCouponPlatformDto> getCouponList(int page, int size, String storeId, String status, String name);
 
     /**
+     * 代金券列表,返回与优惠券一致的数据结构(LifeDiscountCouponVo,type=4),供 getCouponList 接口 couponType=1 使用
+     */
+    IPage<LifeDiscountCouponVo> getCouponListAsDiscountVo(int page, int size, String storeId, String status, String name);
+
+    /**
      * 更新优惠券状态
      * 修改优惠券的状态,如上架、下架等
      *

+ 105 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/LifeCouponPlatformServiceImpl.java

@@ -12,11 +12,13 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.*;
+import shop.alien.entity.store.vo.LifeDiscountCouponVo;
 import shop.alien.entity.storePlatform.vo.LifeCouponPlatformDto;
 import shop.alien.mapper.*;
 import shop.alien.storeplatform.service.LifeCouponPlatformService;
 import shop.alien.util.common.UniqueRandomNumGenerator;
 
+import java.math.BigDecimal;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.time.format.TextStyle;
@@ -270,6 +272,109 @@ public class LifeCouponPlatformServiceImpl extends ServiceImpl<LifeCouponMapper,
         return dto;
     }
 
+    @Override
+    public IPage<LifeDiscountCouponVo> getCouponListAsDiscountVo(int page, int size, String storeId, String status, String name) {
+        LambdaQueryWrapper<LifeCoupon> wrapper = new LambdaQueryWrapper<>();
+        if (status != null && !status.isEmpty() && status.equals("0")) {
+            wrapper.eq(LifeCoupon::getDataType, 1);
+        } else {
+            wrapper.eq(status != null && !status.isEmpty(), LifeCoupon::getStatus, status);
+        }
+        wrapper.eq(storeId != null && !storeId.isEmpty(), LifeCoupon::getStoreId, storeId);
+        wrapper.like(name != null && !name.isEmpty(), LifeCoupon::getName, name);
+        wrapper.eq(LifeCoupon::getType, 1);
+        wrapper.last("ORDER BY CASE " +
+                "WHEN status = 3 THEN 0 " +
+                "WHEN status = 1 THEN 1 " +
+                "WHEN status = 5 THEN 2 " +
+                "WHEN status IN (4, 6, 7) THEN 3 " +
+                "ELSE 4 END ASC, created_time DESC");
+
+        IPage<LifeCoupon> lifeCouponIPage = lifeCouponMapper.selectPage(new Page<>(page, size), wrapper);
+        IPage<LifeDiscountCouponVo> result = new Page<>(page, size);
+        result.setPages(lifeCouponIPage.getPages());
+        result.setCurrent(lifeCouponIPage.getCurrent());
+        result.setSize(lifeCouponIPage.getSize());
+        result.setTotal(lifeCouponIPage.getTotal());
+
+        List<LifeDiscountCouponVo> voList = lifeCouponIPage.getRecords().stream().map(this::mapLifeCouponToDiscountVo).collect(Collectors.toList());
+        result.setRecords(voList);
+        return result;
+    }
+
+    /** 代金券转成与优惠券一致的结构(LifeDiscountCouponVo),type=4 */
+    private LifeDiscountCouponVo mapLifeCouponToDiscountVo(LifeCoupon lc) {
+        LifeDiscountCouponVo vo = new LifeDiscountCouponVo();
+        vo.setVoucherId(lc.getId());
+        if (lc.getId() != null) {
+            try {
+                vo.setId(Integer.parseInt(lc.getId()));
+            } catch (NumberFormatException ignored) { }
+        }
+        vo.setStoreId(lc.getStoreId());
+        vo.setName(lc.getName());
+        vo.setType(lc.getType());
+        vo.setSingleQty(lc.getSingleQty());
+        if (lc.getPrice() != null) {
+            try {
+                vo.setNominalValue(new BigDecimal(lc.getPrice()));
+            } catch (Exception ignored) { }
+        }
+        if (lc.getStartDate() != null) {
+            vo.setStartDate(lc.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+        }
+        if (lc.getEndDate() != null) {
+            vo.setEndDate(lc.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+            vo.setValidDate(lc.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+        }
+        vo.setBeginGetDate(vo.getStartDate());
+        vo.setEndGetDate(vo.getEndDate());
+        vo.setCreatedTime(lc.getCreatedTime());
+        vo.setCouponStatus(lc.getDataType() != null && lc.getDataType() == 0 ? 1 : 0);
+        vo.setQuantityClaimed(0);
+        if (lc.getStatus() != null) {
+            switch (lc.getStatus()) {
+                case 0:
+                    vo.setStatus(5);
+                    vo.setStatusDesc("草稿");
+                    break;
+                case 1:
+                    vo.setStatus(2);
+                    vo.setStatusDesc("待审核");
+                    break;
+                case 2:
+                    vo.setStatus(2);
+                    vo.setStatusDesc("未开始");
+                    break;
+                case 3:
+                    vo.setStatus(3);
+                    vo.setStatusDesc("审核拒绝");
+                    break;
+                case 4:
+                    vo.setStatus(4);
+                    vo.setStatusDesc("已售罄");
+                    break;
+                case 5:
+                    vo.setStatus(0);
+                    vo.setStatusDesc("进行中");
+                    break;
+                case 6:
+                    vo.setStatus(3);
+                    vo.setStatusDesc("已下架");
+                    break;
+                case 7:
+                    vo.setStatus(1);
+                    vo.setStatusDesc("已结束");
+                    break;
+                default:
+                    vo.setStatus(null);
+                    vo.setStatusDesc("未知状态");
+                    break;
+            }
+        }
+        return vo;
+    }
+
     /**
      * 更新优惠券状态
      * 修改优惠券的状态,支持上架、下架等操作

+ 0 - 1
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -109,7 +109,6 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 Double score = commonRating.getScore();
                 if (score != null && score >= 4.5 && commonRating.getUserId() != null && commonRating.getBusinessId() != null) {
                     try {
-
                         lifeDiscountCouponStoreFriendService.issueCouponForGoodRating(Math.toIntExact(commonRating.getUserId()), commonRating.getBusinessId());
                     } catch (Exception ex) {
                         log.warn("CommonRatingService.saveCommonRating 好评送券异常 userId={}, storeId={}, msg={}", commonRating.getUserId(), commonRating.getBusinessId(), ex.getMessage());

+ 88 - 34
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -646,8 +646,7 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
     }
 
     /**
-     *  商家优惠券活动
-     * 好评送券:用户对店铺好评且通过AI审核后,将店铺可用券发放到用户卡包
+     * 好评送券:用户对店铺好评且通过审核后,将店铺可用优惠券和代金券发放到用户卡包,通知按优惠券/代金券分开发送
      */
     @Override
     public int issueCouponForGoodRating(Integer userId, Integer storeId) {
@@ -661,44 +660,99 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
                 .ge(LifeDiscountCoupon::getValidDate, currentDate)
                 .gt(LifeDiscountCoupon::getSingleQty, 0);
         List<LifeDiscountCoupon> coupons = lifeDiscountCouponMapper.selectList(queryWrapper);
-        if (CollectionUtils.isEmpty(coupons)) {
+
+        LambdaQueryWrapper<LifeCoupon> wrapper = new LambdaQueryWrapper<LifeCoupon>();
+        wrapper.eq(LifeCoupon::getStoreId, String.valueOf(storeId))
+                .eq(LifeCoupon::getStatus, 5)
+                .gt(LifeCoupon::getSingleQty, 0);
+        List<LifeCoupon> voucherList = lifeCouponMapper.selectList(wrapper);
+
+        if (CollectionUtils.isEmpty(coupons) && CollectionUtils.isEmpty(voucherList)) {
             return 0;
         }
-        int granted = 0;
+
         int commenterUserId = userId.intValue();
         StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
         LifeUser lifeUser = lifeUserMapper.selectById(commenterUserId);
-        for (LifeDiscountCoupon coupon : coupons) {
-            try {
-                LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
-                lifeDiscountCouponUser.setCouponId(coupon.getId());
-                lifeDiscountCouponUser.setUserId(commenterUserId);
-                lifeDiscountCouponUser.setReceiveTime(new Date());
-                lifeDiscountCouponUser.setExpirationTime(coupon.getValidDate());
-                lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
-                lifeDiscountCouponUser.setDeleteFlag(0);
-                lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
-                coupon.setSingleQty(coupon.getSingleQty() - 1);
-                lifeDiscountCouponMapper.updateById(coupon);
-                granted++;
-            } catch (Exception e) {
-                // 单张发放失败不影响其余
+        int grantedCoupon = 0;
+        int grantedVoucher = 0;
+
+        // 发放优惠券到用户卡包
+        if (ObjectUtils.isNotEmpty(coupons)) {
+            for (LifeDiscountCoupon coupon : coupons) {
+                try {
+                    LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
+                    lifeDiscountCouponUser.setCouponId(coupon.getId());
+                    lifeDiscountCouponUser.setUserId(commenterUserId);
+                    lifeDiscountCouponUser.setReceiveTime(new Date());
+                    lifeDiscountCouponUser.setExpirationTime(coupon.getValidDate());
+                    lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
+                    lifeDiscountCouponUser.setDeleteFlag(0);
+                    lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
+                    coupon.setSingleQty(coupon.getSingleQty() - 1);
+                    lifeDiscountCouponMapper.updateById(coupon);
+                    grantedCoupon++;
+                } catch (Exception e) {
+                    // 单张发放失败不影响其余
+                }
+            }
+        }
+
+        // 发放代金券到用户卡包
+        if (ObjectUtils.isNotEmpty(voucherList)) {
+            for (LifeCoupon life : voucherList) {
+                try {
+                    LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
+                    lifeDiscountCouponUser.setVoucherId(life.getId());
+                    lifeDiscountCouponUser.setUserId(commenterUserId);
+                    lifeDiscountCouponUser.setReceiveTime(new Date());
+                    if (life.getEndDate() != null) {
+                        lifeDiscountCouponUser.setExpirationTime(life.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+                    }
+                    lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
+                    lifeDiscountCouponUser.setDeleteFlag(0);
+                    lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
+                    life.setSingleQty(life.getSingleQty() - 1);
+                    lifeCouponMapper.updateById(life);
+                    grantedVoucher++;
+                } catch (Exception e) {
+                    // 单张发放失败不影响其余
+                }
             }
         }
-        if (granted > 0 && lifeUser != null && storeInfo != null) {
-            LifeNotice lifeNotice = new LifeNotice();
-            lifeNotice.setSenderId("system");
-            lifeNotice.setReceiverId("user_" + lifeUser.getUserPhone());
-            String text = "您对好友店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + granted + "张优惠券,快去我的券包查看吧~";
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("message", text);
-            lifeNotice.setContext(jsonObject.toJSONString());
-            lifeNotice.setNoticeType(1);
-            lifeNotice.setTitle("好评送券");
-            lifeNotice.setIsRead(0);
-            lifeNotice.setDeleteFlag(0);
-            lifeNoticeMapper.insert(lifeNotice);
-        }
-        return granted;
+
+        // 通知分开:优惠券一条,代金券一条
+        if (lifeUser != null && storeInfo != null) {
+            if (grantedCoupon > 0) {
+                LifeNotice couponNotice = new LifeNotice();
+                couponNotice.setSenderId("system");
+                couponNotice.setReceiverId("user_" + lifeUser.getUserPhone());
+                String couponText = "您对店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + grantedCoupon + "张优惠券,快去我的券包查看吧~";
+                JSONObject couponJson = new JSONObject();
+                couponJson.put("message", couponText);
+                couponNotice.setContext(couponJson.toJSONString());
+                couponNotice.setNoticeType(1);
+                couponNotice.setTitle("好评送券");
+                couponNotice.setIsRead(0);
+                couponNotice.setDeleteFlag(0);
+                lifeNoticeMapper.insert(couponNotice);
+            }
+            if (grantedVoucher > 0) {
+                LifeNotice voucherNotice = new LifeNotice();
+                voucherNotice.setSenderId("system");
+                voucherNotice.setReceiverId("user_" + lifeUser.getUserPhone());
+                String voucherText = "您对店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + grantedVoucher + "张代金券,快去我的券包查看吧~";
+                JSONObject voucherJson = new JSONObject();
+                voucherJson.put("message", voucherText);
+                voucherNotice.setContext(voucherJson.toJSONString());
+                voucherNotice.setNoticeType(1);
+                voucherNotice.setTitle("好评送代金券");
+                voucherNotice.setIsRead(0);
+                voucherNotice.setDeleteFlag(0);
+                lifeNoticeMapper.insert(voucherNotice);
+            }
+        }
+
+        return grantedCoupon + grantedVoucher;
     }
 }