puzhibing
2025-01-13 acccff9860b271d55c55dc87486f7c20b9896e6c
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java
@@ -7,12 +7,14 @@
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.other.api.domain.OrderActivityInfo;
import com.ruoyi.other.service.OrderActivityInfoService;
import com.ruoyi.other.service.VipSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -33,6 +35,8 @@
   @Resource
   private OrderActivityInfoService orderActivityInfoService;
   @Resource
   private VipSettingService vipSettingService;
   
   
   /**
@@ -42,27 +46,75 @@
    */
   @ResponseBody
   @PostMapping("/getNowOrderActivityInfo")
   public R<OrderActivityInfo> getNowOrderActivityInfo(@RequestParam("vip") Integer vip){
      OrderActivityInfo one = orderActivityInfoService.getOne(new LambdaQueryWrapper<OrderActivityInfo>().eq(OrderActivityInfo::getDelFlag, 0)
            .last(" and now() between start_time and end_time and FIND_IN_SET(" + vip + ", vip_ids) limit 0, 1"));
   public R<List<OrderActivityInfo>> getNowOrderActivityInfo(@RequestParam("vip") Integer vip){
      List<OrderActivityInfo> one = orderActivityInfoService.list(new LambdaQueryWrapper<OrderActivityInfo>().eq(OrderActivityInfo::getDelFlag, 0)
            .eq(OrderActivityInfo::getIsShelf, 1).last(" and now() between start_time and end_time and FIND_IN_SET(" + vip + ", vip_ids)"));
      return R.ok(one);
   }
   /**
    * 添加活动
    */
   @PostMapping("/save")
   @ApiOperation(value = "添加活动", tags = {"管理后台-活动管理-订单优惠活动"})
   @ApiOperation(value = "订单优惠活动-添加活动", tags = {"管理后台-活动管理"})
   public R<Void> saveActivityConfig(@RequestBody OrderActivityInfo orderActivityInfo){
      orderActivityInfo.setIsShelf(0);
      if (org.springframework.util.StringUtils.hasLength(orderActivityInfo.getVipIds())){
         List<String> vipIds = new ArrayList<>(Arrays.asList(orderActivityInfo.getVipIds().split(",")));
         List<OrderActivityInfo> list = orderActivityInfoService.lambdaQuery()
               .le(OrderActivityInfo::getStartTime, orderActivityInfo.getStartTime())
               .or()
               .ge(OrderActivityInfo::getEndTime, orderActivityInfo.getEndTime()).list();
         if (!list.isEmpty()){
            for (OrderActivityInfo activityInfo : list) {
               List<String> vips = Arrays.asList(activityInfo.getVipIds().split(","));
               vipIds.addAll(vips);
               if (!vipIds.isEmpty()){
                  StringBuilder message = new StringBuilder();
                  List<String> collect = vips.stream().sorted().collect(Collectors.toList());
                  for (String s : collect) {
                     switch (s){
                        case "1":
                           message.append("普通会员,");
                           break;
                        case "2":
                           message.append("黄金会员,");
                           break;
                        case "3":
                           message.append("钻石会员,");
                           break;
                        case "4":
                           message.append("准代理,");
                           break;
                        case "5":
                           message.append("代理,");
                           break;
                        case "6":
                           message.append("总代,");
                           break;
                        case "7":
                           message.append("合伙人,");
                           break;
                     }
                  }
                  StringBuilder res = message.deleteCharAt(message.length() - 1);
                  return R.fail(res+"在当前活动时间已有订单优惠");
               }
            }
         }
      }
      orderActivityInfoService.save(orderActivityInfo);
      return R.ok();
   }
   /**
    * 删除活动
    */
   @PostMapping("/delete")
   @ApiOperation(value = "删除活动", tags = {"管理后台-活动管理-订单优惠活动"})
   @DeleteMapping("/delete")
   @ApiOperation(value = "订单优惠活动-删除活动", tags = {"管理后台-活动管理"})
   public R<Void> deleteActivityConfig(@RequestParam("id") Long id){
      orderActivityInfoService.removeById(id);
      return R.ok();
@@ -72,8 +124,53 @@
    * 修改活动
    */
   @PostMapping("/update")
   @ApiOperation(value = "修改活动", tags = {"管理后台-活动管理-订单优惠活动"})
   @ApiOperation(value = "修改活动", tags = {"管理后台-活动管理"})
   public R<Void> updateActivityConfig(@RequestBody OrderActivityInfo orderActivityInfo){
      orderActivityInfo.setId(Long.valueOf(orderActivityInfo.getIdStr()));
      if (org.springframework.util.StringUtils.hasLength(orderActivityInfo.getVipIds())){
         List<String> vipIds = Arrays.asList(orderActivityInfo.getVipIds().split(","));
         List<OrderActivityInfo> list = orderActivityInfoService.lambdaQuery()
               .le(OrderActivityInfo::getStartTime, orderActivityInfo.getStartTime())
               .or()
               .ge(OrderActivityInfo::getEndTime, orderActivityInfo.getEndTime()).list();
         if (!list.isEmpty()){
            for (OrderActivityInfo activityInfo : list) {
               List<String> vips = Arrays.asList(activityInfo.getVipIds().split(","));
               vipIds.retainAll(vips);
               if (!vipIds.isEmpty()){
                  StringBuilder message = new StringBuilder();
                  List<String> collect = vips.stream().sorted().collect(Collectors.toList());
                  for (String s : collect) {
                     switch (s){
                        case "1":
                           message.append("普通会员,");
                           break;
                        case "2":
                           message.append("黄金会员,");
                           break;
                        case "3":
                           message.append("钻石会员,");
                           break;
                        case "4":
                           message.append("准代理,");
                           break;
                        case "5":
                           message.append("代理,");
                           break;
                        case "6":
                           message.append("总代,");
                           break;
                        case "7":
                           message.append("合伙人,");
                           break;
                     }
                  }
                  StringBuilder res = message.deleteCharAt(message.length() - 1);
                  return R.fail(res+"在当前活动时间已有订单优惠");
               }
            }
         }
      }
      orderActivityInfoService.updateById(orderActivityInfo);
      return R.ok();
   }
@@ -82,26 +179,58 @@
    * 获取活动列表
    */
   @GetMapping("/list")
   @ApiOperation(value = "获取活动列表", tags = {"管理后台-活动管理-订单优惠活动"})
   @ApiOperation(value = "订单优惠活动-获取活动列表", tags = {"管理后台-活动管理"})
   public R<Page<OrderActivityInfo>> list(@ApiParam("页码") @RequestParam Integer pageNum,
                            @ApiParam("每一页数据大小") Integer pageSize,
                            OrderActivityInfo orderActivityInfo){
      return R.ok(orderActivityInfoService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<OrderActivityInfo>()
            .eq(orderActivityInfo.getId() != null, OrderActivityInfo::getId, orderActivityInfo.getId())
            .eq(StringUtils.isNotEmpty(orderActivityInfo.getActivityName()), OrderActivityInfo::getActivityName, orderActivityInfo.getActivityName())
            .lt(orderActivityInfo.getStatus() == 0, OrderActivityInfo::getStartTime, orderActivityInfo.getStartTime())
            .ge(orderActivityInfo.getStatus() == 1, OrderActivityInfo::getEndTime, orderActivityInfo.getStartTime())
            .eq(orderActivityInfo.getIsShelf() != null, OrderActivityInfo::getIsShelf, orderActivityInfo.getIsShelf())));
      Page<OrderActivityInfo> page = orderActivityInfoService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<OrderActivityInfo>()
            .like(orderActivityInfo.getId() != null, OrderActivityInfo::getId, orderActivityInfo.getId())
            .like(StringUtils.isNotEmpty(orderActivityInfo.getActivityName()), OrderActivityInfo::getActivityName, orderActivityInfo.getActivityName())
            .gt(orderActivityInfo.getStatus() != null && orderActivityInfo.getStatus() == 0, OrderActivityInfo::getStartTime, LocalDateTime.now())
            .ge(orderActivityInfo.getStatus() != null && orderActivityInfo.getStatus() == 1, OrderActivityInfo::getEndTime, LocalDateTime.now())
            .lt(orderActivityInfo.getStatus() != null && orderActivityInfo.getStatus() == 1, OrderActivityInfo::getStartTime, LocalDateTime.now())
            .eq(orderActivityInfo.getIsShelf() != null, OrderActivityInfo::getIsShelf, orderActivityInfo.getIsShelf()).orderByDesc(OrderActivityInfo::getCreateTime)
            .orderByDesc(OrderActivityInfo::getCreateTime))
            ;
      page.getRecords().forEach(item -> {
         LocalDateTime startTime = item.getStartTime();
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime endTime = item.getEndTime();
         if (endTime.isBefore(now)){
            item.setStatus(2); //已结束
         }else if (startTime.isBefore(now)){
            item.setStatus(1); // 已开始
         }else {
            item.setStatus(0); // 未开始
         }
         String vipIds = item.getVipIds();
         if (StringUtils.isNotEmpty(vipIds)){
            String[] vipIdArr = vipIds.split(",");
            if (vipIdArr.length == 7){
               item.setVipName("全部");
            }else {
               List<String> vipNameList = new ArrayList<>();
               for (String vipId : vipIdArr) {
                  String vipName = vipSettingService.getById(Long.parseLong(vipId)).getVipName();
                  vipNameList.add(vipName);
               }
               item.setVipName(String.join(",", vipNameList));
            }
         }
      });
      return R.ok(page);
   }
   /**
    * 获取活动详情
    */
   @GetMapping("/getDetailById")
   @ApiOperation(value = "获取活动详情", tags = {"管理后台-活动管理-订单优惠活动"})
   public R<OrderActivityInfo> getDetailById(@RequestParam("id") Long id){
      return R.ok(orderActivityInfoService.getById(id));
   @ApiOperation(value = "订单优惠活动-获取活动详情", tags = {"管理后台-活动管理"})
   public R<OrderActivityInfo> getDetailById(@RequestParam("id") String id){
      return R.ok(orderActivityInfoService.getById(Long.parseLong(id)));
   }