From 631a5aa09e0147ca81fffcb1434e57b1cd1ba6f6 Mon Sep 17 00:00:00 2001
From: lisy <linlangsur163@163.com>
Date: 星期三, 09 八月 2023 09:34:53 +0800
Subject: [PATCH] app端口:积分变动记录增加变动类型字段,代码同步更新;积分兑换操作的数量校验功能完善

---
 cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java |  103 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
index c0c704b..55f41f0 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
@@ -14,10 +14,13 @@
 import com.dsh.activity.feignclient.account.model.TStoreStaff;
 import com.dsh.activity.feignclient.model.CouponExamineListSearch;
 import com.dsh.activity.feignclient.model.CouponListOfSearch;
+import com.dsh.activity.feignclient.other.RegionClient;
 import com.dsh.activity.feignclient.other.StoreClient;
+import com.dsh.activity.feignclient.other.model.CityDataAndProvinceDataVo;
 import com.dsh.activity.feignclient.other.model.Store;
 import com.dsh.activity.model.CouponListVo;
 import com.dsh.activity.model.request.CommodityRequest;
+import com.dsh.activity.model.request.CouponDataVo;
 import com.dsh.activity.model.request.CouponPackageReq;
 import com.dsh.activity.model.response.CouponPackageResp;
 import com.dsh.activity.service.CouponCityService;
@@ -35,6 +38,7 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -68,6 +72,10 @@
 
     @Resource
     private StoreClient stoClient;
+
+
+    @Resource
+    private RegionClient regionClient;
 
     @Resource
     private CouponStoreService couStoreService;
@@ -264,14 +272,15 @@
             JSONObject jsonObject = JSON.parseObject(coupon.getContent());
             switch (coupon.getType()){
                 case 1:
-                    couponInfo.put("num1",jsonObject.getDouble("num1"));
-                    couponInfo.put("num2",jsonObject.getDouble("num2"));
+//                {"conditionalAmount":50,"deductionAmount":10,"experienceName":""}
+                    couponInfo.put("num1",jsonObject.getDouble("conditionalAmount"));
+                    couponInfo.put("num2",jsonObject.getDouble("deductionAmount"));
                     break;
                 case 2:
-                    couponInfo.put("num1",jsonObject.getDouble("num1"));
+                    couponInfo.put("num1",jsonObject.getDouble("conditionalAmount"));
                     break;
                 case 3:
-                    couponInfo.put("num1",jsonObject.getString("num1"));
+                    couponInfo.put("num1",jsonObject.getString("experienceName"));
                     break;
                 default:
                     break;
@@ -366,4 +375,90 @@
         }
     }
 
+    @ResponseBody
+    @PostMapping("/base/coupon/insertIntoCouponData")
+    public boolean saveCouponData(@RequestBody CouponDataVo dataVo){
+        try {
+            System.out.println(dataVo);
+            Coupon coupon = new Coupon();
+            coupon.setName(dataVo.getCouponName());
+            coupon.setType(dataVo.getPrescription());
+            HashMap<String, Object> stringObjectHashMap = new HashMap<>();
+            switch (dataVo.getPrescription()){
+//                {"conditionalAmount":50,"deductionAmount":10,"experienceName":""}
+                case 1:
+                    stringObjectHashMap.put("conditionalAmount",dataVo.getCondition());
+                    stringObjectHashMap.put("deductionAmount",dataVo.getSubtraction());
+                    coupon.setContent(stringObjectHashMap.toString());
+                    break;
+                case 2:
+                    stringObjectHashMap.put("conditionalAmount",dataVo.getDiscount());
+                    coupon.setContent(stringObjectHashMap.toString());
+                    break;
+                case 3:
+                    stringObjectHashMap.put("experienceName",dataVo.getExperience());
+                    coupon.setContent(stringObjectHashMap.toString());
+                    break;
+                default:
+                    break;
+            }
+            coupon.setIllustrate(dataVo.getIllustrate());
+            coupon.setDistributionMethod(dataVo.getDistributionMethod());
+            coupon.setRedemptionMethod(dataVo.getExchangeMethod());
+            coupon.setCash(dataVo.getRequiredCash());
+            coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints()));
+            coupon.setQuantityIssued(dataVo.getQuantityIssued());
+            coupon.setPickUpQuantity(dataVo.getPickUpQuantity());
+            coupon.setUseScope(dataVo.getCompany());
+            coupon.setAuditStatus(1);
+            coupon.setStatus(1);
+            coupon.setInsertTime(new Date());
+            coupon.setCover(dataVo.getGoodImg());
+            List<String> goodImgs = dataVo.getGoodImgs();
+            StringBuilder builder = new StringBuilder();
+            if (goodImgs.size() > 0){
+                if (goodImgs.size() == 1){
+                    coupon.setProductImages(goodImgs.get(0));
+                }else {
+                    for (String goodImg : goodImgs) {
+                        builder.append(goodImg).append(",");
+                    }
+                    builder.deleteCharAt(builder.lastIndexOf(","));
+                    coupon.setProductImages(builder.toString());
+                }
+            }
+            coupon.setPublisherType(dataVo.getUserType());
+            if (dataVo.getUserType() == 1){
+                coupon.setCityManagerId(dataVo.getCityManagerId());
+            }
+            boolean save = couponService.save(coupon);
+            if (save){
+                if (dataVo.getCompany() == 2){
+                    for (Integer storeId : dataVo.getStoreIds()) {
+                        CouponStore couponStore = new CouponStore();
+                        couponStore.setCouponId(coupon.getId());
+                        couponStore.setStoreId(storeId);
+                        couStoreService.save(couponStore);
+                    }
+                }
+                List<Integer> cityIds = dataVo.getCityIds();
+                if (dataVo.getCompany() == 3 && cityIds.size() > 0 ){
+                    List<CityDataAndProvinceDataVo> cityAndProvince = regionClient.getCityAndProvince(cityIds);
+                    for (CityDataAndProvinceDataVo cityId : cityAndProvince) {
+                        CouponCity couponCity = new CouponCity();
+                        couponCity.setCouponId(coupon.getId());
+                        couponCity.setCityCode(cityId.getCityCode());
+                        couponCity.setCity(cityId.getCityName());
+                        couponCity.setProvinceCode(cityId.getProvinceCode());
+                        couponCity.setProvince(cityId.getProvinceName());
+                        cityService.save(couponCity);
+                    }
+                }
+            }
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
 }

--
Gitblit v1.7.1