yanghb
2023-04-06 4f406ca4ce377c3bab7ef622496af73e1076dc71
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
238
239
240
241
242
243
package com.stylefeng.guns.modular.api;
 
import com.stylefeng.guns.modular.system.service.IMerchantActivityService;
import com.stylefeng.guns.modular.system.service.IMerchantService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.service.IUserMerchantCouponService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
 
/**
* 商家
* @author pzb
* @Date 2022/2/8 10:49
*/
@RestController
@RequestMapping("/api/merchant")
public class MerchantController {
 
    @Autowired
    private IMerchantService merchantService;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private IMerchantActivityService merchantActivityService;
 
    @Autowired
    private IUserMerchantCouponService userMerchantCouponService;
 
 
 
    @ResponseBody
    @PostMapping("/registeredMerchant")
    @ApiOperation(value = "1.0-提交商家申请", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商家名称", name = "name", required = true, dataType = "string"),
            @ApiImplicitParam(value = "商家头像", name = "headImg", required = true, dataType = "string"),
            @ApiImplicitParam(value = "联系人姓名", name = "contactName", required = true, dataType = "string"),
            @ApiImplicitParam(value = "联系人电话", name = "contactPhone", required = true, dataType = "string"),
            @ApiImplicitParam(value = "营业地址", name = "address", required = true, dataType = "string"),
            @ApiImplicitParam(value = "营业执照", name = "businessLicense", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil registeredMerchant(String name, String headImg, String contactName, String contactPhone, String address, String businessLicense, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return merchantService.registeredMerchant(uid, name, headImg, contactName, contactPhone, address, businessLicense);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/getMerchant")
    @ApiOperation(value = "1.0-获取商家信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<MerchantWapper> getMerchant(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            MerchantWapper merchant = merchantService.getMerchant(uid);
            return ResultUtil.success(merchant);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/getMerchantCoupon")
    @ApiOperation(value = "1.0-商家获取商家券列表", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数据类型(1=进行中,2=已结束)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<MerchantCouponListWarpper>> getMerchantCoupon(Integer type, Integer pageNum, Integer size, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<MerchantCouponListWarpper> merchantCoupon = merchantActivityService.getMerchantCoupon(uid, type, pageNum, size);
            return ResultUtil.success(merchantCoupon);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/getUserMerchantCoupon")
    @ApiOperation(value = "1.0-根据核销码获取优惠券详情", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "核销码", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<UserMerchantCouponWapper> getUserMerchantCoupon(String code, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userMerchantCouponService.getUserMerchantCoupon(uid, code);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    @ResponseBody
    @PostMapping("/writeOffMerchantCoupon")
    @ApiOperation(value = "1.0-核销优惠券操作", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "核销码", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil writeOffMerchantCoupon(String code, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userMerchantCouponService.writeOffMerchantCoupon(uid, code);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/getWriteOffHistory")
    @ApiOperation(value = "1.0-商家获取优惠券核销记录", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "活动id", name = "activityId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "优惠券id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<Map<String, Object>>> getWriteOffHistory(Integer activityId, Integer id, Integer pageNum, Integer size){
        try {
            List<Map<String, Object>> writeOffHistory = userMerchantCouponService.getWriteOffHistory(activityId, id, pageNum, size);
            return ResultUtil.success(writeOffHistory);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/getMyMerchantCoupon")
    @ApiOperation(value = "1.0-获取我的商家优惠券", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数据类型(1=正常,2=失效)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<MerchantCouponWarpper>> getMyMerchantCoupon(Integer type, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<MerchantCouponWarpper> myMerchantCoupon = userMerchantCouponService.getMyMerchantCoupon(uid, type);
            return ResultUtil.success(myMerchantCoupon);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/giveAwayMerchantCoupon")
    @ApiOperation(value = "1.0-订单完成后获取商家优惠券", tags = {"用户端-出租车", "用户端-专车", "用户端-跨城","用户端-小件物流"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "订单类型(1=专车/快车,2=出租车,3=机场专线,7=景区直通车,8=公务出行)", name = "orderType", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<MerchantCouponListWarpper>> giveAwayMerchantCoupon(Integer orderId, Integer orderType, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<MerchantCouponListWarpper> listWarppers = userMerchantCouponService.giveAwayMerchantCoupon(uid, orderId, orderType);
            return ResultUtil.success(listWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/gainMerchantCoupon")
    @ApiOperation(value = "1.0-首页获取商家券数据(仅跨城和小件物流)", tags = {"用户端-跨城","用户端-小件物流"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<MerchantCouponListWarpper>> gainMerchantCoupon(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<MerchantCouponListWarpper> merchantCoupon = userMerchantCouponService.getMerchantCoupon(uid);
            return ResultUtil.success(merchantCoupon);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}