Pu Zhibing
2024-09-23 e49f212c5ae9c5382386ddc0d34e346799720116
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package com.ruoyi.shop.controller.console;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.shop.domain.pojo.shop.*;
import com.ruoyi.shop.service.shop.*;
import com.ruoyi.shop.service.task.MemberTaskService;
import com.ruoyi.shop.service.task.ShopTaskService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.dto.*;
import com.ruoyi.system.api.domain.poji.shop.Shop;
import com.ruoyi.system.api.domain.vo.ShopProportionVo;
import com.ruoyi.system.api.domain.poji.sys.SysUser;
import com.ruoyi.system.api.domain.vo.*;
import com.ruoyi.system.api.model.QwH5LoginVo;
import com.ruoyi.system.api.model.QwUserDetailDto;
import com.ruoyi.system.api.service.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * @author jqs34
 * @ClassName ShopController
 * @description: TODO
 * @date 2023年05月03日
 * @version: 1.0
 */
@RestController
@RequestMapping("/shop")
public class ShopController {
 
    @Resource
    private ShopService shopService;
 
    @Resource
    private ShopRelUserService shopRelUserService;
 
    @Resource
    private ShopStaffService shopStaffService;
 
    @Resource
    private RemoteUserService remoteUserService;
 
    @Resource
    private ShopSuggestService shopSuggestService;
 
    @Resource
    private ShopTaskService shopTaskService;
 
    @Resource
    private ShopTotalService shopTotalService;
 
    @Resource
    private MemberTaskService memberTaskService;
 
    @Resource
    private ShopAuthenticationService shopAuthenticationService;
 
    @Resource
    private ShopProportionService shopProportionService;
 
    @Resource
    private RedisService redisService;
 
    @Autowired
    private ShopAuthenticationHftxService shopAuthenticationHftxService;
 
    @PostMapping("/getShopIdsByUserIds")
    public R<List<Long>> getShopIdsByUserIds(@RequestBody List<Long> userIds)
    {
        // 店铺ids
        List<Long> list = shopService.list(new QueryWrapper<Shop>()
                .in("belong_user_id", userIds)
                .eq("del_flag", 0))
                .stream().map(Shop::getShopId).collect(Collectors.toList());
        return R.ok(list);
    }
 
    /**
     * 企业微信H5登录
     * @param qwUserDetail
     * @return
     */
    @PostMapping("/qwH5Login")
    public R<QwH5LoginVo> qwH5Login(@RequestBody QwUserDetailDto qwUserDetail)
    {
        String mobile = qwUserDetail.getMobile();
        ShopStaff shopStaff = null;
        if(StringUtils.isNotEmpty(mobile)){
            shopStaff = shopStaffService.getByMobile(mobile);
        }else{
            shopStaff = shopStaffService.getOne(new QueryWrapper<ShopStaff>().eq("del_flag", 0)
                    .eq("user_id", qwUserDetail.getUserid()));
        }
        if(shopStaff==null){
            throw new ServiceException(AppErrorConstant.USER_NO_SHOP);
        }
        Long userId = shopStaff.getUserId();
        SysUser sysUser = remoteUserService.getSysUser(userId).getData();
        Optional.ofNullable(sysUser).orElseThrow(() -> new ServiceException("登录失败,未查询到用户"));
        Shop shop = shopService.getByShopId(shopStaff.getShopId());
        if(shop.getFrozenFlag()==1){
            String userKey = SecurityUtils.getUserKey();
            redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY+userKey);
            throw new ServiceException("商户已被冻结,请联系管理员",401);
        }
        // 构造登录返回信息
        QwH5LoginVo qwH5LoginVo = new QwH5LoginVo();
        qwH5LoginVo.setUserid(qwUserDetail.getUserid());
        qwH5LoginVo.setMobile(qwUserDetail.getMobile());
        qwH5LoginVo.setSysUser(sysUser);
        return R.ok(qwH5LoginVo);
    }
 
    @PostMapping("/getShop")
    public R<Shop> getShop(@RequestBody Long shopId)
    {
        Shop shop = shopService.getByShopId(shopId);
        return R.ok(shop);
    }
 
    @PostMapping("/getShopSubMchId")
    public R<String> getShopSubMchId(@RequestBody Long shopId){
        String subMchid = "";
        ShopAuthentication authentication = shopAuthenticationService.getByShopId(shopId);
        if(null != authentication){
            subMchid = authentication.getSubMchid();
        }
        return R.ok(subMchid, "");
    }
 
 
    @PostMapping("/getShopHFTXSubMchId")
    public R<ShopAuthenticationHftxVo> getShopHFTXSubMchId(@RequestBody Long shopId){
        ShopAuthenticationHftx shopAuthenticationHftx = shopAuthenticationHftxService.getOne(new QueryWrapper<ShopAuthenticationHftx>()
                .eq("is_delete", 0).eq("shop_id", shopId));
        ShopAuthenticationHftxVo vo = new ShopAuthenticationHftxVo();
        BeanUtils.copyProperties(shopAuthenticationHftx, vo);
        return R.ok(vo, "");
    }
 
 
 
    /**
     * 获取商户分成
     * @param shopId
     * @return
     */
    @PostMapping("/getShopProportion")
    public R<ShopProportionVo> getShopProportion(@RequestBody Long shopId){
        ShopProportion shopProportion = shopProportionService.getByShopId(shopId);
 
        ShopProportionVo shopProportionVo = new ShopProportionVo();
        BeanUtils.copyBeanProp(shopProportionVo, shopProportion);
        return R.ok(shopProportionVo);
    }
 
    @PostMapping("/getShopByUserId")
    public R<ShopRelUserVo> getShopByUserId(@RequestBody Long userId)
    {
        ShopRelUser shopRelUser = shopRelUserService.getByUserId(userId);
        Optional.ofNullable(shopRelUser).orElseThrow(() -> new ServiceException("未查询到用户关联商户"));
        ShopRelUserVo shopRelUserVo = new ShopRelUserVo();
        shopRelUserVo.setShopId(shopRelUser.getShopId());
        shopRelUserVo.setUserName(shopRelUser.getUserName());
        return R.ok(shopRelUserVo);
    }
 
    @PostMapping("/getShopByBelongUserId")
    public R<ShopRelUserVo> getShopByBelongUserId(@RequestBody Long userId)
    {
        List<Shop> shopList = shopService.getShopByBelongUserId(userId);
        Optional.ofNullable(shopList.get(0)).orElseThrow(() -> new ServiceException("未查询到商户信息"));
        ShopRelUserVo shopRelUserVo = new ShopRelUserVo();
        shopRelUserVo.setShopId(shopList.get(0).getShopId());
        return R.ok(shopRelUserVo);
    }
 
    /**
     * @description  删除商户标签
     * @author  jqs
     * @date    2023/6/8 15:52
     * @param tag
     * @return  R
     */
    @PostMapping("/deleteShopTag")
    public R deleteShopTag(@RequestBody String tag)
    {
        shopService.deleteShopTag(tag);
        return R.ok();
    }
 
    /**
     * @description
     * @author  jqs
     * @date    2023/6/9 10:18
     * @param suggestTag
     * @return  R
     */
    @PostMapping("/deleteShopSuggestTag")
    public R deleteShopSuggestTag(@RequestBody String suggestTag)
    {
        shopSuggestService.deleteShopSuggestTag(suggestTag);
        return R.ok();
    }
 
    /**
     * @description  通过区域代码获取shopId
     * @author  jqs
     * @date    2023/6/21 15:50
     * @param mgtShopIdByCodeDto
     * @return  R<MgtShopIdByCodeVo>
     */
    @PostMapping("/getShopIdByCode")
    public R<MgtShopIdByCodeVo> getShopIdByCode(@RequestBody MgtShopIdByCodeDto mgtShopIdByCodeDto)
    {
        MgtShopIdByCodeVo mgtShopIdByCodeVo = shopService.getShopIdByCode(mgtShopIdByCodeDto);
        return R.ok(mgtShopIdByCodeVo);
    }
 
    /**
     * @description  通过id获取商户简易信息list
     * @author  jqs
     * @date    2023/6/21 15:50
     * @param mgtBaseBathDto
     * @return  R<List<MgtSimpleShopVo>>
     */
    @PostMapping("/listShopSimpleVoByIds")
    public R<List<MgtSimpleShopVo>> listShopSimpleVoByIds(@RequestBody MgtBaseBathDto mgtBaseBathDto)
    {
        List<MgtSimpleShopVo> mgtShopListSimpleVos = shopService.listShopSimpleVoByIds(mgtBaseBathDto.getIds());
        return R.ok(mgtShopListSimpleVos);
    }
 
    /**
     * @description boardShopTotal
     * @param
     * @return R<MgtBulletinBoardVo>
     * @author jqs34
     * @date 2023/6/18 16:45
     */
    @PostMapping("/boardShopTotal")
    public R<MgtBulletinBoardVo> boardShopTotal(@RequestBody BoardMemberTotalDto boardMemberTotalDto)
    {
        MgtBulletinBoardVo bulletinBoardVo = new MgtBulletinBoardVo();
        MgtBulletinBoardVo bulletinBoardVoShop = shopService.boardShopTotal(boardMemberTotalDto.getUserIds());
        MgtBulletinBoardVo bulletinBoardVoTask = shopTaskService.boardTaskTotal(boardMemberTotalDto.getUserIds());
        bulletinBoardVo.setShopTotal(bulletinBoardVoShop.getShopTotal());
        bulletinBoardVo.setDealerTotal(bulletinBoardVoShop.getDealerTotal());
        bulletinBoardVo.setAgencyTotal(bulletinBoardVoShop.getAgencyTotal());
        bulletinBoardVo.setFollowShopToday(bulletinBoardVoTask.getFollowShopToday());
        return R.ok(bulletinBoardVo);
    }
 
    /**
    * @description 获取平台统计shopId
    * @param mgtBasePlatformDto
    * @return R<List<Long>>
    * @author jqs34
    * @date 2023/6/23 14:14
    */
    @PostMapping("/listShopIdByPlTotal")
    public R<List<Long>> listShopIdByPlTotal(@RequestBody MgtBasePlatformDto mgtBasePlatformDto)
    {
        List<Long> shopIdList = shopService.listShopIdByPlTotal(mgtBasePlatformDto);
        return R.ok(shopIdList);
    }
 
 
    /**
     * @description  更新商户统计
     * @author  jqs
     * @date    2023/6/28 17:52
     * @param shopTotalChangeDto
     * @return  R
     */
    @PostMapping("/changeShopTotal")
    public R changeShopTotal(@RequestBody ShopTotalChangeDto shopTotalChangeDto)
    {
        shopTotalService.changeShopTotal(shopTotalChangeDto);
        return R.ok();
    }
 
    /**
     * @description  获取最近任务
     * @author  jqs
     * @date    2023/6/29 18:25
     * @param userId
     * @return  R<MemberTaskSimpleVo>
     */
    @PostMapping("/getLastMemberTask")
    public R<MemberTaskSimpleVo> getLastMemberTask(@RequestBody Long userId)
    {
        MemberTaskSimpleVo taskSimpleVo = memberTaskService.getLastMemberTask(userId);
        return R.ok(taskSimpleVo);
    }
 
    /**
     * @description  获取商户下属代理商
     * @author  jqs
     * @date    2023/7/3 17:26
     * @return  R<List<Long>>
     */
    @PostMapping("/listShopIdByShopId")
    public R<List<Long>> listShopIdByShopId(@RequestBody Long shopId)
    {
        List<Long> shopIdList = shopService.listShopIdByShopId(shopId);
        return R.ok(shopIdList);
    }
 
    /**
     * @description  获取未回复数量
     * @author  jqs
     * @date    2023/7/5 12:49
     * @param
     * @return  R<Integer>
     */
    @PostMapping("/getUnReplaySuggestVo")
    public R<Integer> getUnReplaySuggestVo()
    {
        Integer count = shopSuggestService.getUnReplaySuggestVo();
        return R.ok(count);
    }
 
    /**
     * @description  获取商户营销状态
     * @author  jqs
     * @date    2023/7/7 14:05
     * @param shopId
     * @return  R<Integer>
     */
    @PostMapping("/getShopMarketingStatus")
    public R<Integer> getShopMarketingStatus(@RequestBody Long shopId)
    {
        Shop shop = shopService.getByShopId(shopId);
        Integer platformCouponFlag = shop.getPlatformCouponFlag();
        Integer platformBirthdayFlag = shop.getPlatformBirthdayFlag();
        Integer marketingStatus = 0;
        if(platformCouponFlag==1&&platformBirthdayFlag==2){
            marketingStatus = 1;
        }else if(platformCouponFlag==2&&platformBirthdayFlag==1){
            marketingStatus = 2;
        }else if(platformCouponFlag==1&&platformBirthdayFlag==1){
            marketingStatus = 3;
        }
        return R.ok(marketingStatus);
    }
 
    /**
     * @description  修改商户员工
     * @author  jqs
     * @date    2023/7/19 19:02
     * @param mgtShopStaffEditDto
     * @return  R
     */
    @PostMapping("/editMgtShopStaff")
    public R editMgtShopStaff(@RequestBody MgtShopStaffEditDto mgtShopStaffEditDto)
    {
        shopStaffService.editMgtShopStaff(mgtShopStaffEditDto);
        return R.ok();
    }
 
    /**
     * @description
     * @author  jqs
     * @date    2023/8/10 23:01
     * @param cityCodes
     * @return  R<List<Long>>
     */
    @PostMapping("/listShopIdByCityCode")
    R<List<Long>> listShopIdByCityCode(@RequestBody List<String> cityCodes){
        List<Long> shopIdList = shopService.listShopIdByCityCode(cityCodes);
        return R.ok(shopIdList);
    }
 
    @PostMapping("/authShop")
    R authShop(){
        shopService.authShop();
        return R.ok();
    }
 
    /**
     * @description  获取今日任务通知列表
     * @author  jqs
     * @date    2023/8/29 15:03
     * @param
     * @return  R<List<MgtUserTaskMsgVo>>
     */
    @PostMapping("/getTaskMsgList")
    R<List<MgtUserTaskMsgVo>> getTaskMsgList(){
        List<MgtUserTaskMsgVo> userTaskMsgVoList = shopService.getTaskMsgList();
        return R.ok(userTaskMsgVoList);
    }
 
 
 
    /**
     * @description
     * @author  jqs
     * @date    2023/8/10 23:01
     * @param cityCodes
     * @return  R<List<Long>>
     */
    @PostMapping("/listShopByCityCode")
    public R<List<Shop>> listShopByCityCode(@RequestBody List<String> cityCodes){
        List<Shop> shopIdList = shopService.listShopByCityCode(cityCodes);
        return R.ok(shopIdList);
    }
 
 
    /**
     * @description
     * @author  jqs
     * @date    2023/8/10 23:01
     * @return  R<List<Long>>
     */
    @PostMapping("/listShopByIds")
    public R<List<Shop>> listShopByIds(@RequestBody List<String> ids){
        List<Shop> shopIdList = shopService.listByIds(ids);
        return R.ok(shopIdList);
    }
 
 
    /**
     * 根据管理员id获取门店
     * @return
     */
    @PostMapping("/getShopBySysUserIds")
    public List<Shop> getShopBySysUserIds(@RequestBody BoardMemberTotalDto boardMemberTotalDto){
        return shopService.getShopBySysUserIds(boardMemberTotalDto.getUserIds());
    }
}