| | |
| | | package com.ruoyi.other.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.UserCouponClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserCoupon; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.other.api.domain.CouponInfo; |
| | | import com.ruoyi.other.api.domain.Goods; |
| | | import com.ruoyi.other.service.CouponInfoService; |
| | | import com.ruoyi.other.service.GoodsService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | @Resource |
| | | private UserCouponClient userCouponClient; |
| | | @Resource |
| | | private GoodsService goodsService; |
| | | |
| | | @PostMapping("/list") |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "优惠劵管理-列表", tags = {"管理后台-活动管理"}) |
| | | public R<IPage<CouponInfo>> list(@RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize, |
| | | CouponInfo couponInfo) { |
| | | return R.ok(couponInfoService.queryCouponInfoPage(Page.of(pageNum, pageSize), couponInfo)); |
| | | IPage<CouponInfo> couponInfoIPage = couponInfoService.queryCouponInfoPage(Page.of(pageNum, pageSize), couponInfo); |
| | | for (CouponInfo record : couponInfoIPage.getRecords()) { |
| | | R<Long> r = userCouponClient.getCouponCount(record.getId()); |
| | | record.setSendNumNow(r.getData()); |
| | | } |
| | | return R.ok(couponInfoIPage); |
| | | } |
| | | |
| | | |
| | | //查看详情 |
| | | @PostMapping("/detail") |
| | | @GetMapping("/detail") |
| | | @ApiOperation(value = "优惠劵管理-详情", tags = {"管理后台-活动管理"}) |
| | | public R<CouponInfo> detail(@RequestParam("id") Integer id) { |
| | | CouponInfo byId = couponInfoService.getById(id); |
| | | String forGoodIds = byId.getForGoodIds(); |
| | | if (!"-1".equals(forGoodIds) && StringUtils.isNotEmpty(forGoodIds)){ |
| | | List<Goods> goods = goodsService.listByIds(Arrays.asList(forGoodIds.split(","))); |
| | | byId.setGoods(goods); |
| | | byId.setGoodsNameList(goods.stream().map(Goods::getName).collect(Collectors.toList())); |
| | | } |
| | | String personIds = byId.getPersonIds(); |
| | | if (StringUtils.isNotEmpty(personIds)){ |
| | | List<Long> ids = Arrays.stream(personIds.split(",")).map(Long::valueOf).collect(Collectors.toList()); |
| | | List<AppUser> appUserList = appUserClient.listByIds(ids); |
| | | byId.setAppUserList(appUserList); |
| | | } |
| | | |
| | | return R.ok(byId); |
| | | } |
| | | |
| | | // 删除优惠劵 |
| | | @PostMapping("/delete") |
| | | @DeleteMapping("/delete") |
| | | @ApiOperation(value = "优惠劵管理-删除", tags = {"管理后台-活动管理"}) |
| | | public R<Void> delete(@RequestParam("id") Integer id) { |
| | | couponInfoService.removeById(id); |
| | |
| | | @PostMapping("/edit") |
| | | @ApiOperation(value = "优惠劵管理-编辑", tags = {"管理后台-活动管理"}) |
| | | public R<Void> edit(@RequestBody CouponInfo couponInfo) { |
| | | List<String> goodsNameList = couponInfo.getGoodsNameList(); |
| | | couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList)); |
| | | if(couponInfo.getPeriodType() == 2){ |
| | | Integer periodDays = couponInfo.getPeriodDays(); |
| | | couponInfo.setPeriodStartTime(LocalDate.now()); |
| | | couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays)); |
| | | } |
| | | couponInfoService.updateById(couponInfo); |
| | | return R.ok(); |
| | | } |
| | |
| | | couponInfo.setId(id); |
| | | couponInfo.setShelfStatus(shelfStatus); |
| | | couponInfoService.updateById(couponInfo); |
| | | return R.ok(); |
| | | } |
| | | |
| | | // 添加优惠券 |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "优惠劵管理-添加", tags = {"管理后台-活动管理"}) |
| | | public R<Void> add(@RequestBody CouponInfo couponInfo) { |
| | | couponInfo.setShelfStatus(0); |
| | | List<String> goodsNameList = couponInfo.getGoodsNameList(); |
| | | couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList)); |
| | | couponInfo.setShelfStatus(1); |
| | | if(couponInfo.getPeriodType() == 2){ |
| | | Integer periodDays = couponInfo.getPeriodDays(); |
| | | couponInfo.setPeriodStartTime(LocalDate.now()); |
| | | couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays)); |
| | | } |
| | | couponInfoService.save(couponInfo); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | return R.ok(couponInfos); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取领取记录 |
| | | */ |
| | | |
| | | @GetMapping("/getReceiveRecord") |
| | | public R<IPage<UserCoupon>> getReceiveRecord(@ApiParam("页码") @RequestParam Integer pageNum, @ApiParam("大小") Integer pageSize,UserCoupon userCoupon) { |
| | | // TODO 待完善 |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |