|
|
@@ -1,5 +1,6 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
@@ -9,10 +10,17 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import shop.alien.entity.store.LifeCoupon;
|
|
|
+import shop.alien.entity.store.LifeGroupBuyMain;
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.StoreInfo;
|
|
|
import shop.alien.entity.store.excelVo.StoreCouponStatusVo;
|
|
|
import shop.alien.entity.store.excelVo.util.ExcelGenerator;
|
|
|
import shop.alien.entity.store.vo.LifeCouponVo;
|
|
|
+import shop.alien.entity.store.vo.LifeGroupBuyMainVo;
|
|
|
import shop.alien.mapper.PlatformStoreCouponMapper;
|
|
|
+import shop.alien.mapper.PlatformStoreLifeGroupBuyMainMapper;
|
|
|
+import shop.alien.mapper.StoreImgMapper;
|
|
|
+import shop.alien.mapper.StoreInfoMapper;
|
|
|
import shop.alien.store.service.PlatformStoreCouponService;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -28,6 +36,9 @@ import java.util.stream.Collectors;
|
|
|
public class PlatformStoreCouponServiceImpl implements PlatformStoreCouponService {
|
|
|
|
|
|
private final PlatformStoreCouponMapper platformStoreCouponMapper;
|
|
|
+ private final PlatformStoreLifeGroupBuyMainMapper platformStoreLifeGroupBuyMainMapper;
|
|
|
+ private final StoreInfoMapper storeInfoMapper;
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
|
|
|
List<LifeCouponVo> toExcel = new ArrayList<>();
|
|
|
|
|
|
@@ -80,6 +91,54 @@ public class PlatformStoreCouponServiceImpl implements PlatformStoreCouponServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public IPage<LifeGroupBuyMainVo> getLifeGroupBuyMainList(Integer page, Integer size, String storeName, String status, String createdTime, String phone, String expiredState) {
|
|
|
+ QueryWrapper<LifeGroupBuyMainVo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.like(StringUtils.isNotEmpty(storeName), "store.store_name", storeName);
|
|
|
+ if(status==null || status.equals("")){
|
|
|
+ wrapper.in("life.status",1,2,3,4,5,6,7);
|
|
|
+ }
|
|
|
+ if(status.equals("9")){
|
|
|
+ wrapper.in("life.status",4,5,6,7);
|
|
|
+ }else{
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(status), "life.status", status);
|
|
|
+ }
|
|
|
+ //0:套餐未过期 1:套餐已过期
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now(); // 获取当前时间
|
|
|
+ if(expiredState!=null){
|
|
|
+ if(expiredState.equals("0")){
|
|
|
+ wrapper.gt("life.end_time",nowDate);
|
|
|
+ }
|
|
|
+ if(expiredState.equals("1")){
|
|
|
+ wrapper.lt("life.end_time",nowDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.eq("life.delete_flag", 0);
|
|
|
+ wrapper.eq("store.delete_flag", 0);
|
|
|
+ wrapper.eq("user.delete_flag", 0);
|
|
|
+ wrapper.like(StringUtils.isNotEmpty(createdTime), "life.created_time", createdTime);
|
|
|
+ wrapper.like(StringUtils.isNotEmpty(phone), "user.phone", phone);
|
|
|
+ wrapper.orderByDesc("life.created_time");
|
|
|
+
|
|
|
+ IPage<LifeGroupBuyMainVo> lifeGroupBuyMainList = platformStoreLifeGroupBuyMainMapper.getLifeGroupBuyMainList(new Page<>(page, size), wrapper);
|
|
|
+ lifeGroupBuyMainList.getRecords().forEach(item -> {
|
|
|
+// expiredState 赋值逻辑(修正版)
|
|
|
+ LocalDateTime now = LocalDateTime.now(); // 获取当前时间
|
|
|
+ Date endDate = item.getEndTime();
|
|
|
+ if (endDate != null) {
|
|
|
+ LocalDateTime endDateTime = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ // 核心逻辑:未过期时赋 0,已过期赋 1(与前端枚举定义一致)
|
|
|
+ if (now.isBefore(endDateTime)) {
|
|
|
+ item.setExpiredState("0"); // 当前时间未超过 endDate → 未到期
|
|
|
+ } else {
|
|
|
+ item.setExpiredState("1"); // 当前时间超过 endDate → 已到期
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return lifeGroupBuyMainList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public IPage<LifeCouponVo> getCouponStatusList(Integer page, Integer size, String status, String expiredState) {
|
|
|
IPage<LifeCouponVo> iPage = new Page<>(page, size);
|
|
|
QueryWrapper<LifeCouponVo> wrapper = new QueryWrapper<>();
|
|
|
@@ -173,23 +232,36 @@ public class PlatformStoreCouponServiceImpl implements PlatformStoreCouponServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int approvalCoupon(Integer id, Integer status, String comment) {
|
|
|
- LifeCoupon coupon = platformStoreCouponMapper.selectById(id);
|
|
|
- if (null == coupon) return 0;
|
|
|
-
|
|
|
- // 如果通过,且券有效时间在当前时间之前,则修改状态为进行中
|
|
|
- Date now = new Date();
|
|
|
- if (status == 0 && coupon.getStartDate().before(now) && coupon.getEndDate().after(now)) {
|
|
|
- status = 1;
|
|
|
- }
|
|
|
+ public int approvalCoupon(Integer id, Integer status, String comment, String type) {
|
|
|
+ if(type.equals("0")){
|
|
|
+ LifeCoupon coupon = platformStoreCouponMapper.selectById(id);
|
|
|
+ if (null == coupon) return 0;
|
|
|
+
|
|
|
+ // 如果通过,且券有效时间在当前时间之前,则修改状态为进行中
|
|
|
+ Date now = new Date();
|
|
|
+ if (status == 0 && coupon.getStartDate().before(now) && coupon.getEndDate().after(now)) {
|
|
|
+ status = 1;
|
|
|
+ }
|
|
|
|
|
|
- coupon.setStatus(status);
|
|
|
- coupon.setApprovalComments(comment);
|
|
|
- // 审核后开始
|
|
|
- if ("0".equals(coupon.getSaleTimeStrType())) {
|
|
|
- coupon.setStartDate(new Date());
|
|
|
+ coupon.setStatus(status);
|
|
|
+ coupon.setApprovalComments(comment);
|
|
|
+ // 审核后开始
|
|
|
+ if ("0".equals(coupon.getSaleTimeStrType())) {
|
|
|
+ coupon.setStartDate(new Date());
|
|
|
+ }
|
|
|
+ return platformStoreCouponMapper.updateById(coupon);
|
|
|
+ }else{
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = platformStoreLifeGroupBuyMainMapper.selectById(id);
|
|
|
+ if (null == lifeGroupBuyMain) return 0;
|
|
|
+ lifeGroupBuyMain.setStatus(status);
|
|
|
+ lifeGroupBuyMain.setApprovalComments(comment);
|
|
|
+ // 审核后开始
|
|
|
+ if ("0".equals(lifeGroupBuyMain.getStartTimeType())) {
|
|
|
+ lifeGroupBuyMain.setStartTimeValue(new Date());
|
|
|
+ }
|
|
|
+ return platformStoreLifeGroupBuyMainMapper.updateById(lifeGroupBuyMain);
|
|
|
}
|
|
|
- return platformStoreCouponMapper.updateById(coupon);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -301,10 +373,161 @@ public class PlatformStoreCouponServiceImpl implements PlatformStoreCouponServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public String lifeGroupBuyMainStatusExport(String status, String expiredState) throws IOException {
|
|
|
+ QueryWrapper<LifeGroupBuyMainVo> wrapper = new QueryWrapper<>();
|
|
|
+ // 定义允许的状态值
|
|
|
+ if(status==null || status.equals("")){
|
|
|
+ wrapper.in("life.status",1,2,3,4,5,6,7);
|
|
|
+ }
|
|
|
+ if(status.equals("9")){
|
|
|
+ wrapper.in("life.status",4,5,6,7);
|
|
|
+ }else{
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(status), "life.status", status);
|
|
|
+ }
|
|
|
+ //0:套餐未过期 1:套餐已过期
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now(); // 获取当前时间
|
|
|
+ if(expiredState!=null){
|
|
|
+ if(expiredState.equals("0")){
|
|
|
+ wrapper.gt("life.end_time",nowDate);
|
|
|
+ }
|
|
|
+ if(expiredState.equals("1")){
|
|
|
+ wrapper.lt("life.end_time",nowDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.eq("life.delete_flag", 0);
|
|
|
+ wrapper.eq("store.delete_flag", 0);
|
|
|
+ wrapper.eq("user.delete_flag", 0);
|
|
|
+
|
|
|
+ wrapper.orderByDesc("life.created_time");
|
|
|
+
|
|
|
+ List<LifeGroupBuyMainVo> lifeGroupBuyMainList = platformStoreLifeGroupBuyMainMapper.getLifeGroupBuyMainList(wrapper);
|
|
|
+ lifeGroupBuyMainList.forEach(item -> {
|
|
|
+ if (item.getStatus() == 1) {
|
|
|
+ item.setCouponState("待审核");
|
|
|
+ } else if (item.getStatus() == 2) {
|
|
|
+ item.setCouponState("未开始");
|
|
|
+ } else if (item.getStatus() == 3) {
|
|
|
+ item.setCouponState("审核拒绝");
|
|
|
+ } else if (item.getStatus() == 4 && item.getInventoryNum() == 0) {
|
|
|
+ item.setCouponState("已售罄");
|
|
|
+ } else if (item.getStatus() == 5 && item.getInventoryNum()>0) {
|
|
|
+ item.setCouponState("进行中");
|
|
|
+ }
|
|
|
+ else if (item.getStatus() == 6) {
|
|
|
+ item.setCouponState("已下架");
|
|
|
+ }
|
|
|
+ else if (item.getStatus() == 7) {
|
|
|
+ item.setCouponState("已结束");
|
|
|
+ }
|
|
|
+ item.setCouponName(item.getGroupName());
|
|
|
+ Date startDate = item.getStartTimeValue();
|
|
|
+ Date endDate = item.getEndTime();
|
|
|
+ // expiredState 赋值逻辑(修正版)
|
|
|
+ LocalDateTime now = LocalDateTime.now(); // 获取当前时间
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String formattedEndDate = "";
|
|
|
+ if (endDate != null) {
|
|
|
+ LocalDateTime endDateTime = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ // 调整结束时间为前一天的23:59:59
|
|
|
+ endDateTime = endDateTime.minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
|
|
+ formattedEndDate = endDateTime.format(formatter);
|
|
|
+
|
|
|
+ // 核心逻辑:未过期时赋 0,已过期赋 1(与前端枚举定义一致)
|
|
|
+ if (now.isBefore(endDateTime)) {
|
|
|
+ // 计算剩余天数
|
|
|
+ long remainingDays = ChronoUnit.DAYS.between(now, endDateTime);
|
|
|
+ item.setDaysToExpire(remainingDays + "天");
|
|
|
+ item.setExpiredState("未到期"); // 当前时间未超过 endDate → 未到期
|
|
|
+ } else {
|
|
|
+ item.setDaysToExpire("0天");
|
|
|
+ item.setExpiredState("已到期"); // 当前时间超过 endDate → 已到期
|
|
|
+ }
|
|
|
+ // 将结束时间调整为前一秒
|
|
|
+ endDateTime = endDateTime.minusSeconds(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startDate != null) {
|
|
|
+ LocalDateTime startDateTime = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ String formattedStartDate = startDateTime.format(formatter);
|
|
|
+ item.setCouponTime(formattedStartDate + "-" + formattedEndDate);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 根据 expiredState 进行筛选
|
|
|
+ if (StringUtils.isNotEmpty(expiredState)) {
|
|
|
+ // 将前端传递的 "0"/"1" 转换为业务状态
|
|
|
+ String targetState = "0".equals(expiredState) ? "未到期" : "已到期";
|
|
|
+
|
|
|
+ // 筛选时增加空值判断,避免 NPE
|
|
|
+ lifeGroupBuyMainList = lifeGroupBuyMainList.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ String itemState = item.getExpiredState(); // 获取当前项的状态
|
|
|
+ return targetState.equals(itemState); // 严格匹配字符串
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<StoreCouponStatusVo> storeCouponStatusVos = new ArrayList<>();
|
|
|
+ int index = 1;
|
|
|
+ for (LifeGroupBuyMainVo record : lifeGroupBuyMainList) {
|
|
|
+ StoreCouponStatusVo storeCouponStatusVo = new StoreCouponStatusVo();
|
|
|
+ BeanUtils.copyProperties(record, storeCouponStatusVo);
|
|
|
+ storeCouponStatusVo.setId(String.valueOf(index++)); // 设置序号
|
|
|
+ storeCouponStatusVos.add(storeCouponStatusVo);
|
|
|
+ }
|
|
|
+ String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
+
|
|
|
+ ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", storeCouponStatusVos, StoreCouponStatusVo.class);
|
|
|
+ return fileUrl + "excel" + excelGeneratePath + fileName + ".xlsx";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public int deleteCouponStatus(Integer id) {
|
|
|
LifeCoupon lifeCoupon = new LifeCoupon();
|
|
|
lifeCoupon.setId(String.valueOf(id));
|
|
|
lifeCoupon.setStatusDeleteFlag(1);
|
|
|
return platformStoreCouponMapper.deleteById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LifeGroupBuyMainVo getLifeGroupBuyMainByDetail(Integer id) {
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = platformStoreLifeGroupBuyMainMapper.selectById(id);
|
|
|
+ // 添加商户信息
|
|
|
+ StoreInfo storeUser = storeInfoMapper.selectById(lifeGroupBuyMain.getStoreId());
|
|
|
+
|
|
|
+ List<String> collect = Arrays.stream(lifeGroupBuyMain.getImageId().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<StoreImg> storeImgs = storeImgMapper.selectList(new LambdaQueryWrapper<StoreImg>().in(StoreImg::getId, collect));
|
|
|
+
|
|
|
+ LifeGroupBuyMainVo lifeGroupBuyMainVo = new LifeGroupBuyMainVo();
|
|
|
+ BeanUtils.copyProperties(lifeGroupBuyMain,lifeGroupBuyMainVo);
|
|
|
+ lifeGroupBuyMainVo.setStoreName(storeUser.getStoreName());
|
|
|
+ lifeGroupBuyMainVo.setStoreImgList(storeImgs);
|
|
|
+ //0:套餐未过期 1:套餐已过期
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now(); // 获取当前时间
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String formattedEndDate = "";
|
|
|
+ LocalDateTime endDateTime = lifeGroupBuyMainVo.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ // 调整结束时间为前一天的23:59:59
|
|
|
+ endDateTime = endDateTime.minusDays(1).withHour(23).withMinute(59).withSecond(59);
|
|
|
+// formattedEndDate = endDateTime.format(formatter);
|
|
|
+
|
|
|
+ // 核心逻辑:未过期时赋 0,已过期赋 1(与前端枚举定义一致)
|
|
|
+ if (nowDate.isBefore(endDateTime)) {
|
|
|
+ // 计算剩余天数
|
|
|
+ long remainingDays = ChronoUnit.DAYS.between(nowDate, endDateTime);
|
|
|
+ lifeGroupBuyMainVo.setDaysToExpire(remainingDays + "天");
|
|
|
+ lifeGroupBuyMainVo.setExpiredState("0"); // 当前时间未超过 endDate → 未到期
|
|
|
+ } else {
|
|
|
+ lifeGroupBuyMainVo.setDaysToExpire("0天");
|
|
|
+ lifeGroupBuyMainVo.setExpiredState("1"); // 当前时间超过 endDate → 已到期
|
|
|
+ }
|
|
|
+
|
|
|
+ return lifeGroupBuyMainVo;
|
|
|
+ }
|
|
|
}
|