Pu Zhibing
4 天以前 d6a0c57043e8cc20694a3c678bf8e3a8f28f6499
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
package com.ruoyi.shop.controller.miniapp;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.shop.domain.dto.AppNearbyShopDto;
import com.ruoyi.shop.domain.dto.MyAppointmentListDto;
import com.ruoyi.shop.domain.vo.AppNearbyShopVo;
import com.ruoyi.shop.domain.vo.AppShopInfoVo;
import com.ruoyi.shop.domain.vo.MyAppointmentListVo;
import com.ruoyi.shop.service.shop.ShopAppointableTimeService;
import com.ruoyi.shop.service.shop.ShopNonAppointableTimeService;
import com.ruoyi.shop.service.shop.ShopService;
import com.ruoyi.system.api.domain.dto.AppBaseGetDto;
import com.ruoyi.system.api.domain.dto.AppointmentTimeDto;
import com.ruoyi.system.api.domain.dto.ShopAppointmentTimeDto;
import com.ruoyi.system.api.domain.poji.member.Member;
import com.ruoyi.system.api.domain.poji.shop.ShopAppointableTime;
import com.ruoyi.system.api.domain.poji.shop.ShopNonAppointableTime;
import com.ruoyi.system.api.service.RemoteMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * @author jqs34
 * @ClassName AppHomeController
 * @description: TODO
 * @date 2023年04月18日
 * @version: 1.0
 */
@Api(value = "小程序首页相关接口", tags = "小程序首页相关接口", description = "小程序首页相关接口")
@RestController
@RequestMapping("/app/home")
@Log4j2
public class AppHomeController {
    
    @Resource
    private RemoteMemberService memberService;
    
    @Resource
    private ShopService shopService;
    
    @Resource
    private ShopNonAppointableTimeService shopNonAppointableTimeService;
    
    @Resource
    private ShopAppointableTimeService shopAppointableTimeService;
    
    
    @RequestMapping(value = "/getNearbyShop", method = RequestMethod.POST)
    @ApiOperation(value = "获取最近商户")
    public R<AppNearbyShopVo> getNearbyShop(@RequestBody AppNearbyShopDto appNearbyShopDto) {
        Long userId = SecurityUtils.getUserId();
        Member member = null;
        if (userId != null) {
            member = memberService.getMember(userId).getData();
        }
        log.info("获取最近商户:userId=" + userId + "&appNearbyShopDto=" + JSON.toJSONString(appNearbyShopDto));
        appNearbyShopDto.setUserId(userId);
        AppNearbyShopVo appNearbyShopVo = shopService.getNearbyShop(appNearbyShopDto,member);
        return R.ok(appNearbyShopVo);
    }
    
    
    @RequestMapping(value = "/getShopInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户详情")
    public R<AppShopInfoVo> getShopInfo(@RequestBody AppBaseGetDto appBaseGetDto) {
        AppShopInfoVo appShopInfoVo = shopService.getAppShopInfo(Long.valueOf(appBaseGetDto.getId()));
        return R.ok(appShopInfoVo);
    }
    
    @RequestMapping(value = "/getShopAppointmentTime", method = RequestMethod.POST)
    @ApiOperation(value = "获取商户不可预约时间段【2.0】")
    public R<List<ShopNonAppointableTime>> getShopAppointmentTime(@RequestBody ShopAppointmentTimeDto dto) {
        List<ShopNonAppointableTime> list = shopNonAppointableTimeService.list(new QueryWrapper<ShopNonAppointableTime>().eq("shop_id", dto.getId())
                .last(" and '" + dto.getDate() + "' like CONCAT('%', non_appointable_start_time, '%') order by non_appointable_start_time"));
        return R.ok(list);
    }
    
    @RequestMapping(value = "/appointmentTime", method = RequestMethod.POST)
    @ApiOperation(value = "门店详情预约操作【2.0】")
    public R appointmentTime(@RequestBody AppointmentTimeDto dto) {
        ShopAppointableTime one = shopAppointableTimeService.getOne(new LambdaQueryWrapper<ShopAppointableTime>().eq(ShopAppointableTime::getShopId, dto.getShopId())
                .eq(ShopAppointableTime::getAppointableTime, dto.getTime()));
        if (null != one) {
            return R.fail("不能重复预约");
        }
        Long userId = SecurityUtils.getUserId();
        one = new ShopAppointableTime();
        one.setShopId(dto.getShopId());
        one.setAppointableTime(dto.getTime());
        one.setUserId(userId);
        one.setStatus(1);
        one.setCreateTime(LocalDateTime.now());
        shopAppointableTimeService.save(one);
        return R.ok();
    }
    
    @RequestMapping(value = "/getMyAppointmentList", method = RequestMethod.POST)
    @ApiOperation(value = "获取我的预约列表【2.0】")
    public R<Page<MyAppointmentListVo>> getMyAppointmentList(@RequestBody MyAppointmentListDto dto) {
        Page<MyAppointmentListVo> page = new Page<>();
        page.setSize(dto.getPageSize());
        page.setCurrent(dto.getPageNum());
        List<MyAppointmentListVo> myAppointmentListVos = shopAppointableTimeService.pageMyAppointmentList(page, dto);
        return R.ok(page.setRecords(myAppointmentListVos));
    }
    
    
    @RequestMapping(value = "/cancelAppointmentTime/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "取消预约【2.0】")
    public R cancelAppointmentTime(@PathVariable("id") String id) {
        Long userId = SecurityUtils.getUserId();
        ShopAppointableTime one = shopAppointableTimeService.getById(id);
        if (null == one) {
            return R.fail("预约不存在");
        }
        if (!one.getUserId().equals(userId)) {
            return R.fail("不能取消别人的预约");
        }
        one.setStatus(0);
        shopAppointableTimeService.updateById(one);
        return R.ok();
    }
}