huliguo
2025-04-18 34f741f39e22bf48df33321230380b40c23110c3
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
package com.ruoyi.account.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.AppUserShop;
import com.ruoyi.account.api.model.ApplyForAdmission;
import com.ruoyi.account.dto.ApplyForAdmissionDTO;
import com.ruoyi.account.dto.ApplyReviewDTO;
import com.ruoyi.account.mapper.AppUserMapper;
import com.ruoyi.account.mapper.ApplyForAdmissionMapper;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.AppUserShopService;
import com.ruoyi.account.service.UserApplyForAdmissionService;
import com.ruoyi.account.util.tencentMap.TencentMapUtil;
import com.ruoyi.account.vo.ApplyForAdmissionDetailVO;
import com.ruoyi.account.vo.ApplyForAdmissionListVO;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Phone;
import com.ruoyi.other.api.domain.Region;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.feignClient.PhoneClient;
import com.ruoyi.other.api.feignClient.RegionClient;
import com.ruoyi.other.api.feignClient.ShopClient;
import com.ruoyi.system.api.model.UserShop;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
 
@Slf4j
@Service
public class UserApplyForAdmissionServiceImpl extends ServiceImpl<ApplyForAdmissionMapper, ApplyForAdmission> implements UserApplyForAdmissionService {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private ApplyForAdmissionMapper userApplyForAdmissionMapper;
    @Autowired
    private AppUserService appUserService;
    @Resource
    private RegionClient regionClient;
    @Resource
    private ShopClient shopClient;
    @Resource
    private PhoneClient phoneClient;
 
    @Autowired
    private AppUserShopService appUserShopService;
 
 
    /**
     * 申请入驻
     */
    @Override
    public R apply(ApplyForAdmissionDTO applyForAdmissionDTO) {
        Long userid = tokenService.getLoginUserApplet().getUserid();
        AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1)
                .eq(AppUser::getPhone, applyForAdmissionDTO.getPhone()));
        if (appUser == null){
            return R.fail("该手机号未注册");
        }
        ApplyForAdmission applyForAdmission = new ApplyForAdmission();
        BeanUtils.copyProperties(applyForAdmissionDTO, applyForAdmission);
        applyForAdmission.setCreateTime(LocalDateTime.now());
        applyForAdmission.setApplyUserId(userid);
        applyForAdmission.setStatus(0);
 
 
        this.save(applyForAdmission);
        return R.ok();
    }
 
    /**
     * 查看
     */
    @Override
    public ApplyForAdmission read() {
        Long userid = tokenService.getLoginUserApplet().getUserid();
        return userApplyForAdmissionMapper
                .selectOne(new LambdaQueryWrapper<ApplyForAdmission>()
                        .eq(ApplyForAdmission::getApplyUserId, userid)
                        .orderByDesc(ApplyForAdmission::getCreateTime)  // 按申请日期降序
                        .last("LIMIT 1"));
    }
 
    @Override
    public IPage<ApplyForAdmissionListVO> getApplyList(Integer pageNum, Integer pageSize, String shopName, String shopManager, String phone, Integer status) {
        Page<ApplyForAdmissionListVO> page = new Page<>(pageNum, pageSize);
        return userApplyForAdmissionMapper.selectApplyList(page, shopName, shopManager, phone, status);
    }
 
    @Override
    public ApplyForAdmissionDetailVO getApplyDetail(Integer id) {
        ApplyForAdmission apply = userApplyForAdmissionMapper.selectById(id);
        if (apply == null) {
            throw new RuntimeException("申请记录不存在");
        }
 
        ApplyForAdmissionDetailVO detail = new ApplyForAdmissionDetailVO();
        BeanUtils.copyProperties(apply, detail);
        detail.setFullAddress(apply.getAddress() + apply.getDetailAddress());
        return detail;
    }
 
    @Override
    public void review(ApplyReviewDTO applyReviewDTO) {
        ApplyForAdmission apply = userApplyForAdmissionMapper.selectById(applyReviewDTO.getId());
        if (apply == null) {
            throw new RuntimeException("申请记录不存在");
        }
        if (apply.getStatus() != 0) {
            throw new RuntimeException("该记录已审核过");
        }
        if(applyReviewDTO.getStatus()==2){
            //审核不通过
            apply.setStatus(2);
            apply.setRemark(applyReviewDTO.getRemark());
            apply.setUpdateTime(LocalDateTime.now());
            this.updateById(apply);
            return;
        }
        //审核通过
        apply.setStatus(1);
        apply.setUpdateTime(LocalDateTime.now());
        this.updateById(apply);
 
        //先加入商店
        Shop shop = new Shop();
        BeanUtils.copyProperties(apply, shop);
        shop.setName(apply.getShopName());
        shop.setBusinessTime(apply.getBusinessTime());
        shop.setAppUserId(apply.getApplyUserId());
        shop.setCreateTime(LocalDateTime.now());
        R shopR = shopClient.insert(shop);
        if (shopR.getCode()!=200){
            throw new RuntimeException("添加店铺失败");
        }
        Integer shopId = (Integer) shopR.getData();
        //加入usershop
        AppUserShop userShop = new AppUserShop();
        userShop.setAppUserId(apply.getApplyUserId());
        userShop.setShopId(shopId);
        appUserShopService.save(userShop);
        //加入客服手机号
        Phone phone = new Phone();
        phone.setType(2);//门店
        phone.setPhoneOne(apply.getServiceTel());
        phone.setShopId(shop.getId());
        R phoneR = phoneClient.insert(phone);
        if (phoneR.getCode()!=200){
            throw new RuntimeException("添加店铺客服电话失败");
        }
 
 
    }
 
}