package com.ruoyi.other.controller;
|
|
|
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.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author luodangjia
|
* @since 2024-11-20
|
*/
|
@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 = 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.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 = 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();
|
}
|
|
/**
|
* 获取活动列表
|
*/
|
@GetMapping("/list")
|
@ApiOperation(value = "订单优惠活动-获取活动列表", tags = {"管理后台-活动管理"})
|
public R<Page<OrderActivityInfo>> list(@ApiParam("页码") @RequestParam Integer pageNum,
|
@ApiParam("每一页数据大小") Integer pageSize,
|
OrderActivityInfo orderActivityInfo){
|
|
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") String id){
|
return R.ok(orderActivityInfoService.getById(Long.parseLong(id)));
|
}
|
|
|
}
|