bug fix --商品是否可售控制

This commit is contained in:
Tankaikai 2025-04-17 10:14:20 +08:00
parent 855d7e7ea4
commit 9615aa33b3
5 changed files with 13 additions and 12 deletions

View File

@ -2,7 +2,6 @@ package com.czg.controller.admin;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import com.czg.account.service.ShopConfigService;
import com.czg.annotation.SaStaffCheckPermission; import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher; import com.czg.config.RabbitPublisher;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
@ -15,6 +14,7 @@ import com.czg.product.param.*;
import com.czg.product.service.ProdConsRelationService; import com.czg.product.service.ProdConsRelationService;
import com.czg.product.service.ProductService; import com.czg.product.service.ProductService;
import com.czg.product.service.ShopSyncService; import com.czg.product.service.ShopSyncService;
import com.czg.product.service.UProductService;
import com.czg.product.vo.ProductStatisticsVo; import com.czg.product.vo.ProductStatisticsVo;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@ -48,7 +48,7 @@ public class ProductController {
@Resource @Resource
private ShopSyncService shopSyncService; private ShopSyncService shopSyncService;
@Resource @Resource
private ShopConfigService shopConfigService; private UProductService uProductService;
/** /**
* 商品-分页 * 商品-分页
@ -72,6 +72,9 @@ public class ProductController {
param.setShopId(shopId); param.setShopId(shopId);
List<ProductDTO> productList = productService.getProductCacheList(param); List<ProductDTO> productList = productService.getProductCacheList(param);
productService.refreshProductStock(param, productList); productService.refreshProductStock(param, productList);
productList.forEach(prod -> {
prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime()));
});
return CzgResult.success(productList); return CzgResult.success(productList);
} }

View File

@ -61,7 +61,7 @@ public class UProductController {
uProductService.refreshProductStock(productStock, item.getProductList()); uProductService.refreshProductStock(productStock, item.getProductList());
item.getProductList().forEach(prod -> { item.getProductList().forEach(prod -> {
prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime())); prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getDays(), prod.getStartTime(), prod.getEndTime()));
prod.setIsSaleTime(uProductService.calcIsSaleTime(item.getUseTime(), item.getSaleStartTime(), item.getSaleEndTime())); prod.setIsSaleTime(uProductService.calcIsSaleTime(prod.getIsSaleTime(), item.getUseTime(), item.getSaleStartTime(), item.getSaleEndTime()));
}); });
}); });
return CzgResult.success(list); return CzgResult.success(list);

View File

@ -78,12 +78,13 @@ public interface UProductService extends IService<Product> {
/** /**
* 分组计算是否在可售时间内 * 分组计算是否在可售时间内
* *
* @param prodIsSaleTime 商品是否可售
* @param useTime 开启时间管控 0:1: * @param useTime 开启时间管控 0:1:
* @param startTime 起售时间 * @param startTime 起售时间
* @param endTime 停售时间 * @param endTime 停售时间
* @return 是否可售时间 1-0- * @return 是否可售时间 1-0-
*/ */
Integer calcIsSaleTime(Integer useTime, LocalTime startTime, LocalTime endTime); Integer calcIsSaleTime(int prodIsSaleTime, Integer useTime, LocalTime startTime, LocalTime endTime);
/** /**
* 商品计算是否在可售时间内 * 商品计算是否在可售时间内

View File

@ -407,12 +407,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
} }
super.updateById(entity); super.updateById(entity);
// 清除商品分类列表缓存 // 清除商品分类列表缓存
Long categoryId = ObjUtil.defaultIfNull(dto.getCategoryId(), old.getCategoryId());
if (!old.getCategoryId().equals(categoryId)) {
// 清除旧分类缓存&新分类缓存
clearProductCache(old.getCategoryId(), entity.getCategoryId());
} else {
clearProductCache(old.getCategoryId()); clearProductCache(old.getCategoryId());
if (!old.getCategoryId().equals(dto.getCategoryId())) {
clearProductCache(entity.getCategoryId());
} }
if (ObjUtil.defaultIfNull(dto.getIsStock(), old.getIsStock()) == YesNoEnum.NO.value()) { if (ObjUtil.defaultIfNull(dto.getIsStock(), old.getIsStock()) == YesNoEnum.NO.value()) {
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId())); redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId()));

View File

@ -233,9 +233,9 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
* @return 是否可售时间 1-0- * @return 是否可售时间 1-0-
*/ */
@Override @Override
public Integer calcIsSaleTime(Integer useTime, LocalTime startTime, LocalTime endTime) { public Integer calcIsSaleTime(int prodIsSaleTime, Integer useTime, LocalTime startTime, LocalTime endTime) {
if (NumberUtil.nullToZero(useTime) == 0) { if (NumberUtil.nullToZero(useTime) == 0) {
return YesNoEnum.YES.value(); return prodIsSaleTime;
} }
if (ObjUtil.isNull(startTime) || ObjUtil.isNull(endTime)) { if (ObjUtil.isNull(startTime) || ObjUtil.isNull(endTime)) {
return YesNoEnum.NO.value(); return YesNoEnum.NO.value();