From 71656127d2d3fa023eb767343a9ac01172f2802d Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 27 八月 2025 21:31:40 +0800
Subject: [PATCH] bug修改

---
 cloud-server-activity/src/main/java/com/dsh/activity/controller/UserCouponController.java |  160 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 150 insertions(+), 10 deletions(-)

diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/UserCouponController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/UserCouponController.java
index ed0fd9d..bbfc1cb 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/UserCouponController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/UserCouponController.java
@@ -1,17 +1,27 @@
 package com.dsh.activity.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.dsh.activity.entity.Coupon;
-import com.dsh.activity.entity.CouponStore;
-import com.dsh.activity.entity.UserCoupon;
+import com.dsh.activity.entity.*;
+import com.dsh.activity.feignclient.account.AppUserClient;
+import com.dsh.activity.feignclient.account.StudentClient;
+import com.dsh.activity.feignclient.account.model.AppUser;
 import com.dsh.activity.feignclient.model.CouponStuAvailableVo;
 import com.dsh.activity.feignclient.model.QueryUserCouponByIdAndUserId;
+import com.dsh.activity.feignclient.other.SiteClient;
+import com.dsh.activity.feignclient.other.StoreClient;
+import com.dsh.activity.feignclient.other.model.Store;
 import com.dsh.activity.model.CouponListVo;
+import com.dsh.activity.model.GrantCoupon;
 import com.dsh.activity.model.SendCouponReq;
 import com.dsh.activity.service.CouponStoreService;
 import com.dsh.activity.service.ICouponService;
 import com.dsh.activity.service.UserCouponService;
+import com.dsh.activity.service.VipDetailService;
+import com.dsh.activity.util.DateUtil;
 import com.dsh.activity.util.ResultUtil;
 import com.dsh.activity.util.TokenUtil;
 import io.swagger.annotations.Api;
@@ -19,13 +29,12 @@
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Api
@@ -43,9 +52,22 @@
     @Autowired
     private UserCouponService userCouponService;
 
-
     @Autowired
     private CouponStoreService csServie;
+
+    @Resource
+    private AppUserClient appUserClient;
+
+    @Resource
+    private StudentClient studentClient;
+    @Autowired
+    private VipDetailService vipDetailService;
+    @Autowired
+    private StoreClient storeClient;
+    @Autowired
+    private SiteClient siteClient;
+
+
 
 
     private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
@@ -186,6 +208,25 @@
         }
     }
 
+    @ResponseBody
+    @PostMapping("/userCoupon/updateUserCouponStatus/{id}/{storeId}/{siteId}")
+    public void updateUserCouponStatus(@PathVariable("id") Long id,@PathVariable("storeId") Integer storeId,@PathVariable("siteId") Integer siteId) {
+
+            UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getId, id));
+        userCoupon.setStatus(2);
+        if (userCoupon.getIsVipGrant()!=null && userCoupon.getIsVipGrant()==1){
+            VipDetail vipDetailServiceById = vipDetailService.getById(userCoupon.getVipDetailId());
+            vipDetailServiceById.setStatus(2);
+            List<Store> stores = storeClient.queryStoreByIds(Collections.singletonList(vipDetailServiceById.getUseStoreId()));
+            Store store = stores.get(0);
+            vipDetailServiceById.setUseSiteId(siteId);
+            vipDetailServiceById.setUseStoreId(storeId);
+            vipDetailServiceById.setOperatorId(store.getOperatorId());
+            vipDetailServiceById.setUseTime(new Date());
+            vipDetailService.updateById(vipDetailServiceById);
+        }
+    }
+
     @Autowired
     private ICouponService couponService;
 
@@ -202,6 +243,28 @@
             String couponIds = sendCouponReq.getCouponIds();
             for (String s : couponIds.split(",")) {
                 Coupon coupon = couponService.getById(s);
+                Integer userId = sendCouponReq.getUserId();
+                if(coupon.getAuditStatus() != 2){
+                    continue;
+                }
+                if(coupon.getStatus() != 2){
+                    continue;
+                }
+                if(coupon.getState() != 1){
+                    continue;
+                }
+                if(coupon.getUserPopulation() == 2){
+                    AppUser appUser = appUserClient.queryAppUser(userId);
+                    if(appUser.getIsVip() == 0){
+                        continue;
+                    }
+                }
+                if(coupon.getUserPopulation() == 3){
+                    List<TStudent> tStudents = studentClient.queryStudentList(userId);
+                    if(tStudents.size() == 0){
+                        continue;
+                    }
+                }
                 if (new Date().before(coupon.getStartTime()) && new Date().after(coupon.getEndTime())) {
                     continue;
                 }
@@ -210,6 +273,10 @@
                 queryIds.add(coupon.getId());
                 int counts = userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", s));
                 if (coupon.getQuantityIssued() <= counts) {
+                    continue;
+                }
+                counts = userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", s).eq("userId", userId));
+                if (coupon.getPickUpQuantity() <= counts) {
                     continue;
                 }
 
@@ -277,8 +344,81 @@
     @PostMapping("/userCoupon/queryCounts1")
     public Integer queryCounts1(@RequestBody List<Integer> queryIds) {
         return userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", queryIds.get(0)).eq("userId", queryIds.get(1)));
-
-
     }
 
+    // 开通会员后 赠送优惠券和门票
+    @ResponseBody
+    @PostMapping("/userCoupon/grantCoupon")
+    public void grantCoupon(@RequestBody GrantCoupon grantCoupon) {
+        String couponJson = grantCoupon.getCouponJson();
+        if (StringUtils.hasLength(couponJson)) {
+
+            // 赠送优惠券
+            JSONArray objects = JSON.parseArray(couponJson);
+            for (Object object : objects) {
+                JSONObject jsonObject = (JSONObject) object;
+                // 优惠券id
+                String id = jsonObject.getString("id");
+                // 优惠券数量
+                String value = jsonObject.getString("value");
+                for (Integer i = 0; i < Integer.valueOf(value); i++) {
+                    UserCoupon userCoupon = new UserCoupon();
+                    userCoupon.setCouponId(Integer.valueOf(id));
+                    userCoupon.setUserId(grantCoupon.getUserId());
+                    userCoupon.setStatus(1);
+                    userCoupon.setVerificationUserId(null);
+                    userCoupon.setVerificationTime(null);
+                    userCoupon.setInsertTime(new Date());
+                    userCoupon.setIsVipGrant(1);
+                    userCouponService.save(userCoupon);
+                    // 生成对应的权益明细记录
+                    VipDetail vipDetail = new VipDetail();
+                    vipDetail.setAppUserId(grantCoupon.getUserId());
+                    vipDetail.setStatus(1);
+                    vipDetail.setInsertTime(new Date());
+                    vipDetail.setVipId(grantCoupon.getVipId());
+                    vipDetail.setType(1);
+                    vipDetail.setVipPaymentId(grantCoupon.getVipPaymentId());
+                    vipDetail.setCouponId(Integer.valueOf(id));
+                    vipDetail.setUserCouponId(userCoupon.getId());
+                    vipDetailService.save(vipDetail);
+                    userCoupon.setVipDetailId(vipDetail.getId());
+                    userCoupon.setUserId(null);
+                    userCouponService.updateById(userCoupon);
+                }
+            }
+        }
+        String ticketJson = grantCoupon.getTicketJson();
+        if (StringUtils.hasLength(ticketJson)) {
+            // 赠送门票
+            JSONArray objects = JSON.parseArray(ticketJson);
+            for (Object object : objects) {
+                JSONObject jsonObject = (JSONObject) object;
+                // 门票名称
+                String name = jsonObject.getString("name");
+                // 领取后x天有效
+                String time = jsonObject.getString("time");
+                Integer days = Integer.valueOf(time);
+                // 可用次数
+                String count = jsonObject.getString("count");
+                for (Integer i = 0; i < Integer.valueOf(count); i++) {
+                    // 生成对应的权益明细记录
+                    VipDetail vipDetail = new VipDetail();
+                    vipDetail.setTicketName(name);
+                    vipDetail.setStartTime(new Date());
+                    Date date = new Date();
+                    // 加X天
+                    Date tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000L * days);
+                    vipDetail.setEndTime(tomorrow);
+                    vipDetail.setAppUserId(grantCoupon.getUserId());
+                    vipDetail.setStatus(1);
+                    vipDetail.setInsertTime(new Date());
+                    vipDetail.setVipId(grantCoupon.getVipId());
+                    vipDetail.setType(2);
+                    vipDetail.setVipPaymentId(grantCoupon.getVipPaymentId());
+                    vipDetailService.save(vipDetail);
+                }
+            }
+        }
+    }
 }

--
Gitblit v1.7.1