From 7504753468ffbd0af41b07de66c0ccebf73680ea Mon Sep 17 00:00:00 2001
From: lisy <linlangsur163@163.com>
Date: 星期一, 14 八月 2023 15:47:20 +0800
Subject: [PATCH] 管理后台:添加优惠券的字段优化

---
 cloud-server-activity/src/main/java/com/dsh/activity/controller/PointMercharsController.java |  171 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 129 insertions(+), 42 deletions(-)

diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/PointMercharsController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/PointMercharsController.java
index 898ee0c..24697ee 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/PointMercharsController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/PointMercharsController.java
@@ -1,6 +1,7 @@
 package com.dsh.activity.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.dsh.activity.entity.*;
 import com.dsh.activity.feignclient.course.CoursePackageClient;
@@ -10,6 +11,8 @@
 import com.dsh.activity.feignclient.model.*;
 import com.dsh.activity.feignclient.other.StoreClient;
 import com.dsh.activity.feignclient.other.model.StoreDetailOfCourse;
+import com.dsh.activity.model.PointMerchandiseVo;
+import com.dsh.activity.model.request.AppUserGoodResp;
 import com.dsh.activity.model.request.CommodityRequest;
 import com.dsh.activity.service.*;
 import com.dsh.activity.util.GDMapGeocodingUtil;
@@ -17,11 +20,9 @@
 import com.dsh.activity.util.TokenUtil;
 import com.dsh.activity.util.ToolUtil;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -64,13 +65,18 @@
     @Autowired
     private TokenUtil tokenUtil;
 
+    @Resource
+    private CouponCityService ccityService;
 
+
+    @ResponseBody
     @PostMapping("/base/pointMerchars/convertGoods")
     public List<IntegralCommodity> getConvertibleGoods(){
         List<IntegralCommodity> commodity = new ArrayList<>();
         List<PointsMerchandise> merchandises = pmdsService.list(new QueryWrapper<PointsMerchandise>()
                 .eq("state",1)
-                .lt("endTime",new Date()));
+                .eq("shelves",1)
+                .gt("endTime",new Date()));
         if (merchandises.size() > 0){
             for (PointsMerchandise merchandise : merchandises) {
                 IntegralCommodity integralCommodity = new IntegralCommodity();
@@ -78,17 +84,25 @@
                 integralCommodity.setCommodityImg(merchandise.getProductImages());
                 integralCommodity.setCommodityName(merchandise.getName());
                 integralCommodity.setCommodityPrice(merchandise.getPrice());
+                integralCommodity.setGoodsType(merchandise.getType());
                 commodity.add(integralCommodity);
             }
         }
+        System.out.println(commodity);
         return commodity;
     }
 
 
+    @ResponseBody
     @PostMapping("/base/pointMerchars/getCommoditys")
-    public List<PointsMerchandise> getVicinityGoods(@RequestBody CommodityRequest request){
+    public PointMerchandiseVo getVicinityGoods(@RequestBody CommodityRequest request){
+        PointMerchandiseVo pointMerchandiseVo = new PointMerchandiseVo();
+        List<PointsMerchandise> list =  new ArrayList<>();
         String provinceCode = "";
         String cityCode = "";
+        if (ToolUtil.isEmpty(request.getLon()) && ToolUtil.isEmpty(request.getLat())){
+            return pointMerchandiseVo;
+        }
         try {
             Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat());
             provinceCode = geocode.get("provinceCode");
@@ -97,8 +111,9 @@
             e.printStackTrace();
         }
 
-        List<PointsMerchandise> list = pmdsService.list(new QueryWrapper<PointsMerchandise>()
-                .eq("state", 1));
+        list = pmdsService.list(new QueryWrapper<PointsMerchandise>()
+                .eq("state", 1)
+                .eq("shelves",1));
         if (list.size() > 0 ){
             Iterator<PointsMerchandise> iterator = list.iterator();
             while (iterator.hasNext()) {
@@ -107,8 +122,9 @@
                     iterator.remove(); // 移除符合条件的商品
                 }
             }
+            pointMerchandiseVo.setMerchandises(list);
         }
-        return list;
+        return pointMerchandiseVo;
     }
 
     @PostMapping("/base/pointMerchars/getRedeemedNums")
@@ -129,8 +145,9 @@
                 CoursePackage coursePackage = cpClient.queryCoursePackageById(merchandise.getCoursePackageId());
 
                 detailsVo.setGoodId(coursePackage.getId());
-                List<String> list1 = Arrays.asList(StrUtils.splitStr2StrArr(coursePackage.getDetailDrawing(), ","));
+                List<String> list1 = new ArrayList<>();
                 list1.add(coursePackage.getCoverDrawing());
+                list1.addAll(Arrays.asList(StrUtils.splitStr2StrArr(coursePackage.getDetailDrawing(), ",")));
                 detailsVo.setPics(list1);
                 Collections.sort(detailsVo.getPics(), (s1, s2) -> {
                     if (s1.equals(coursePackage.getCoverDrawing())) {
@@ -146,14 +163,15 @@
                 int coursePackageNums = upmseService.count(new QueryWrapper<UserPointsMerchandise>()
                         .eq("pointsMerchandiseId",merchandise.getId() ));
                 detailsVo.setRedeemedNum(coursePackageNums);
-                detailsVo.setResidueNum(merchandise.getQuantityIssued() - coursePackageNums);
+                detailsVo.setResidueNum(Math.max(merchandise.getQuantityIssued() - coursePackageNums, 0));
                 detailsVo.setPerLimit(merchandise.getPickUpQuantity());
                 if (merchandise.getRedemptionMethod() == 1){
                     detailsVo.setExchangeType(1);
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分");
+                    detailsVo.setIntegral(merchandise.getIntegral());
                 }else {
                     detailsVo.setExchangeType(2);
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分+¥"+merchandise.getCash());
+                    detailsVo.setIntegral(merchandise.getIntegral());
+                    detailsVo.setCash(merchandise.getCash());
                 }
                 detailsVo.setCost(merchandise.getPrice());
                 if (merchandise.getUseScope() == 1){
@@ -171,12 +189,13 @@
                     detailsVo.setBelongs(courseOfStore.getStoreName()+"可用");
                 }
                 List<CoursePackagePaymentConfig> courseConfigList = cpcfigClient.getCourseConfigList(coursePackage.getId());
-                int redul = 0;
 
                 for (CoursePackagePaymentConfig coursePackagePaymentConfig : courseConfigList) {
-                    redul = redul + coursePackagePaymentConfig.getClassHours();
+                    if (Objects.equals(coursePackagePaymentConfig.getId(), merchandise.getCoursePackageConfigId())){
+                        detailsVo.setCourseHours(coursePackagePaymentConfig.getClassHours());
+                        break;
+                    }
                 }
-                detailsVo.setCourseHours(redul);
                 detailsVo.setStartTime(format.format(merchandise.getStartTime()));
                 detailsVo.setEndTime(format.format(merchandise.getEndTime()));
 
@@ -188,8 +207,10 @@
             case 3:
 
                 detailsVo.setGoodId(merchandise.getId());
-                List<String> list2 = Arrays.asList(StrUtils.splitStr2StrArr(merchandise.getProductImages(), ","));
-                list2.add(merchandise.getCover());
+                List<String> list2 = new ArrayList<>();
+                String cover = merchandise.getCover();
+                list2.add(cover);
+                list2.addAll(Arrays.asList(StrUtils.splitStr2StrArr(merchandise.getProductImages(), ",")));
                 detailsVo.setPics(list2);
                 Collections.sort(detailsVo.getPics(), (s1, s2) -> {
                     if (s1.equals(merchandise.getCover())) {
@@ -206,19 +227,24 @@
                 int count = upmseService.count(new QueryWrapper<UserPointsMerchandise>()
                         .eq("pointsMerchandiseId",merchandise.getId() ));
                 detailsVo.setRedeemedNum(count);
-                detailsVo.setResidueNum(merchandise.getQuantityIssued()-count);
+                detailsVo.setResidueNum(Math.max(merchandise.getQuantityIssued() - count, 0));
                 detailsVo.setPerLimit(merchandise.getPickUpQuantity());
+                detailsVo.setExchangeType(merchandise.getRedemptionMethod());
                 if (merchandise.getRedemptionMethod() == 1){
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分");
+                    detailsVo.setIntegral(merchandise.getIntegral());
                 }else {
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分+¥"+merchandise.getCash());
+                    detailsVo.setIntegral(merchandise.getIntegral());
+                    detailsVo.setCash(merchandise.getCash());
                 }
                 detailsVo.setCost(merchandise.getPrice());
                 if (merchandise.getUseScope() == 1){
+                    detailsVo.setExchangeAddrType(1);
                     detailsVo.setBelongs("全国通用");
                 }else if (merchandise.getUseScope() == 2){
+                    detailsVo.setExchangeAddrType(2);
                     detailsVo.setBelongs(merchandise.getProvince()+"|"+merchandise.getCity() + "用户可用");
                 }else {
+                    detailsVo.setExchangeAddrType(3);
                     List<PointsMerchandiseStore> list = pmdstoService.list(new QueryWrapper<PointsMerchandiseStore>()
                             .eq("pointsMerchandiseId",merchandise.getId() ));
                     PointsMerchandiseStore pointsMerchandiseStore = list.get(0);
@@ -236,8 +262,11 @@
 //                优惠券
                 Coupon coupon = iCouponService.getById(detailRequest.getGoodId());
                 detailsVo.setGoodId(coupon.getId());
-                List<String> list3 = Arrays.asList(StrUtils.splitStr2StrArr(coupon.getProductImages(), ","));
-                list3.add(coupon.getCover());
+                List<String> list3 = new ArrayList<>();
+                list3.add(ToolUtil.isEmpty(coupon.getCover()) ? "" : coupon.getCover());
+                if (ToolUtil.isNotEmpty(coupon.getProductImages())){
+                    list3.addAll(Arrays.asList(StrUtils.splitStr2StrArr(coupon.getProductImages(), ",")));
+                }
                 detailsVo.setPics(list3);
                 Collections.sort(detailsVo.getPics(), (s1, s2) -> {
                     if (s1.equals(coupon.getCover())) {
@@ -250,28 +279,37 @@
                 });
                 detailsVo.setGoodName(coupon.getName());
                 detailsVo.setBelongsScope(coupon.getUserPopulation());
-                int couponNums = uconService.count(new QueryWrapper<UserCoupon>()
-                        .eq("couponId",coupon.getId() ));
+                int couponNums = upmseService.count(new QueryWrapper<UserPointsMerchandise>()
+                        .eq("pointsMerchandiseId",merchandise.getId() ));
                 detailsVo.setRedeemedNum(couponNums);
-                detailsVo.setResidueNum(coupon.getQuantityIssued()-couponNums);
+                detailsVo.setResidueNum(Math.max(coupon.getQuantityIssued() - couponNums, 0));
                 detailsVo.setPerLimit(coupon.getPickUpQuantity());
-                if (merchandise.getRedemptionMethod() == 1){
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分");
+                detailsVo.setExchangeType(coupon.getRedemptionMethod());
+                if (coupon.getRedemptionMethod() == 1){
+                    detailsVo.setIntegral(coupon.getIntegral().intValue());
                 }else {
-                    detailsVo.setRequiredType(merchandise.getIntegral() + "积分+¥"+merchandise.getCash());
+                    detailsVo.setIntegral(coupon.getIntegral().intValue());
+                    detailsVo.setCash(coupon.getCash());
                 }
                 if (coupon.getUseScope() == 1){
+                    detailsVo.setExchangeAddrType(1);
                     detailsVo.setBelongs("全国通用");
                 }else if (coupon.getUseScope() == 2){
-                    detailsVo.setBelongs(coupon.getProvince()+"|"+coupon.getCity() + "用户可用");
+                    detailsVo.setExchangeAddrType(2);
+                    List<CouponCity> list = ccityService.list(new LambdaQueryWrapper<CouponCity>()
+                            .eq(CouponCity::getCouponId, coupon.getId()));
+                    if (list.size() > 0){
+                        detailsVo.setBelongs(list.get(0).getProvince()+"|"+list.get(0).getCity() + "用户可用");
+                    }
                 }else {
+                    detailsVo.setExchangeAddrType(3);
                     List<CouponStore> list = cstoreService.list(new QueryWrapper<CouponStore>()
                             .eq("couponId",coupon.getId() ));
                     StoreDetailOfCourse courseOfStore = stoClient.getCourseOfStore(list.get(0).getStoreId());
                     detailsVo.setBelongs(courseOfStore.getStoreName()+"可用");
                 }
-                detailsVo.setStartTime(format.format(merchandise.getStartTime()));
-                detailsVo.setEndTime(format.format(merchandise.getEndTime()));
+                detailsVo.setStartTime(format.format(coupon.getStartTime()));
+                detailsVo.setEndTime(format.format(coupon.getEndTime()));
 
                 detailsVo.setContents(coupon.getIllustrate());
                 detailsVo.setGoodType(4);
@@ -283,9 +321,10 @@
     }
 
 
-
+    @ResponseBody
     @PostMapping("/base/pointMerchars/getDetailsOfExchange")
-    public List<ExchangeDetailsResponse> getIntegralExchangeDetails(@RequestBody Integer appUserId){
+    public ExchangeDetailsVo getIntegralExchangeDetails(@RequestBody Integer appUserId){
+        ExchangeDetailsVo detailsVo = new ExchangeDetailsVo();
         List<ExchangeDetailsResponse> responses = new ArrayList<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         List<UserPointsMerchandise> pointsMerchandises = upmseService.list(new QueryWrapper<UserPointsMerchandise>()
@@ -297,22 +336,26 @@
                 detailsResponse.setDetailsId(pointsMerchandise.getId());
                 detailsResponse.setGoodName(merchandise.getName());
                 if (merchandise.getRedemptionMethod() == 1){
-                    detailsResponse.setRequiredType(merchandise.getIntegral()+"积分");
+                    detailsResponse.setExchangeType(1);
+                    detailsResponse.setIntegral(merchandise.getIntegral());
                 }else {
-                    detailsResponse.setRequiredType(merchandise.getIntegral()+"积分 ¥"+merchandise.getCash());
+                    detailsResponse.setExchangeType(2);
+                    detailsResponse.setIntegral(merchandise.getIntegral());
+                    detailsResponse.setCash(merchandise.getCash());
                 }
                 detailsResponse.setStartTime(simpleDateFormat.format(merchandise.getStartTime()));
                 detailsResponse.setEndTime(simpleDateFormat.format(merchandise.getEndTime()));
-                detailsResponse.setUseStatus(pointsMerchandise.getStatus());
+                detailsResponse.setUseStatus(pointsMerchandise.getStatus() == 1 ? 2 : 1);
                 detailsResponse.setGoodType(merchandise.getType());
                 responses.add(detailsResponse);
             }
+            detailsVo.setDetailsResponses(responses);
         }
-        return responses;
+        return detailsVo;
     }
 
 
-
+    @ResponseBody
     @PostMapping("/base/pointMerchars/getSpecificsOfGoods")
     public PointDetailsVo getSpecificsOfGoods(@RequestBody Integer speMercharsId){
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
@@ -320,6 +363,14 @@
         UserPointsMerchandise byId = upmseService.getById(speMercharsId);
         if (ToolUtil.isNotEmpty(byId)){
             PointsMerchandise pmdsServiceById = pmdsService.getById(byId.getPointsMerchandiseId());
+            detailsVo.setExchangeType(pmdsServiceById.getRedemptionMethod());
+            detailsVo.setGoodType(pmdsServiceById.getType());
+            if (pmdsServiceById.getRedemptionMethod() == 1){
+                detailsVo.setIntegral(pmdsServiceById.getIntegral());
+            }else {
+                detailsVo.setCash(pmdsServiceById.getCash());
+                detailsVo.setIntegral(pmdsServiceById.getIntegral());
+            }
             detailsVo.setDetailsId(byId.getId());
             switch (pmdsServiceById.getType()){
                 case 1:
@@ -342,6 +393,8 @@
                     List<String> list1 = Arrays.asList(StrUtils.splitStr2StrArr(coursePackage.getDetailDrawing(), ","));
                     list1.add(coursePackage.getCoverDrawing());
                     detailsVo.setPics(list1);
+                    CoursePackagePaymentConfig coursePackagePaymentConfig = cpClient.queryConfigCoursePackData(pmdsServiceById.getCoursePackageConfigId());
+                    detailsVo.setClassHours(coursePackagePaymentConfig.getClassHours());
                     Collections.sort(detailsVo.getPics(), (s1, s2) -> {
                         if (s1.equals(coursePackage.getCoverDrawing())) {
                             return -1; // s1排在前面
@@ -391,9 +444,7 @@
                     detailsVo.setBelongs(pmdsServiceById.getProvince()+pmdsServiceById.getCity());
                     break;
                 case 3:
-                    PointsMerchandiseStore one = pmdstoService.getOne(new QueryWrapper<PointsMerchandiseStore>()
-                            .eq("pointsMerchandiseId",pmdsServiceById.getId() ));
-                    StoreDetailOfCourse courseOfStore = stoClient.getCourseOfStore(one.getStoreId());
+                    StoreDetailOfCourse courseOfStore = stoClient.getCourseOfStore(byId.getStoreId());
                     detailsVo.setBelongs(courseOfStore.getStoreName()+" "+courseOfStore.getStoreAddr());
                     break;
                 default:
@@ -413,6 +464,7 @@
 
     @PostMapping("/base/pointMerchars/saveDetailsUserPointMercase")
     public void saveDetailsUserPointMercase(@RequestBody UserPointsMerchandise merchandise){
+        merchandise.setInsertTime(new Date());
         upmseService.save(merchandise);
     }
 
@@ -440,4 +492,39 @@
         return storeIds;
     }
 
+    /**
+     * 获取用户已兑换商品的数量
+     * @param goodResp
+     * @return 数量
+     */
+    @ResponseBody
+    @PostMapping("/base/pointMerchars/queryUserHasGoodsNums")
+    public int queryUserHasGoodsNums(@RequestBody AppUserGoodResp goodResp){
+        int count = upmseService.count(new LambdaQueryWrapper<UserPointsMerchandise>()
+                .eq(UserPointsMerchandise::getUserId,goodResp.getGoodId())
+                .eq(UserPointsMerchandise::getPointsMerchandiseId,goodResp.getGoodId()));
+        System.out.println(count);
+        return count;
+    }
+
+
+    /**
+     * 变更兑换商品的的状态
+     * @param code
+     * @return 数量
+     */
+    @ResponseBody
+    @PostMapping("/base/pointMerchars/deletePaymentRecord")
+    public void deletePaymentRecord(@RequestBody String code){
+        List<UserPointsMerchandise> list = upmseService.list(new LambdaQueryWrapper<UserPointsMerchandise>()
+                .eq(UserPointsMerchandise::getCode,code));
+        if (list.size() > 0 ){
+            for (UserPointsMerchandise pointsMerchandise : list) {
+                pointsMerchandise.setState(2);
+                upmseService.updateById(pointsMerchandise);
+            }
+        }
+
+    }
+
 }

--
Gitblit v1.7.1