Pu Zhibing
2025-03-26 7f26677ab7f9b83697370fa142dd1686cdf4082a
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
package com.ruoyi.other.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Phone;
import com.ruoyi.other.enums.PhoneType;
import com.ruoyi.other.service.PhoneService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@RestController
@RequestMapping("/phone")
@Api("手机")
public class PhoneController extends BaseController {
    @Resource
    private PhoneService phoneService;
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private SysUserClient sysUserClient;
    
    
    
 
    /**
     * 查询指定门店手机号
     */
    @GetMapping("/selectPhoneByShopId")
    @ApiOperation(value = "查询指定门店手机号", tags = {"小程序-首页-门店详情"})
    public R<Phone> getPhoneByShopId(@ApiParam("门店id") @RequestParam Integer shopId) {
        Phone list = phoneService.getOne(new LambdaQueryWrapper<Phone>()
                .eq(Phone::getType, PhoneType.SHOP.getCode())
                .eq(Phone::getShopId, shopId));
        return R.ok(list);
    }
    
    
    
    @GetMapping("/getSysPhone")
    @ApiOperation(value = "获取客服电话", tags = {"管理后台-客服电话", "门店后台-客服电话"})
    public R<Phone> getSysPhone(){
        Long userId = tokenService.getLoginUser().getSysUser().getUserId();
        SysUser sysUser = sysUserClient.getSysUser(userId).getData();
        LambdaQueryWrapper<Phone> wrapper = new LambdaQueryWrapper<>();
        if(sysUser.getRoleType() == 1){
            wrapper.eq(Phone::getType, 1);
        }else{
            wrapper.eq(Phone::getType, 2).eq(Phone::getShopId, sysUser.getObjectId());
        }
        Phone one = phoneService.getOne(wrapper);
        return R.ok(one);
    }
    
    
    
    @PostMapping("/savePhone")
    @ApiOperation(value = "保存客服电话", tags = {"管理后台-客服电话", "门店后台-客服电话"})
    public R savePhone(@RequestBody Phone phone){
        Long userId = tokenService.getLoginUser().getSysUser().getUserId();
        SysUser sysUser = sysUserClient.getSysUser(userId).getData();
        //平台配置
        if(sysUser.getRoleType() == 1){
            Phone one = phoneService.getOne(new LambdaQueryWrapper<Phone>().eq(Phone::getType, 1));
            if(null != one){
                one.setPhoneOne(phone.getPhoneOne());
                one.setPhoneTwo(phone.getPhoneTwo());
                phoneService.updateById(one);
            }else{
                phone.setType(1);
                phoneService.save(phone);
            }
        }else{
            //门店配置
            Phone one = phoneService.getOne(new LambdaQueryWrapper<Phone>().eq(Phone::getType, 2).eq(Phone::getShopId, sysUser.getObjectId()));
            if(null != one){
                one.setPhoneOne(phone.getPhoneOne());
                one.setPhoneTwo(phone.getPhoneTwo());
                phoneService.updateById(one);
            }else{
                phone.setType(2);
                phone.setShopId(sysUser.getObjectId());
                phoneService.save(phone);
            }
        }
        return R.ok();
    }
    
}