| | |
| | | package com.ruoyi.shop.controller.miniapp; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.member.domain.pojo.member.Member; |
| | | import com.ruoyi.member.service.member.MemberService; |
| | | import com.ruoyi.system.service.config.AdvertService; |
| | | import com.ruoyi.system.service.config.BannerService; |
| | | import com.ruoyi.system.service.config.QuickEntryService; |
| | | import com.ruoyi.system.service.goods.GoodsService; |
| | | import com.ruoyi.system.service.shop.ShopService; |
| | | import com.ruoyi.shop.domain.dto.AppNearbyShopDto; |
| | | import com.ruoyi.shop.domain.vo.AppNearbyShopVo; |
| | | import com.ruoyi.shop.domain.vo.AppShopInfoVo; |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Api(value = "小程序首页相关接口", tags = "小程序首页相关接口", description = "小程序首页相关接口") |
| | | @RestController |
| | | @RequestMapping("/app/home") |
| | | @Log4j2 |
| | | public class AppHomeController { |
| | | |
| | | |
| | | @Autowired |
| | | private MemberService memberService; |
| | | |
| | | @Autowired |
| | | private BannerService bannerService; |
| | | |
| | | @Autowired |
| | | private QuickEntryService quickEntryService; |
| | | |
| | | @Autowired |
| | | private AdvertService advertService; |
| | | |
| | | @Autowired |
| | | private GoodsService goodsService; |
| | | |
| | | @Autowired |
| | | |
| | | @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 = memberService.getNearbyShop(appNearbyShopDto); |
| | | AppNearbyShopVo appNearbyShopVo = shopService.getNearbyShop(appNearbyShopDto,member); |
| | | return R.ok(appNearbyShopVo); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getHomeBanner", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取首页banner") |
| | | public R<List<AppBannerVo>> getHomeBanner() { |
| | | List<AppBannerVo> appBannerVoList = bannerService.listHomeBannerVo(); |
| | | return R.ok(appBannerVoList); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getQuickEntry", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取首页快速入口") |
| | | public R<List<AppQuickEntryVo>> getQuickEntry() { |
| | | List<AppQuickEntryVo> appQuickEntryVoList = quickEntryService.listQuickEntryVo(); |
| | | return R.ok(appQuickEntryVoList); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getAdvert", method = RequestMethod.POST) |
| | | @ApiOperation(value = "获取首页广告") |
| | | public R<AppAdvertVo> getAdvert() { |
| | | AppAdvertVo appAdvertVo = advertService.getAdvertVo(); |
| | | return R.ok(appAdvertVo); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pageRecommendGoods", method = RequestMethod.POST) |
| | | @ApiOperation(value = "推荐商品") |
| | | public R<Page<AppSimpleGoodsVo>> pageRecommendGoods(@RequestBody AppPageDto appPageDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Long shopId = null; |
| | | if(userId!=null){ |
| | | Member member = memberService.getById(userId); |
| | | if(member!=null&&member.getRealtionShopId()!=null){ |
| | | shopId = member.getRealtionShopId(); |
| | | } |
| | | } |
| | | Page<AppSimpleGoodsVo> page = new Page<>(); |
| | | page.setSize(appPageDto.getPageSize()); |
| | | page.setCurrent(appPageDto.getPageNum()); |
| | | List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsService.pageRecommendGoods(page,shopId); |
| | | return R.ok(page.setRecords(appSimpleGoodsVoList)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pageShopGoods", method = RequestMethod.POST) |
| | | @ApiOperation(value = "商城商品") |
| | | public R<Page<AppSimpleGoodsVo>> pageShopGoods(@RequestBody AppShopGoodsPageDto appShopGoodsPageDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if(userId!=null){ |
| | | Member member = memberService.getById(userId); |
| | | if(member!=null&&member.getRealtionShopId()!=null){ |
| | | appShopGoodsPageDto.setShopId(member.getRealtionShopId()); |
| | | } |
| | | } |
| | | Page<AppSimpleGoodsVo> page = new Page<>(); |
| | | page.setSize(appShopGoodsPageDto.getPageSize()); |
| | | page.setCurrent(appShopGoodsPageDto.getPageNum()); |
| | | List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsService.pageShopGoods(page,appShopGoodsPageDto); |
| | | return R.ok(page.setRecords(appSimpleGoodsVoList)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pageSearchGoods", method = RequestMethod.POST) |
| | | @ApiOperation(value = "搜索商品") |
| | | public R<Page<AppSimpleGoodsVo>> pageSearchGoods(@RequestBody AppSearchGoodsPageDto appSearchGoodsPageDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if(userId!=null){ |
| | | Member member = memberService.getById(userId); |
| | | if(member!=null&&member.getRealtionShopId()!=null){ |
| | | appSearchGoodsPageDto.setShopId(member.getRealtionShopId()); |
| | | } |
| | | } |
| | | Page<AppSimpleGoodsVo> page = new Page<>(); |
| | | page.setSize(appSearchGoodsPageDto.getPageSize()); |
| | | page.setCurrent(appSearchGoodsPageDto.getPageNum()); |
| | | List<AppSimpleGoodsVo> appSimpleGoodsVoList = goodsService.pageSearchGoods(page,appSearchGoodsPageDto); |
| | | return R.ok(page.setRecords(appSimpleGoodsVoList)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pageSearchActivityGoods", method = RequestMethod.POST) |
| | | @ApiOperation(value = "搜索活动商品") |
| | | public R<Page<AppSimpleActivityGoodsVo>> pageSearchActivityGoods(@RequestBody AppSearchGoodsPageDto appSearchGoodsPageDto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if(userId!=null){ |
| | | Member member = memberService.getById(userId); |
| | | if(member!=null&&member.getRealtionShopId()!=null){ |
| | | appSearchGoodsPageDto.setShopId(member.getRealtionShopId()); |
| | | } |
| | | } |
| | | Page<AppSimpleActivityGoodsVo> page = new Page<>(); |
| | | page.setSize(appSearchGoodsPageDto.getPageSize()); |
| | | page.setCurrent(appSearchGoodsPageDto.getPageNum()); |
| | | List<AppSimpleActivityGoodsVo> appSimpleGoodsVoList = goodsService.pageSearchActivityGoods(page,appSearchGoodsPageDto); |
| | | return R.ok(page.setRecords(appSimpleGoodsVoList)); |
| | | } |
| | | |
| | | |
| | | |
| | | @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(); |
| | | } |
| | | } |