From d1cab4b2f2690d1331f12f0d9de78bbbf926f390 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 16 一月 2025 14:27:51 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/qijisheng --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 230 insertions(+), 2 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java index 5ca965f..f75ff29 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/OrderActivityInfoController.java @@ -1,8 +1,22 @@ package com.ruoyi.other.controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.R; +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.*; +import java.util.stream.Collectors; /** * <p> @@ -14,7 +28,221 @@ */ @RestController @RequestMapping("/order-activity-info") +@Api("订单优惠活动") public class OrderActivityInfoController { + @Resource + private OrderActivityInfoService orderActivityInfoService; + @Resource + private VipSettingService vipSettingService; + + + /** + * 获取当前生效的活动 + * @param vip + * @return + */ + @ResponseBody + @PostMapping("/getNowOrderActivityInfo") + 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 = {"管理后台-活动管理"}) + 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() + .between(OrderActivityInfo::getStartTime, orderActivityInfo.getStartTime(), orderActivityInfo.getEndTime()) + .or() + .between(OrderActivityInfo::getEndTime, orderActivityInfo.getStartTime(), orderActivityInfo.getEndTime()) + .list(); + if (!list.isEmpty()){ + for (OrderActivityInfo activityInfo : list) { + List<String> vips = Arrays.asList(activityInfo.getVipIds().split(",")); + if (!vipIds.isEmpty()){ + StringBuilder message = new StringBuilder(); + Set<String> set1 = new HashSet<>(vipIds); + Set<String> set2 = new HashSet<>(vips); + set1.retainAll(set2); + if (!set1.isEmpty()) { + // 有交集 判断是哪些会员 + for (String s : set1) { + 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(); + } + + /** + * 删除活动 + */ + @DeleteMapping("/delete") + @ApiOperation(value = "订单优惠活动-删除活动", tags = {"管理后台-活动管理"}) + public R<Void> deleteActivityConfig(@RequestParam("id") Long id){ + orderActivityInfoService.removeById(id); + return R.ok(); + } + + /** + * 修改活动 + */ + @PostMapping("/update") + @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 = new ArrayList<>(Arrays.asList(orderActivityInfo.getVipIds().split(","))); + List<OrderActivityInfo> list = orderActivityInfoService.lambdaQuery() + .between(OrderActivityInfo::getStartTime, orderActivityInfo.getStartTime(), orderActivityInfo.getEndTime()) + .or() + .between(OrderActivityInfo::getEndTime, orderActivityInfo.getStartTime(), orderActivityInfo.getEndTime()) + .list(); + // 遍历集合 通过startTime和endTime 判断是否与当前活动时间重叠 + + if (!list.isEmpty()){ + for (OrderActivityInfo activityInfo : list) { + List<String> vips = Arrays.asList(activityInfo.getVipIds().split(",")); + if (!vipIds.isEmpty()){ + StringBuilder message = new StringBuilder(); + Set<String> set1 = new HashSet<>(vipIds); + Set<String> set2 = new HashSet<>(vips); + set1.retainAll(set2); + if (!set1.isEmpty()) { + // 有交集 判断是哪些会员 + for (String s : set1) { + 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(); + } + + /** + * 获取活动列表 + */ + @GetMapping("/list") + @ApiOperation(value = "订单优惠活动-获取活动列表", tags = {"管理后台-活动管理"}) + public R<Page<OrderActivityInfo>> list(@ApiParam("页码") @RequestParam Integer pageNum, + @ApiParam("每一页数据大小") Integer pageSize, String id, String activityName, Integer status, Integer isShelf){ + + Page<OrderActivityInfo> page = orderActivityInfoService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<OrderActivityInfo>() + .like(StringUtils.isNotEmpty(id), OrderActivityInfo::getId, id) + .like(StringUtils.isNotEmpty(activityName), OrderActivityInfo::getActivityName, activityName) + .gt(status != null && status == 0, OrderActivityInfo::getStartTime, LocalDateTime.now()) + .ge(status != null && status == 1, OrderActivityInfo::getEndTime, LocalDateTime.now()) + .lt(status != null && status == 1, OrderActivityInfo::getStartTime, LocalDateTime.now()) + .lt(status != null && status == 2, OrderActivityInfo::getEndTime, LocalDateTime.now()) + .eq(isShelf != null, OrderActivityInfo::getIsShelf, isShelf).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") String id){ + return R.ok(orderActivityInfoService.getById(Long.parseLong(id))); + } + + } -- Gitblit v1.7.1