From 8bd65ed0eab661b4d76c26650be445686f889ca5 Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期二, 14 一月 2025 12:09:46 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java | 43 +++++++++++++++++++++++++++++++++++++------
1 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java
index 26e2585..7bde80d 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/CouponInfoController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.feignClient.AppUserClient;
@@ -25,6 +26,7 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
+import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -74,11 +76,11 @@
@ApiOperation(value = "优惠劵管理-详情", tags = {"管理后台-活动管理"})
public R<CouponInfo> detail(@RequestParam("id") Integer id) {
CouponInfo byId = couponInfoService.getById(id);
- byId.setGoodsNameList(JSON.parseArray(byId.getGoodsNameJson(), String.class));
String forGoodIds = byId.getForGoodIds();
- if (StringUtils.isNotEmpty(forGoodIds)){
+ if (!"-1".equals(forGoodIds) && StringUtils.isNotEmpty(forGoodIds)){
List<Goods> goods = goodsService.listByIds(Arrays.asList(forGoodIds.split(",")));
byId.setGoods(goods);
+ byId.setGoodsNameList(goods.stream().map(Goods::getName).collect(Collectors.toList()));
}
String personIds = byId.getPersonIds();
if (StringUtils.isNotEmpty(personIds)){
@@ -104,6 +106,11 @@
public R<Void> edit(@RequestBody CouponInfo couponInfo) {
List<String> goodsNameList = couponInfo.getGoodsNameList();
couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList));
+ if(couponInfo.getPeriodType() == 2){
+ Integer periodDays = couponInfo.getPeriodDays();
+ couponInfo.setPeriodStartTime(LocalDate.now());
+ couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays));
+ }
couponInfoService.updateById(couponInfo);
return R.ok();
}
@@ -127,6 +134,12 @@
couponInfo.setShelfStatus(0);
List<String> goodsNameList = couponInfo.getGoodsNameList();
couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList));
+ couponInfo.setShelfStatus(1);
+ if(couponInfo.getPeriodType() == 2){
+ Integer periodDays = couponInfo.getPeriodDays();
+ couponInfo.setPeriodStartTime(LocalDate.now());
+ couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays));
+ }
couponInfoService.save(couponInfo);
return R.ok();
}
@@ -146,19 +159,25 @@
//查出指定人员可领取优惠券
List<CouponInfo> list1 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 2).apply("FIND_IN_SET('" + appUserById.getId() + "', person_ids)").list();
//查出指定会员可领取优惠劵
- List<CouponInfo> list2 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 3).apply("FIND_IN_SET('" + appUserById.getVipId() + "', person_ids)").list();
+ List<CouponInfo> list2 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 3).apply("FIND_IN_SET('" + appUserById.getVipId() + "', vip_ids)").list();
List<CouponInfo> returnList = new ArrayList<>();
count(userid, list, returnList);
count(userid, list1, returnList);
count(userid, list2, returnList);
-
-
return R.ok(returnList);
}
private void count(Long userid, List<CouponInfo> list1, List<CouponInfo> returnList) {
for (CouponInfo couponInfo : list1) {
- Long count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData();
+ Long count = appUserClient.getCouponCount(-1L, couponInfo.getId()).getData();
+ if(couponInfo.getSendNum() <= count){
+ couponInfo.setMaxNum(count.intValue() - couponInfo.getSendNum());
+ for (int i = 0; i < couponInfo.getMaxNum(); i++) {
+ returnList.add(couponInfo);
+ }
+ continue;
+ }
+ count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData();
couponInfo.setMaxNum(couponInfo.getMaxNum() - count.intValue());
for (int i = 0; i < couponInfo.getMaxNum(); i++) {
returnList.add(couponInfo);
@@ -187,8 +206,20 @@
@GetMapping("/getReceiveRecord")
public R<IPage<UserCoupon>> getReceiveRecord(@ApiParam("页码") @RequestParam Integer pageNum, @ApiParam("大小") Integer pageSize,UserCoupon userCoupon) {
+ // TODO 待完善
return null;
}
+
+ /**
+ * 根据类型获取有效优惠券列表
+ */
+ @PostMapping("/getCouponInfoByPersonType")
+ public R<List<CouponInfo>> getCouponInfoByPersonType(@RequestParam("personType") Integer personType){
+ List<CouponInfo> list = couponInfoService.list(new LambdaUpdateWrapper<CouponInfo>().eq(CouponInfo::getPersonType, personType).eq(CouponInfo::getDelFlag, 0).eq(CouponInfo::getShelfStatus, 1).last(" and now() between period_start_time and period_end_time"));
+ return R.ok(list);
+ }
+
+
}
--
Gitblit v1.7.1