From 7d914d51a902b3013a8ae27ee48239821d766e4d Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 16 三月 2023 18:23:51 +0800
Subject: [PATCH] 基础信息管理:公告
---
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCouponController.java | 76 ++++++++++++++++++++++++++++++++++++--
1 files changed, 72 insertions(+), 4 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 e1535ec..3d745de 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
@@ -6,7 +6,11 @@
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.system.controller.req.CouponSendReq;
import com.stylefeng.guns.modular.system.enums.CouponStatusEnum;
+import com.stylefeng.guns.modular.system.model.TAgent;
+import com.stylefeng.guns.modular.system.model.TUserToCoupon;
+import com.stylefeng.guns.modular.system.service.ITUserToCouponService;
import io.swagger.annotations.ApiOperation;
+import org.apache.poi.hdf.extractor.TC;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -21,6 +25,8 @@
import com.stylefeng.guns.modular.system.model.TCoupon;
import com.stylefeng.guns.modular.system.service.ITCouponService;
+import java.time.LocalDate;
+import java.time.ZoneId;
import java.util.*;
/**
@@ -37,6 +43,8 @@
@Autowired
private ITCouponService tCouponService;
+ @Autowired
+ private ITUserToCouponService tUserToCouponService;
/**
* 跳转到首页
@@ -86,8 +94,22 @@
wrapper.between("create_time",startTime,endTime);
}
wrapper.orderBy(true,"create_time",false);
- wrapper.groupBy(true,"coupon_name");
- wrapper.groupBy(true,"coupon_type");
+ return tCouponService.selectList(wrapper);
+ }
+
+ /**
+ * 获取活动券列表
+ */
+ @RequestMapping(value = "/activityCouponList")
+ @ResponseBody
+ public Object activityCouponList(String couponName) {
+ EntityWrapper<TCoupon> wrapper = new EntityWrapper<>();
+ if(StringUtils.hasLength(couponName)){
+ wrapper.like("coupon_name",couponName);
+ }
+ wrapper.eq("coupon_type",1);
+ wrapper.eq("coupon_state",1);
+ wrapper.orderBy(true,"create_time",false);
return tCouponService.selectList(wrapper);
}
@@ -126,6 +148,33 @@
}
/**
+ * 修改优惠券状态
+ */
+ @RequestMapping(value = "/update-status")
+ @ResponseBody
+ public Object updateStatus(Integer id,Integer status) {
+ TCoupon tCoupon = tCouponService.selectById(id);
+
+ // 查询已启用的新人券数量
+ int count = tCouponService.selectCount(new EntityWrapper<TCoupon>().eq("coupon_state", 1)
+ .eq("coupon_type",2));
+
+ // 判断是否为新人券,新人券只可启用一条记录
+ if(count > 0 && 2 == tCoupon.getCouponType() && 2 == status){
+ return new SuccessTip(500,"已有启动的新人券!");
+ }
+
+ if(1 == status){
+ tCoupon.setCouponState(2);
+ }
+ if(2 == status){
+ tCoupon.setCouponState(1);
+ }
+ tCouponService.updateById(tCoupon);
+ return SUCCESS_TIP;
+ }
+
+ /**
* 修改
*/
@RequestMapping(value = "/update")
@@ -154,8 +203,27 @@
List<Integer> userIds = couponSendReq.getUserIds();
+ // 查询选择的优惠券
+ TCoupon tCoupon = tCouponService.selectById(couponSendReq.getCouponId());
+
+ List<TUserToCoupon> tUserToCoupons = new ArrayList<>(userIds.size());
+
+ for (Integer userId : userIds) {
+ // 创建用户优惠券关联表
+ TUserToCoupon tUserToCoupon = new TUserToCoupon();
+ tUserToCoupon.setCouponId(tCoupon.getId());
+ tUserToCoupon.setUserId(userId);
+ 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);
+ tUserToCoupons.add(tUserToCoupon);
+ }
+ tUserToCouponService.insertBatch(tUserToCoupons);
+
// 查询该优惠券的列表
- List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("coupon_name", couponSendReq.getCouponName())
+ /*List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("coupon_name", couponSendReq.getCouponName())
.eq("coupon_status",CouponStatusEnum.UNISSUED.getCode()));
Assert.isTrue(!CollectionUtils.isEmpty(tCoupons),"该优惠券不存在!");
List<TCoupon> tCouponList = new ArrayList<>();
@@ -186,7 +254,7 @@
}
if(!CollectionUtils.isEmpty(tCouponList)){
tCouponService.updateBatchById(tCouponList);
- }
+ }*/
return SUCCESS_TIP;
}
--
Gitblit v1.7.1