Pu Zhibing
4 天以前 890c290afef9faca8ddaf0fea6197c3daa472141
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
package com.ruoyi.shop.controller.business;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.shop.domain.dto.*;
import com.ruoyi.shop.domain.pojo.shop.ShopRelUser;
import com.ruoyi.shop.domain.vo.*;
import com.ruoyi.shop.service.shop.*;
import com.ruoyi.system.api.domain.dto.MerBaseDto;
import com.ruoyi.system.api.domain.dto.MerBaseGetDto;
import com.ruoyi.system.api.domain.dto.MerEditUserDto;
import com.ruoyi.system.api.domain.dto.MerPageDto;
import com.ruoyi.system.api.domain.poji.shop.Shop;
import com.ruoyi.system.api.domain.poji.shop.ShopAppointableTime;
import com.ruoyi.system.api.domain.poji.shop.ShopNonAppointableTime;
import com.ruoyi.system.api.domain.vo.MerHomeShopTotalVo;
import com.ruoyi.system.api.domain.vo.MerStaffInfoVo;
import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author jqs34
 * @ClassName BShopController
 * @description: TODO
 * @date 2023年05月04日
 * @version: 1.0
 */
@Api(value = "商户端商户相关接口", tags = "商户端商户相关接口", description = "商户端商户相关接口")
@RestController
@RequestMapping("/mer/shop")
public class MerShopController {
 
 
    @Resource
    private ShopService shopService;
 
    @Resource
    private ShopCertificateService shopCertificateService;
    
    @Resource
    private ShopStaffService shopStaffService;
    
    @Resource
    private ShopRelUserService shopRelUserService;
    
    @Resource
    private ShopSuggestService shopSuggestService;
    
    @Resource
    private ShopNonAppointableTimeService shopNonAppointableTimeService;
    
    @Resource
    private ShopAppointableTimeService shopAppointableTimeService;
    
    
    /**
     * 未完成实际统计
     *
     * @param merBaseDto
     * @return
     */
    @RequestMapping(value = "/getMerHomeTotal", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户端商业统计【2.0】")
    public R<MerHomeShopTotalVo> getMerHomeTotal(@RequestBody MerBaseDto merBaseDto) {
        Long userId = SecurityUtils.getUserId();
        merBaseDto.setUserId(userId);
        MerHomeShopTotalVo merHomeShopTotalVo = shopService.getMerHomeTotal(merBaseDto);
        return R.ok(merHomeShopTotalVo);
    }
 
    @RequestMapping(value = "/pageMerAgency", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取商户加盟商列表")
    public R<Page<MerAgencyPageVo>> pageMerAgency(@RequestBody MerAgencyPageDto merAgencyPageDto) {
        Long userId = SecurityUtils.getUserId();
        merAgencyPageDto.setUserId(userId);
        Page<MerAgencyPageVo> page = new Page<>();
        page.setSize(merAgencyPageDto.getPageSize());
        page.setCurrent(merAgencyPageDto.getPageNum());
        List<MerAgencyPageVo> merAgencyPageVoList = shopService.pageMerAgencyVo(page,merAgencyPageDto);
        return R.ok(page.setRecords(merAgencyPageVoList));
    }
 
    @RequestMapping(value = "/listShopCertificate", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户证书列表")
    public R<List<MerShopCertificateListVo>> listShopCertificate(@RequestBody MerShopCertificateListDto merShopCertificateListDto) {
        Long userId = SecurityUtils.getUserId();
        List<MerShopCertificateListVo> merShopCertificateListVoList = shopCertificateService.listShopCertificateVo(merShopCertificateListDto);
        return R.ok(merShopCertificateListVoList);
    }
 
    @RequestMapping(value = "/editShopCertificate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑商户证书")
    public R editShopCertificate(@RequestBody MerShopCertificateEditDto merShopCertificateEditDto) {
        Long userId = SecurityUtils.getUserId();
        shopCertificateService.editShopCertificate(merShopCertificateEditDto);
        return R.ok();
    }
 
    @RequestMapping(value = "/deleteShopCertificate", method = RequestMethod.POST)
    @ApiOperation(value = "删除商户证书")
    public R deleteShopCertificate(@RequestBody MerBaseGetDto merBaseGetDto) {
        Long userId = SecurityUtils.getUserId();
        shopCertificateService.deleteShopCertificate(Long.valueOf(merBaseGetDto.getId()));
        return R.ok();
    }
    
    @RequestMapping(value = "/getShopStaffInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取员工信息【2.0】")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前商户id", name = "shopId", required = true, dataType = "Long", paramType = "query")
    })
    public R<MerStaffInfoVo> getShopStaffInfo(@RequestParam("shopId") Long shopId) {
        Long userId = SecurityUtils.getUserId();
        Shop shop = shopService.getByShopId(shopId);
        MerStaffInfoVo merStaffInfoVo = shopStaffService.getShopStaffInfo(userId, shop);
        return R.ok(merStaffInfoVo);
    }
 
    @RequestMapping(value = "/editShopStaffInfo", method = RequestMethod.POST)
    @ApiOperation(value = "修改员工信息")
    public R editShopStaffInfo(@RequestBody MerEditUserDto merEditUserDto) {
        Long userId = SecurityUtils.getUserId();
        merEditUserDto.setUserId(userId);
        if(merEditUserDto.getEditType()!=5){
            shopStaffService.editShopStaffInfo(merEditUserDto);
        }else{
            Shop shop = shopService.getByShopId(merEditUserDto.getShopId());
            String editValue = merEditUserDto.getEditValue();
            String[] editArr = editValue.split("-");
            shop.setBusinessStartTime(editArr[0]);
            shop.setBusinessEndTime(editArr[1]);
            shopService.saveOrUpdate(shop);
        }
        return R.ok();
    }
 
 
 
    @RequestMapping(value = "/pageMerShopSuggest", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取商户建议")
    public R<Page<MerShopSuggestVo>> pageMerShopSuggest(@RequestBody MerPageDto merPageDto) {
        Long userId = SecurityUtils.getUserId();
        merPageDto.setUserId(userId);
        Page<MerShopSuggestVo> page = new Page<>();
        page.setSize(merPageDto.getPageSize());
        page.setCurrent(merPageDto.getPageNum());
        List<MerShopSuggestVo> merShopSuggestVoList = shopSuggestService.pageMerShopSuggest(page,merPageDto);
        return R.ok(page.setRecords(merShopSuggestVoList));
    }
 
    @RequestMapping(value = "/suggest", method = RequestMethod.POST)
    @ApiOperation(value = "建议")
    public R suggest(@RequestBody MerShopSuggestDto merShopSuggestDto) {
        Long userId = SecurityUtils.getUserId();
        merShopSuggestDto.setUserId(userId);
        shopSuggestService.suggest(merShopSuggestDto);
        return R.ok();
    }
    
    
    @RequestMapping(value = "/listShopByShop", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户下属代理商")
    public R<List<MgtSimpleShopVo>> listShopByShop(@RequestBody MerBaseDto merBaseDto) {
        List<MgtSimpleShopVo> mgtShopListSimpleVos = shopService.listShopByShop(merBaseDto.getShopId());
        return R.ok(mgtShopListSimpleVos);
    }
    
    
    @RequestMapping(value = "/getShopMerchantBasicDataSettlement", method = RequestMethod.POST)
    @ApiOperation(value = "获取提现记录(汇付天下)")
    public R<List<MerchantBasicdataSettlementVo>> getMerchantBasicDataSettlement(@Validated @RequestBody MerchantBasicdataSettlementDto mgtShopShareRatioSetDto) {
        return shopService.getMerchantBasicDataSettlement(mgtShopShareRatioSetDto);
    }
    
    @RequestMapping(value = "/getUserShopList", method = RequestMethod.POST)
    @ApiOperation(value = "获取切换门店列表【2.0】")
    public R<List<Shop>> getUserShopList() {
        List<ShopRelUser> shopRelUsers = shopRelUserService.getByUserId(SecurityUtils.getUserId());
        shopRelUsers.sort(Comparator.comparing(ShopRelUser::getIsDefault));
        List<Shop> collect = shopRelUsers.stream().map(shopRelUser -> {
            Shop shop = shopService.getById(shopRelUser.getShopId());
            return shop;
        }).collect(Collectors.toList());
        return R.ok(collect);
    }
    
    
    @RequestMapping(value = "/getShopReservationConfig/{shopId}", method = RequestMethod.POST)
    @ApiOperation(value = "获取门店预约管理配置【2.0】")
    public R<ShopReservationConfigVo> getShopReservationConfig(@PathVariable("shopId") Long shopId) {
        Shop shop = shopService.getById(shopId);
        Integer subscribe = shop.getSubscribe();
        ShopReservationConfigVo vo = new ShopReservationConfigVo();
        vo.setSubscribe(subscribe);
        List<ShopNonAppointableTime> list = shopNonAppointableTimeService.list(new LambdaQueryWrapper<ShopNonAppointableTime>().eq(ShopNonAppointableTime::getShopId, shopId)
                .orderByAsc(ShopNonAppointableTime::getNonAppointableStartTime));
        vo.setUnsubscribeTime(list.stream().map(shopNonAppointableTime -> {
            Map<String, String> map = new HashMap<>();
            String time = shopNonAppointableTime.getNonAppointableStartTime().format(DateTimeFormatter.ofPattern("MM月dd日 HH:mm")) + "-" + shopNonAppointableTime.getNonAppointableEndTime().format(DateTimeFormatter.ofPattern("HH:mm"));
            map.put("time", time);
            map.put("id", shopNonAppointableTime.getId());
            return map;
        }).collect(Collectors.toList()));
        return R.ok(vo);
    }
    
    @RequestMapping(value = "/addShopNonAppointableTime", method = RequestMethod.POST)
    @ApiOperation(value = "门店添加不可预约时间段【2.0】")
    public R addShopNonAppointableTime(@RequestBody ShopNonAppointableTimeDto dto) {
        ShopNonAppointableTime shopNonAppointableTime = new ShopNonAppointableTime();
        shopNonAppointableTime.setShopId(dto.getShopId());
        shopNonAppointableTime.setNonAppointableStartTime(dto.getNonAppointableStartTime());
        shopNonAppointableTime.setNonAppointableEndTime(dto.getNonAppointableEndTime());
        shopNonAppointableTimeService.save(shopNonAppointableTime);
        return R.ok();
    }
    
    
    @RequestMapping(value = "/switchAppointment/{shopId}/{subscribe}", method = RequestMethod.POST)
    @ApiOperation(value = "开关门店预约配置【2.0】")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "门店id", name = "shopId", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(value = "预约开关(0=关,1=开)", name = "subscribe", required = true, dataType = "Integer", paramType = "path")
    })
    public R switchAppointment(@PathVariable("shopId") Long shopId, @PathVariable("subscribe") Integer subscribe) {
        Shop shop = shopService.getById(shopId);
        shop.setSubscribe(subscribe);
        shopService.updateById(shop);
        return R.ok();
    }
    
    @RequestMapping(value = "/getShopAppointableTimeList", method = RequestMethod.POST)
    @ApiOperation(value = "商户获取预约列表【2.0】")
    public R<Page<ShopAppointableTimeListVo>> getShopAppointableTimeList(@RequestBody ShopAppointableTimeListDto dto) {
        Page<ShopAppointableTimeListVo> page = new Page<>();
        page.setSize(dto.getPageSize());
        page.setCurrent(dto.getPageNum());
        List<ShopAppointableTimeListVo> shopAppointableTimeList = shopAppointableTimeService.getShopAppointableTimeList(page, dto);
        return R.ok(page.setRecords(shopAppointableTimeList));
    }
    
    
    @RequestMapping(value = "/confirmReservation/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "商户确认预约【2.0】")
    public R confirmReservation(@PathVariable("id") String id) {
        ShopAppointableTime shopAppointableTime = shopAppointableTimeService.getById(id);
        if (null == shopAppointableTime) {
            return R.fail("预约不存在");
        }
        if (1 != shopAppointableTime.getStatus()) {
            return R.fail("确认预约失败");
        }
        shopAppointableTime.setStatus(2);
        shopAppointableTimeService.updateById(shopAppointableTime);
        return R.ok();
    }
    
    
    @RequestMapping(value = "/cancelReservation", method = RequestMethod.POST)
    @ApiOperation(value = "商户取消预约【2.0】")
    public R cancelReservation(@RequestBody CancelReservationDto dto) {
        ShopAppointableTime shopAppointableTime = shopAppointableTimeService.getById(dto.getId());
        if (null == shopAppointableTime) {
            return R.fail("预约不存在");
        }
        if (0 == shopAppointableTime.getStatus()) {
            return R.fail("不能重复操作");
        }
        shopAppointableTime.setStatus(0);
        shopAppointableTime.setReason(dto.getReason());
        shopAppointableTimeService.updateById(shopAppointableTime);
        return R.ok();
    }
}