From 4ff5f35054ab141d915c11ad878d4dcffe7e034a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 12 五月 2023 18:43:27 +0800
Subject: [PATCH] BUG修改

---
 management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java
index 1fd7164..e38c646 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.stylefeng.guns.core.base.controller.BaseController;
 import com.stylefeng.guns.core.base.tips.SuccessTip;
+import com.stylefeng.guns.core.shiro.ShiroKit;
 import com.stylefeng.guns.core.util.DateUtil;
 import com.stylefeng.guns.modular.system.controller.req.CouponSendReq;
 import com.stylefeng.guns.modular.system.enums.CouponStatusEnum;
@@ -135,6 +136,16 @@
         if(isExit){
             return new SuccessTip(500,"该优惠券名称与类型已存在!");
         }
+        // 如果是新人优惠券,查询是否存在已启用的新人优惠券
+        if(tCoupon.getCouponType() == 2){
+            int count = tCouponService.selectCount(new EntityWrapper<TCoupon>()
+                    .eq("coupon_type", 2)
+                    .eq("coupon_state", 1)
+                    .eq("status", true));
+            if(count>0){
+                return new SuccessTip(500,"已存在已启用的新人优惠券!");
+            }
+        }
         tCouponService.insert(tCoupon);
         return SUCCESS_TIP;
     }
@@ -221,8 +232,12 @@
             tUserToCoupon.setCouponTotal(1);
             tUserToCoupon.setValidCount(1);
             Date expireTime = Date.from(LocalDate.now().plusDays(tCoupon.getCouponValidity()).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
-            System.err.println(expireTime);
             tUserToCoupon.setExpireTime(expireTime);
+
+            // 添加发放人id和类型
+            tUserToCoupon.setObjectId(ShiroKit.getUser().getObjectId());
+            tUserToCoupon.setRoleType(ShiroKit.getUser().getRoleType());
+
             tUserToCoupons.add(tUserToCoupon);
         }
         tUserToCouponService.insertBatch(tUserToCoupons);

--
Gitblit v1.7.1