| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.core.web.page.TableDataInfo; |
| | | import com.ruoyi.order.feignClient.OrderClient; |
| | | import com.ruoyi.other.api.domain.Goods; |
| | | import com.ruoyi.other.api.domain.GoodsSeckill; |
| | | import com.ruoyi.other.api.domain.SeckillActivityInfo; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private GoodsService goodsService; |
| | | |
| | | @Resource |
| | | private OrderClient orderClient; |
| | | |
| | | |
| | | |
| | |
| | | * 秒杀活动列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "秒杀活动列表",tags = {"小程序-商城-首页","后台管理-活动管理-秒杀活动"}) |
| | | @ApiOperation(value = "秒杀活动列表",tags = {"小程序-商城-首页"}) |
| | | public R<TableDataInfo> list(Goods goods) |
| | | { |
| | | startPage(); |
| | | return R.ok(getDataTable(seckillActivityInfoService.listSeckillActivity(goods))); |
| | | return R.ok(seckillActivityInfoService.listSeckillActivity(goods)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @GetMapping("/detail/{id}") |
| | | @ApiOperation(value = "秒杀活动详情", tags = {"小程序-商城-首页"}) |
| | | public R<SeckillActivityDetailVO> detail(@PathVariable("id") Integer id) |
| | | public R<SeckillActivityDetailVO> detail(@PathVariable("id") Integer id, String latitude, String longitude) |
| | | { |
| | | return R.ok(seckillActivityInfoService.detail(id)); |
| | | return R.ok(seckillActivityInfoService.detail(id, latitude, longitude)); |
| | | } |
| | | |
| | | |
| | |
| | | @PostMapping("/getSeckillActivityInfo") |
| | | public R<GoodsSeckill> getSeckillActivityInfo(@RequestBody GetSeckillActivityInfo info){ |
| | | SeckillActivityInfo one = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, info.getGoodsId()) |
| | | .eq(SeckillActivityInfo::getDelFlag, 0).last(" and now() between start_time and end_time order by create_time limit 0,1")); |
| | | .eq(SeckillActivityInfo::getDelFlag, 0).eq(SeckillActivityInfo::getIsShelves, 1).last(" and now() between start_time and end_time order by create_time limit 0,1")); |
| | | if(null == one){ |
| | | return R.ok(); |
| | | } |
| | | GoodsSeckill goodsSeckill = goodsSeckillService.getOne(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, one.getGoodId()).eq(GoodsSeckill::getVip, info.getVip())); |
| | | GoodsSeckill goodsSeckill = goodsSeckillService.getOne(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, one.getId()).eq(GoodsSeckill::getVip, info.getVip())); |
| | | if(null != goodsSeckill){ |
| | | goodsSeckill.setEndTime(one.getEndTime().toEpochSecond(ZoneOffset.UTC) * 1000); |
| | | LocalDateTime endTime = one.getEndTime(); |
| | | // 转时间戳 |
| | | long timeStamp = endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
| | | goodsSeckill.setEndTime(timeStamp); |
| | | } |
| | | return R.ok(goodsSeckill); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取商品秒杀活动 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/getSeckillActivityInfoById") |
| | | public R<SeckillActivityInfo> getSeckillActivityInfoById(@RequestParam("id") Integer id){ |
| | | SeckillActivityInfo one = seckillActivityInfoService.getById(id); |
| | | return R.ok(one); |
| | | } |
| | | |
| | | |
| | |
| | | * 秒杀活动列表 |
| | | */ |
| | | @GetMapping("/manageList") |
| | | @ApiOperation(value = "秒杀活动列表",tags = {"小程序-商城-首页","后台管理-活动管理-秒杀活动"}) |
| | | @ApiOperation(value = "秒杀活动列表",tags = {"后台管理-活动管理-秒杀活动"}) |
| | | public R<IPage<SeckillActivityVO>> manageList(@ApiParam("页码") @RequestParam Integer pageNum, |
| | | @ApiParam("每一页数据大小") Integer pageSize, |
| | | Goods goods) |
| | | { |
| | | IPage<SeckillActivityVO> IPage = seckillActivityInfoMapper.querySeckillActivity(Page.of(pageNum, pageSize), goods); |
| | | for (SeckillActivityVO record : IPage.getRecords()) { |
| | | LocalDateTime startTime = record.getStartTime(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime endTime = record.getEndTime(); |
| | | if (endTime.isBefore(now)){ |
| | | record.setStatus(3); //已结束 |
| | | }else if (startTime.isBefore(now)){ |
| | | record.setStatus(2); // 已开始 |
| | | }else { |
| | | record.setStatus(1); // 未开始 |
| | | } |
| | | Integer saleNum = orderClient.getGoodsSaleNum(record.getGoodsId(), 2).getData(); |
| | | record.setSaleNum(saleNum); |
| | | } |
| | | return R.ok(IPage); |
| | | } |
| | | |
| | |
| | | { |
| | | seckillActivityInfoService.saveSeckillActivityInfo(seckillActivityInfo); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @GetMapping("/getSeckillActivityInfoByGoodsId") |
| | | public R<SeckillActivityInfo> getSeckillActivityInfoByGoodsId(@RequestParam("goodsId") Integer goodsId){ |
| | | SeckillActivityInfo seckillActivityInfo = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>() |
| | | .eq(SeckillActivityInfo::getGoodId, goodsId) |
| | | .eq(SeckillActivityInfo::getDelFlag, 0) |
| | | .eq(SeckillActivityInfo::getIsShelves, 1) |
| | | .last(" and now() between start_time and end_time")); |
| | | return R.ok(seckillActivityInfo); |
| | | } |
| | | |
| | | /** |
| | |
| | | .set(SeckillActivityInfo::getIsShelves, seckillActivityVO.getShowStatus())); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |