From ee9cb0da4a43bcf523ebb157678f64a2895fba1a Mon Sep 17 00:00:00 2001
From: nickchange <126672920+nickchange@users.noreply.github.com>
Date: 星期二, 10 十月 2023 15:30:38 +0800
Subject: [PATCH] 10.10

---
 cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TCouponController.java |  256 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 239 insertions(+), 17 deletions(-)

diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TCouponController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TCouponController.java
index 615e19a..16e7442 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TCouponController.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TCouponController.java
@@ -1,29 +1,41 @@
 package com.dsh.guns.modular.system.controller.code;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.dsh.course.feignClient.account.AppUserClient;
+import com.dsh.course.feignClient.account.CityManagerClient;
+import com.dsh.course.feignClient.account.model.CityManager;
+import com.dsh.course.feignClient.account.model.QueryByNamePhone;
+import com.dsh.course.feignClient.account.model.TAppUser;
 import com.dsh.course.feignClient.activity.CouponClient;
+import com.dsh.course.feignClient.activity.model.Coupon;
+import com.dsh.course.feignClient.activity.model.CouponCity;
 import com.dsh.course.feignClient.activity.model.CouponListOfSearch;
+import com.dsh.course.feignClient.activity.model.CouponRecordQuery;
+import com.dsh.guns.config.UserExt;
+import com.dsh.guns.core.base.tips.SuccessTip;
 import com.dsh.guns.core.common.constant.factory.PageFactory;
 import com.dsh.guns.core.util.ToolUtil;
-import com.dsh.guns.modular.system.model.Region;
-import com.dsh.guns.modular.system.service.IRegionService;
+import com.dsh.guns.modular.system.model.*;
+import com.dsh.guns.modular.system.service.*;
 import com.dsh.guns.modular.system.util.OBSUploadUtil;
+import com.dsh.guns.modular.system.util.OssUploadUtil;
+import com.dsh.guns.modular.system.util.ResultUtil;
 import org.apache.commons.beanutils.ConvertUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
@@ -34,16 +46,28 @@
 @RequestMapping("/tCouponManage")
 public class TCouponController {
 
-
-
     private String PREFIX = "/system/tCoupon/";
-
 
     @Resource
     private IRegionService regiService;
 
     @Resource
+    private IStoreService storeService;
+
+    @Resource
     private CouponClient client;
+
+    @Resource
+    private CityManagerClient cmgrClient;
+
+    @Autowired
+    private AppUserClient appUserClient;
+    @Autowired
+    private IUserService userService;
+    @Autowired
+    private TOperatorService operatorService;
+    @Autowired
+    private TOperatorCityService operatorCityService;
 
     /**
      * 跳转到优惠券管理首页
@@ -57,20 +81,125 @@
      * 跳转到添加
      */
     @RequestMapping("/coupon_add")
-    public String memberCouponAdd() {
-        return PREFIX + "TCouponAdd.html";
+    public String memberCouponAdd(Model model) {
+        Integer objectType = UserExt.getUser().getObjectType();
+        System.out.println(objectType);
+        model.addAttribute("userType",objectType);
+        return PREFIX + "TQuestionAdd.html";
+    }
+
+    @RequestMapping("/coupon_record/{id}")
+    public String memberCouponAdd(@PathVariable Integer id,Model model) {
+        Coupon coupon = client.queryCouponById(id);
+
+        model.addAttribute("id",id);
+        model.addAttribute("type",coupon.getType());
+        return PREFIX + "TCouponRecord.html";
+    }
+
+
+
+    @RequestMapping("/coupon_detail/{id}")
+    public String memberCouponDetail(@PathVariable Integer id,Model model) {
+        Coupon coupon = client.queryCouponById(id);
+        String content = coupon.getContent();
+        JSONObject jsonObject = JSONObject.parseObject(content);
+        String one ="";
+        String two ="";
+        String three ="";
+        if(coupon.getType()==1){
+            one = jsonObject.get("conditionalAmount").toString();
+            two = jsonObject.get("deductionAmount").toString();
+        }
+        if(coupon.getType()==2){
+            one = jsonObject.get("conditionalAmount").toString();
+        }
+        if(coupon.getType()==3){
+            three = jsonObject.get("experienceName").toString();
+        }
+        List<CouponCity> list = new ArrayList<>();
+        List<Integer> list1=null;
+        List<TStore> list2=new ArrayList<>();
+        if(coupon.getUseScope()==2){
+            list = client.queryCity(coupon.getId());
+        }
+        if(coupon.getUseScope()==3){
+            list1 = client.queryStore(coupon.getId());
+            list2 = storeService.list(new LambdaQueryWrapper<TStore>().in(TStore::getId, list1));
+            for (TStore tStore : list2) {
+                CityManager cityManager = cmgrClient.queryCityManagerById(tStore.getCityManagerId());
+                if (ToolUtil.isNotEmpty(cityManager)){
+                    tStore.setProvince(tStore.getProvince()+tStore.getCity());
+                    tStore.setPhone(cityManager.getName()+"-"+cityManager.getPhone());
+                }
+            }
+
+        }
+        model.addAttribute("city",list);
+        model.addAttribute("store",list2);
+        model.addAttribute("s",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getStartTime()));
+        model.addAttribute("e",new SimpleDateFormat("yyyy-MM-dd").format(coupon.getEndTime()));
+        model.addAttribute("one",one);
+        model.addAttribute("two",two);
+        model.addAttribute("three",three);
+        ArrayList<String> strings = new ArrayList<>();
+        String productImages = coupon.getProductImages();
+        for (String s : productImages.split(",")) {
+            strings.add(s);
+        }
+
+        model.addAttribute("img",strings);
+        Integer objectType = UserExt.getUser().getObjectType();
+        System.out.println(objectType);
+        model.addAttribute("item",coupon);
+        return PREFIX + "TCouponInfo.html";
     }
 
 
 
     /**
-     * 跳转到优惠券管理首页
+     * 跳转到门店管理列表页
      */
     @RequestMapping("/storeList")
     public String storePage(Model model) {
         return PREFIX + "TStoreList.html";
     }
+    @RequestMapping("/updateType")
+    @ResponseBody
+    public Object updateType(Long id) {
+        client.updateType(id);
+        return new SuccessTip<>();
+    }
 
+    @RequestMapping("/storeDetailsOfSearch")
+    @ResponseBody
+    public Object listOfStore(String provinceId,String cityId,Integer operatorId,String storeName){
+
+
+        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
+        List<Map<String,Object>> storeList = storeService.queryListOfpage(provinceId,cityId,operatorId,storeName,page);
+        if (storeList.size() > 0 ){
+            for (Map<String, Object> stringObjectMap : storeList) {
+                String provinceName = (String) stringObjectMap.get("province");
+                String cityName = (String) stringObjectMap.get("city");
+                stringObjectMap.put("provinceCity",provinceName+cityName);
+                Integer managerId = (Integer) stringObjectMap.get("operatorId");
+                if (managerId==0){
+                    stringObjectMap.put("accountName","平台");
+                }else{
+                    TOperator operator = operatorService.getOne(new QueryWrapper<TOperator>().eq("id", managerId));
+                    if (ToolUtil.isNotEmpty(operator)){
+                        stringObjectMap.put("accountName",operator.getName());
+                    }else{
+                        stringObjectMap.put("accountName","平台");
+
+                    }
+                }
+
+            }
+        }
+        return storeList;
+    }
 
     /**
      * 获取 优惠券管理
@@ -90,11 +219,66 @@
         return client.getCouponListOfSearch(ofSearch);
     }
 
+    /**
+     * 获取 优惠券管理
+     */
+    @RequestMapping(value = "/list1")
+    @ResponseBody
+    public Object listOfDatas1(String name, Integer type, Integer distributionMethod , Integer userPopulation, Integer status, Integer state,String cityCode,Integer storeId) {
+        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
+        CouponListOfSearch ofSearch = new CouponListOfSearch();
+        ofSearch.setPage(page);
+        ofSearch.setName(name);
+        ofSearch.setType(type);
+        ofSearch.setDistributionMethod(distributionMethod);
+        ofSearch.setUserPopulation(userPopulation);
+        ofSearch.setStatus(status);
+        ofSearch.setState(state);
+        ofSearch.setCityCode(cityCode);
+        ofSearch.setStoreId(storeId);
+        return client.getCouponListOfSearch(ofSearch);
+    }
+    @RequestMapping(value = "/listRecord")
+    @ResponseBody
+    public Object listRecord(Integer id,String name, Integer type, String phone) {
+        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
+        List<TAppUser> tAppUsers = appUserClient.queryByNamePhone(new QueryByNamePhone(name, phone));
+        if(tAppUsers.size()==0){
+            return new ArrayList<>();
+        }
+        CouponRecordQuery ofSearch = new CouponRecordQuery();
+        ofSearch.setId(id);
+        ofSearch.setLimit(page.getSize());
+        ofSearch.setOffset(page.getCurrent());
+        ofSearch.setIds(tAppUsers.stream().map(TAppUser::getId).collect(Collectors.toList()));
+        ofSearch.setType(type);
+        List<Map<String, Object>> maps = client.listRecord(ofSearch);
+        for (Map<String, Object> map : maps) {
+            map.put("id",map.get("id").toString());
+            for (TAppUser tAppUser : tAppUsers) {
+                if(map.get("userId").equals(tAppUser.getId())){
+                    map.put("name",tAppUser.getName());
+                    map.put("phone",tAppUser.getPhone());
+                }
+            }
+        }
+        return maps;
+    }
+
     @RequestMapping(value = "/getProvince")
     @ResponseBody
     public Object getProvince(){
         return regiService.list(new LambdaQueryWrapper<Region>()
                 .eq(Region::getParentId,0));
+    }
+
+    @RequestMapping(value = "/onShelf")
+    @ResponseBody
+    public Object onShelf(Integer id,Integer type){
+        Coupon coupon = client.queryCouponById(id);
+        coupon.setState(type);
+        client.updateCouponData(coupon);
+        return new SuccessTip<>();
     }
 
 
@@ -104,13 +288,26 @@
         return regiService.list(new LambdaQueryWrapper<Region>()
                 .eq(Region::getParentId,province));
     }
+    // 通过市 获取运营商
+    @RequestMapping(value = "/getOperator")
+    @ResponseBody
+    public Object getOperator(String city){
+        List<TOperatorCity> name = operatorCityService.list(new QueryWrapper<TOperatorCity>().eq("name", city));
+        List<Integer> collect = name.stream().map(TOperatorCity::getOperatorId)
+                .collect(Collectors.toList());
+        if (collect.size()==0){
+            return new ArrayList<>();
+        }
+        return operatorService.list(new QueryWrapper<TOperator>().in("id",collect));
+    }
 
     @RequestMapping(value = "/uploadPic")
     @ResponseBody
     public Object add(@RequestParam("file") MultipartFile imgFile) throws IOException {
+        if (imgFile != null){
         String originalFilename = imgFile.getOriginalFilename();
         String newName = originalFilename.substring(imgFile.getOriginalFilename().lastIndexOf("."));
-        String url = OBSUploadUtil.inputStreamUpload(imgFile);
+        String url = OssUploadUtil.ossUpload("img/",imgFile);
         Map<String, String> map = new HashMap<String, String>();
         //是否上传成功
         map.put("state", "SUCCESS");
@@ -125,6 +322,31 @@
         //文件大小(字节数)
         map.put("size", imgFile.getSize() + "");
         System.out.println(map);
-        return url;
+            return url;
+        }
+        return ResultUtil.success();
+    }
+
+    /**
+     * 提交添加
+     */
+    @PostMapping(value = "/commitData")
+    @ResponseBody
+    public Object commitData( CouponDataVo dataVo){
+        System.out.println(dataVo);
+        Integer objectType = UserExt.getUser().getObjectType();
+        dataVo.setUserType(objectType);
+        client.insertIntoData(dataVo);
+        return new SuccessTip<>();
+    }
+    @PostMapping(value = "/update")
+    @ResponseBody
+    public Object update( Integer id,Integer num,Integer num1,String text){
+        Coupon coupon = client.queryCouponById(id);
+        coupon.setQuantityIssued(num);
+        coupon.setPickUpQuantity(num1);
+        coupon.setIllustrate(text);
+        client.updateCouponData(coupon);
+        return new SuccessTip<>();
     }
 }

--
Gitblit v1.7.1