优惠券同步 下架问题

This commit is contained in:
2025-12-11 19:13:08 +08:00
parent e4ea8de704
commit a390ea9097
8 changed files with 85 additions and 7 deletions

View File

@@ -8,7 +8,9 @@ import com.czg.market.dto.MkCouponGiftDTO;
import com.czg.market.dto.MkRewardCouponDTO;
import com.czg.market.dto.MkShopCouponRecordDTO;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkPointsGoods;
import com.czg.market.service.MkCouponGiftService;
import com.czg.market.service.MkPointsGoodsService;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.ShopCouponService;
import com.czg.product.service.ShopSyncService;
@@ -19,12 +21,14 @@ import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -46,6 +50,8 @@ public class ACouponController {
private MkShopCouponRecordService couponRecordService;
@DubboReference
private ShopSyncService shopSyncService;
@Resource
private MkPointsGoodsService pointsGoodsSettingService;
/**
* 分页
@@ -53,7 +59,7 @@ public class ACouponController {
@GetMapping("page")
// @SaAdminCheckPermission("coupon:page")
public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) {
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
param.setShopId(shopId);
Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param);
return CzgResult.success(data);
@@ -79,9 +85,14 @@ public class ACouponController {
@OperationLog("优惠券-新增")
// @SaAdminCheckPermission("coupon:add")
public CzgResult<Void> addCoupon(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
dto.setShopId(shopId);
dto.setLeftNum(dto.getGiveNum());
if ("custom".equals(dto.getValidType())) {
if (dto.getValidEndTime().isBefore(LocalDateTime.now())) {
dto.setStatus(0);
}
}
shopCouponService.addCoupon(dto);
asyncToBranchShop(dto.getId(), 1);
return CzgResult.success();
@@ -94,8 +105,17 @@ public class ACouponController {
@OperationLog("优惠券-修改")
// @SaAdminCheckPermission("coupon:update")
public CzgResult<Void> updateCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
dto.setShopId(shopId);
if ("custom".equals(dto.getValidType())) {
if (dto.getValidEndTime().isBefore(LocalDateTime.now())) {
dto.setStatus(0);
}
}
if (dto.getStatus().equals(0)) {
//优惠券禁用 同步下架积分优惠券商品
pointsGoodsSettingService.updateGoodsCouponStatus(dto.getId());
}
shopCouponService.updateCouponById(dto);
couponGiftService.upCouponName(dto.getId(), dto.getTitle());
asyncToBranchShop(dto.getId(), 2);
@@ -122,6 +142,8 @@ public class ACouponController {
}
shopCouponService.deleteCoupon(id);
couponGiftService.deleteCoupon(id);
//优惠券删除 同步下架积分优惠券商品
pointsGoodsSettingService.updateGoodsCouponStatus(id);
asyncToBranchShop(id, 3);
return CzgResult.success();
}

View File

@@ -4,9 +4,12 @@ import cn.hutool.core.bean.BeanUtil;
import com.czg.BaseQueryParam;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.enums.DeleteEnum;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkPointsGoodsDTO;
import com.czg.market.entity.MkPointsGoods;
import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.MkPointsGoodsService;
import com.czg.market.service.ShopCouponService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
@@ -14,6 +17,8 @@ import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
/**
* 积分商城
@@ -26,6 +31,8 @@ public class PointsGoodsController {
@Resource
private MkPointsGoodsService pointsGoodsSettingService;
@Resource
private ShopCouponService shopCouponService;
/**
* 积分:商品:列表
@@ -53,6 +60,17 @@ public class PointsGoodsController {
@SaAdminCheckPermission(parentName = "积分相关", value = "points:goods:up", name = "积分-商品-新增/修改")
public CzgResult<Boolean> addPointsGoodsSetting(@RequestBody @Validated MkPointsGoodsDTO dto) {
dto.setShopId(StpKit.USER.getShopId());
if (dto.getCouponId() != null) {
ShopCoupon coupon = shopCouponService.getById(dto.getCouponId());
if (coupon == null || coupon.getIsDel() == DeleteEnum.DELETED.value() || coupon.getStatus() != 1) {
throw new CzgException("操作失败,优惠券已删除或未启用");
}
if ("custom".equals(coupon.getValidType())) {
if (coupon.getValidEndTime().isBefore(LocalDateTime.now())) {
throw new CzgException("操作失败,对应的优惠券已过期");
}
}
}
MkPointsGoods entity = BeanUtil.copyProperties(dto, MkPointsGoods.class);
boolean ret;
if (entity.getId() == null) {

View File

@@ -1,8 +1,14 @@
package com.czg.task;
import cn.hutool.core.collection.CollUtil;
import com.czg.config.RedisCst;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkPointsGoods;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.MkPointsGoodsService;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.ShopCouponService;
import com.czg.service.RedisService;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
@@ -26,7 +32,11 @@ public class CouponTask {
@Resource
private MkShopCouponRecordService mkShopCouponRecordService;
@Resource
private ShopCouponService shopCouponService;
@Resource
private RedisService redisService;
@Resource
private MkPointsGoodsService pointsGoodsService;
/**
* 优惠券 过期
@@ -34,7 +44,20 @@ public class CouponTask {
// @Scheduled(cron = "0 30 * * * ? ")
public void task() {
try {
//优惠券 到期 积分商品同步下架
LocalDateTime now = LocalDateTime.now();
QueryWrapper queryWrapper = QueryWrapper.create().eq(ShopCoupon::getStatus, 1)
.eq(ShopCoupon::getValidType, "custom")
.lt(ShopCoupon::getValidEndTime, now);
List<Long> ids = shopCouponService.listAs(queryWrapper, Long.class);
shopCouponService.update(new ShopCoupon().setStatus(0), queryWrapper);
if (CollUtil.isNotEmpty(ids)) {
MkPointsGoods upMkPointsGoods = new MkPointsGoods();
upMkPointsGoods.setStatus(0);
pointsGoodsService.update(upMkPointsGoods, QueryWrapper.create().in(MkPointsGoods::getCouponId, ids));
}
mkShopCouponRecordService.update(new MkShopCouponRecord().setStatus(2), new QueryWrapper()
.eq(MkShopCouponRecord::getStatus, 0)
.le(MkShopCouponRecord::getUseEndTime, now)

View File

@@ -4,6 +4,7 @@ import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -14,6 +15,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* 积分商品设置 实体类。
@@ -26,6 +28,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Table("mk_points_goods")
@Accessors(chain = true)
public class MkPointsGoods implements Serializable {
@Serial
@@ -133,5 +136,4 @@ public class MkPointsGoods implements Serializable {
private ShopCoupon couponInfo;
}

View File

@@ -36,4 +36,7 @@ public interface MkPointsGoodsService extends IService<MkPointsGoods> {
* @param totalExchangeCount 累计兑换数量 最终值
*/
boolean upNumberById(Long id, Integer quantity, Integer totalExchangeCount);
void updateGoodsCouponStatus(Long coupon);
}

View File

@@ -68,6 +68,10 @@ public class OrderInfoVo implements Serializable {
* 台桌名称
*/
private String tableName;
/**
* 取餐码
*/
private String takeCode;
/**
* 订单类型-

View File

@@ -45,6 +45,7 @@ public class MkPointsGoodsRecordServiceImpl extends ServiceImpl<MkPointsGoodsRec
.eq(MkPointsGoodsRecord::getIsDel, 0)
.like(MkPointsGoodsRecord::getPointsGoodsName, param.getPointsGoodsName())
.like(MkPointsGoodsRecord::getGoodsCategory, param.getGoodsCategory())
.orderBy(MkPointsGoodsRecord::getCreateTime, false)
, MkPointsGoodsRecordDTO.class);
pages.getRecords().forEach(data -> {
data.fillCouponInfo();

View File

@@ -100,11 +100,9 @@ public class MkPointsGoodsServiceImpl extends ServiceImpl<MkPointsGoodsMapper, M
} else {
queryWrapper.eq(MkPointsGoodsRecord::getStatus, status);
queryWrapper.orderBy(MkPointsGoodsRecord::getStatus, false);
queryWrapper.orderBy(MkPointsGoodsRecord::getCreateTime, false);
}
} else {
queryWrapper.orderBy(MkPointsGoodsRecord::getCreateTime, false);
}
queryWrapper.orderBy(MkPointsGoodsRecord::getCreateTime, false);
Page<MkPointsGoodsRecord> pages = goodsRecordService.page(Page.of(page, size), queryWrapper);
pages.getRecords().forEach(MkPointsGoodsRecord::fillCouponInfo);
return pages;
@@ -159,4 +157,11 @@ public class MkPointsGoodsServiceImpl extends ServiceImpl<MkPointsGoodsMapper, M
return updateById(goodUp);
}
@Override
public void updateGoodsCouponStatus(Long couponId) {
MkPointsGoods upMkPointsGoods = new MkPointsGoods();
upMkPointsGoods.setStatus(0);
update(upMkPointsGoods, query().eq(MkPointsGoods::getCouponId, couponId));
}
}