| 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.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.CouponExamineListSearch; | 
| import com.dsh.course.feignClient.activity.model.CouponListOfSearch; | 
| import com.dsh.guns.config.UserExt; | 
| import com.dsh.guns.core.base.controller.BaseController; | 
| import com.dsh.guns.core.common.constant.factory.PageFactory; | 
| import com.dsh.guns.core.exception.GunsException; | 
| import com.dsh.guns.core.util.ToolUtil; | 
| import com.dsh.guns.modular.system.model.TOperator; | 
| import com.dsh.guns.modular.system.model.TStore; | 
| import com.dsh.guns.modular.system.model.User; | 
| import com.dsh.guns.modular.system.service.IStoreService; | 
| import com.dsh.guns.modular.system.service.IUserService; | 
| import com.dsh.guns.modular.system.service.TOperatorService; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.ui.Model; | 
| import org.springframework.web.bind.annotation.PathVariable; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import java.text.SimpleDateFormat; | 
| import java.util.ArrayList; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * 优惠券审核 控制器 | 
|  */ | 
|   | 
| @Controller | 
| @RequestMapping("/tCouponExamine") | 
| public class TCouponExamineController extends BaseController { | 
|   | 
|   | 
|     private String PREFIX = "/system/tCouponExamine/"; | 
|   | 
|     @Resource | 
|     private CouponClient client; | 
|     @Autowired | 
|     private IUserService userService; | 
|     @Autowired | 
|     private TOperatorService operatorService; | 
|     @Autowired | 
|     private IStoreService storeService; | 
|   | 
|     /** | 
|      * 优惠券审核列表页 | 
|      */ | 
|     @RequestMapping("") | 
|     public String index(Model model) { | 
|         return PREFIX + "TCouponExamineList.html"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取根据门店id 获取店长信息 | 
|      */ | 
|     @RequestMapping(value = "/getStoreInfo") | 
|     @ResponseBody | 
|     public String getStoreInfo(@RequestBody Integer id) { | 
|         User byId = userService.getById(id); | 
|         return byId.getName() + "-" + byId.getAccount(); | 
|     } | 
|     /** | 
|      * 获取 优惠券审核列表 | 
|      */ | 
|     @RequestMapping(value = "/list") | 
|     @ResponseBody | 
|     public Object listOfDatas(String name, Integer type, Integer distributionMethod , Integer userPopulation, Integer auditStatus) { | 
|         Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); | 
|         CouponExamineListSearch ofSearch = new CouponExamineListSearch(); | 
|         ofSearch.setPage(page); | 
|         ofSearch.setName(name); | 
|         ofSearch.setType(type); | 
|         ofSearch.setDistributionMethod(distributionMethod); | 
|         ofSearch.setUserPopulation(userPopulation); | 
|         ofSearch.setAuditStatus(auditStatus); | 
|         List<Map<String, Object>> res = client.getCouponExamineListOfSearch(ofSearch); | 
|         for (Map<String, Object> re : res) { | 
|             if (re.get("publisherType")!=null){ | 
|   | 
|             } | 
|             switch (Integer.valueOf(re.get("publisherType").toString())){ | 
|                 case 1: | 
|                     // 运营商添加 | 
|                     if (re.get("cityManagerId")!=null){ | 
|                         TOperator one = operatorService.getOne(new QueryWrapper<TOperator>() | 
|                                 .eq("id", Integer.valueOf(re.get("cityManagerId").toString()))); | 
|                         if (one!=null){ | 
|                             User id = userService.getOne(new QueryWrapper<User>().eq("id", one.getUserId())); | 
|                             if (id!=null){ | 
|                                 re.put("account",one.getName()+"-"+id.getPhone()); | 
|                             } | 
|                         } | 
|                     } | 
|                     break; | 
|                 case 2: | 
|                     re.put("account","平台"); | 
|                     // 平台添加 | 
|                     break; | 
|                 case 3: | 
|                     // 门店添加 | 
|                     if (re.get("cityManagerId")!=null){ | 
|                         TStore one = storeService.getOne(new QueryWrapper<TStore>() | 
|                                 .eq("id", Integer.valueOf(re.get("cityManagerId").toString()))); | 
|                         if (one!=null){ | 
|                             User id = userService.getOne(new QueryWrapper<User>().eq("id", one.getStoreStaffId())); | 
|                             if (id!=null){ | 
|                                 re.put("account",one.getName()+"-"+id.getPhone()); | 
|                             } | 
|                         } | 
|                     } | 
|                     break; | 
|             } | 
|         } | 
|         return res; | 
|     } | 
|   | 
|     /** | 
|      * 获取 优惠券审核详情 | 
|      */ | 
|     @RequestMapping(value = "/couponOfDetail/{id}") | 
|     public String detailOfCoupon(@PathVariable Integer id, Model model){ | 
|         model.addAttribute("id",id); | 
|         Coupon coupon = client.queryCouponById(id); | 
|         Integer auditStatus1 = coupon.getAuditStatus(); | 
|         model.addAttribute("state",auditStatus1); | 
|         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){ | 
|             // 门店ids | 
|             list1 = client.queryStore(coupon.getId()); | 
|             // 门店集合 | 
|             list2 = storeService.list(new LambdaQueryWrapper<TStore>().in(TStore::getId, list1)); | 
|             for (TStore tStore : list2) { | 
|                 if (coupon.getPublisherType() == 1){ | 
|                     // 获取运营商id | 
|                     Integer operatorId = tStore.getOperatorId(); | 
|                     TOperator operator = operatorService.getById(operatorId); | 
|                     User user = userService.getById(operator.getUserId()); | 
|                     if (ToolUtil.isNotEmpty(user)){ | 
|                         tStore.setProvince(tStore.getProvince()+tStore.getCity()); | 
|                         tStore.setPhone(user.getName()+"-"+user.getPhone()); | 
|                     } | 
|                 } | 
|                 if (coupon.getPublisherType() == 2) { | 
|                     User byId = userService.getById(tStore.getStoreStaffId()); | 
|   | 
|                     tStore.setProvince(tStore.getProvince() + tStore.getCity()); | 
|                     tStore.setPhone(byId.getName() + "-" + byId.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("integral",coupon.getIntegral()); | 
|         model.addAttribute("cash",coupon.getCash()); | 
|         model.addAttribute("img",strings); | 
|         Integer objectType = UserExt.getUser().getObjectType(); | 
|         System.out.println(objectType); | 
|         model.addAttribute("item",coupon); | 
|         model.addAttribute("objectType",objectType); | 
|         Integer auditStatus = coupon.getAuditStatus(); | 
|         switch (auditStatus){ | 
|             case 1: | 
|                 model.addAttribute("state","待审核"); | 
|                 break; | 
|             case 2: | 
|                 model.addAttribute("state","已拒绝"); | 
|                 break; | 
|             case 3: | 
|                 model.addAttribute("state","未通过"); | 
|                 break; | 
|         } | 
|         model.addAttribute("cover",coupon.getCover()); | 
|         model.addAttribute("productImages",coupon.getProductImages()); | 
|         return PREFIX + "TCouponExamineInfo.html"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取 优惠券审核详情 | 
|      */ | 
|     @RequestMapping(value = "/couponExaminePage/{id}") | 
|     public String couponExaminePage(@PathVariable Integer id, Model model){ | 
|         model.addAttribute("id",id); | 
|         return PREFIX + "TCouponExamine.html"; | 
|     } | 
|   | 
|   | 
|   | 
|     @RequestMapping(value = "/examine") | 
|     @ResponseBody | 
|     public Object examine(Integer id, Integer state, String remark) { | 
|         Coupon coupon = client.queryCouponById(id); | 
|         try { | 
|             if (state == 2) { | 
|                 coupon.setAuditStatus(2); | 
|             } | 
|             if (state == 3) { | 
|                 coupon.setAuditStatus(3); | 
|                 coupon.setAuditRemark(remark); | 
|             } | 
|             client.updateCouponData(coupon); | 
|             return SUCCESS_TIP; | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ERROR; | 
|         } | 
|     } | 
|   | 
| } |