nickchange
2023-11-15 331ae50b1cdcb31a4a0c182abb82aec5c1b12f83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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);
        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 + "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;
        }
    }
 
}