| | |
| | | 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.CouponDataVo; |
| | | import com.dsh.guns.modular.system.model.Region; |
| | | import com.dsh.guns.modular.system.service.IRegionService; |
| | | import com.dsh.guns.modular.system.service.IStoreService; |
| | | 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.*; |
| | |
| | | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | @RequestMapping("/tCouponManage") |
| | | public class TCouponController { |
| | | |
| | | |
| | | |
| | | private String PREFIX = "/system/tCoupon/"; |
| | | |
| | | |
| | | @Resource |
| | | private IRegionService regiService; |
| | |
| | | @Resource |
| | | private CityManagerClient cmgrClient; |
| | | |
| | | |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | @Autowired |
| | | private IUserService userService; |
| | | @Autowired |
| | | private TOperatorService operatorService; |
| | | @Autowired |
| | | private TOperatorCityService operatorCityService; |
| | | |
| | | /** |
| | | * 跳转到优惠券管理首页 |
| | | */ |
| | | @RequestMapping("") |
| | | public String index(Model model) { |
| | | model.addAttribute("objectType",UserExt.getUser().getObjectType()); |
| | | return PREFIX + "TCoupon.html"; |
| | | } |
| | | |
| | |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | System.out.println(objectType); |
| | | model.addAttribute("userType",objectType); |
| | | return PREFIX + "TQuestionAdd.html"; |
| | | return PREFIX + "TCouponAdd.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){ |
| | | // 门店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("img",strings); |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | System.out.println(objectType); |
| | | model.addAttribute("item",coupon); |
| | | model.addAttribute("objectType",objectType); |
| | | return PREFIX + "TCouponInfo.html"; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @RequestMapping("/storeList") |
| | | public String storePage(Model model) { |
| | | return PREFIX + "TQuestionEdit.html"; |
| | | return PREFIX + "TStoreList.html"; |
| | | } |
| | | @RequestMapping("/updateType") |
| | | @ResponseBody |
| | | public Object updateType(Long id) { |
| | | client.updateType(id); |
| | | return new SuccessTip<>(); |
| | | } |
| | | |
| | | @RequestMapping("/storeDetailsOfSearch") |
| | | @ResponseBody |
| | | public Object listOfStore(Integer provinceId,Integer cityId,Integer cityManagerId,String storeName){ |
| | | System.out.println("provinceId"+provinceId); |
| | | System.out.println("cityId"+cityId); |
| | | System.out.println("cityManagerId"+cityManagerId); |
| | | System.out.println("storeName"+storeName); |
| | | String provinceCode = null; |
| | | String cityCode = null; |
| | | if (ToolUtil.isNotEmpty(provinceId)){ |
| | | Region provinceRegion = regiService.getById(provinceId); |
| | | provinceCode = provinceRegion.getCode(); |
| | | } |
| | | if (ToolUtil.isNotEmpty(cityId)){ |
| | | Region cityRegion = regiService.getById(cityId); |
| | | cityCode = cityRegion.getCode(); |
| | | public Object listOfStore(String provinceId,String cityId,Integer operatorId,String storeName){ |
| | | if (UserExt.getUser().getObjectType()== 2){ |
| | | // 筛选这个运营商下的门店 |
| | | operatorId = UserExt.getUser().getObjectId(); |
| | | } |
| | | Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(); |
| | | List<Map<String,Object>> storeList = storeService.queryListOfpage(provinceCode,cityCode,cityManagerId,storeName,page); |
| | | 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("cityManagerId"); |
| | | CityManager cityManager = cmgrClient.queryCityManagerById(managerId); |
| | | if (ToolUtil.isNotEmpty(cityManager)){ |
| | | stringObjectMap.put("accountName",cityManager.getName()+"+"+cityManager.getPhone()); |
| | | Integer managerId = (Integer) stringObjectMap.get("operatorId"); |
| | | if (managerId == null){ |
| | | stringObjectMap.put("accountName","平台"); |
| | | }else{ |
| | | 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; |
| | |
| | | ofSearch.setUserPopulation(userPopulation); |
| | | ofSearch.setStatus(status); |
| | | ofSearch.setState(state); |
| | | return client.getCouponListOfSearch(ofSearch); |
| | | if (UserExt.getUser().getObjectType()==2) { |
| | | // 门店ids |
| | | List<Integer> storeIds = storeService.list(new QueryWrapper<TStore>().eq("operatorId", UserExt.getUser().getObjectId())) |
| | | .stream().map(TStore::getId).collect(Collectors.toList()); |
| | | ofSearch.setStoreIds(storeIds); |
| | | ofSearch.setObjType(UserExt.getUser().getObjectType()); |
| | | ofSearch.setOperatorId(UserExt.getUser().getObjectId()); |
| | | // 查询当前门店属于哪个运营商 |
| | | List<TOperatorCity> operatorId = operatorCityService.list(new QueryWrapper<TOperatorCity>().eq("operatorId", UserExt.getUser().getObjectId())); |
| | | ofSearch.setOperatorCities(operatorId); |
| | | } |
| | | if (UserExt.getUser().getObjectType()==3) { |
| | | ofSearch.setStoreId(UserExt.getUser().getObjectId()); |
| | | ofSearch.setObjType(UserExt.getUser().getObjectType()); |
| | | } |
| | | // 运营商可以查看平台添加的优惠券应只展示使用范围为全国通用、 |
| | | // 指定城市有运营商管辖的、指定门店有运营商旗下门店 |
| | | List<Map<String, Object>> couponListOfSearch = client.getCouponListOfSearch(ofSearch); |
| | | |
| | | return couponListOfSearch; |
| | | } |
| | | /** |
| | | * 根据运营商ID 获取运营商管理的省市 |
| | | */ |
| | | |
| | | /** |
| | | * 获取 优惠券管理 |
| | | */ |
| | | @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); |
| | | ofSearch.setObjType(UserExt.getUser().getObjectType()); |
| | | ofSearch.setOperatorId(UserExt.getUser().getObjectId()); |
| | | return client.getCouponListOfSearch1(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") |
| | |
| | | .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<>(); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/getCity") |
| | | @ResponseBody |
| | |
| | | return regiService.list(new LambdaQueryWrapper<Region>() |
| | | .eq(Region::getParentId,province)); |
| | | } |
| | | @RequestMapping(value = "/getCity1") |
| | | @ResponseBody |
| | | public Object getCity1(String province){ |
| | | // 获取省的id |
| | | Integer code = regiService.getOne(new QueryWrapper<Region>().eq("code", province)).getId(); |
| | | return regiService.list(new LambdaQueryWrapper<Region>() |
| | | .eq(Region::getParentId,code)); |
| | | } |
| | | // 通过市 获取运营商 |
| | | @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"); |
| | |
| | | //文件大小(字节数) |
| | | map.put("size", imgFile.getSize() + ""); |
| | | System.out.println(map); |
| | | return url; |
| | | return url; |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | System.out.println(dataVo); |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | dataVo.setUserType(objectType); |
| | | dataVo.setCityManagerId(UserExt.getUser().getObjectId()); |
| | | if(UserExt.getUser().getObjectType()==2){ |
| | | dataVo.setCompany(3); |
| | | dataVo.setUserType(2); |
| | | dataVo.setCityManagerId(UserExt.getUser().getObjectId()); |
| | | }else if(UserExt.getUser().getObjectType()==3){ |
| | | dataVo.setStoreIds(UserExt.getUser().getObjectId().toString()); |
| | | dataVo.setCompany(3); |
| | | dataVo.setUserType(3); |
| | | }else{ |
| | | dataVo.setUserType(1); |
| | | } |
| | | dataVo.setObjType(UserExt.getUser().getObjectType()); |
| | | 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); |
| | | if (UserExt.getUser().getObjectType()==3) { |
| | | coupon.setAuditStatus(1); |
| | | } |
| | | client.updateCouponData(coupon); |
| | | return new SuccessTip<>(); |
| | | } |
| | | } |