小程序商品返回相关推荐
This commit is contained in:
@@ -9,7 +9,6 @@ import com.czg.product.vo.ShopProductSkuInfoVo;
|
|||||||
import com.czg.product.vo.ShopProductVo;
|
import com.czg.product.vo.ShopProductVo;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.service.RedisService;
|
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.validator.ValidatorUtil;
|
import com.czg.validator.ValidatorUtil;
|
||||||
import com.czg.validator.group.DefaultGroup;
|
import com.czg.validator.group.DefaultGroup;
|
||||||
@@ -34,7 +33,6 @@ import java.util.Map;
|
|||||||
@RequestMapping("/user/product")
|
@RequestMapping("/user/product")
|
||||||
public class UProductController {
|
public class UProductController {
|
||||||
private final UProductService uProductService;
|
private final UProductService uProductService;
|
||||||
private final RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序点餐-热销商品列表
|
* 小程序点餐-热销商品列表
|
||||||
@@ -72,15 +70,6 @@ public class UProductController {
|
|||||||
return CzgResult.success(list);
|
return CzgResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取相关推荐商品
|
|
||||||
*/
|
|
||||||
@GetMapping("/related/{id}")
|
|
||||||
public CzgResult<List<ShopProductVo>> getRelatedProduct(@PathVariable("id") Long id) {
|
|
||||||
AssertUtil.isNull(id, "商品id不能为空");
|
|
||||||
return CzgResult.success(uProductService.queryProductRelatedList(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序点餐-商品详情
|
* 小程序点餐-商品详情
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.czg.product.service;
|
package com.czg.product.service;
|
||||||
|
|
||||||
import com.czg.product.dto.RelatedProductDTO;
|
|
||||||
import com.czg.product.entity.Product;
|
import com.czg.product.entity.Product;
|
||||||
import com.czg.product.param.ShopProductSkuParam;
|
import com.czg.product.param.ShopProductSkuParam;
|
||||||
import com.czg.product.vo.ShopGroupProductVo;
|
import com.czg.product.vo.ShopGroupProductVo;
|
||||||
@@ -96,6 +95,4 @@ public interface UProductService extends IService<Product> {
|
|||||||
* @return 是否可售时间 1-是,0-否
|
* @return 是否可售时间 1-是,0-否
|
||||||
*/
|
*/
|
||||||
Integer calcIsSaleTime(String days, LocalTime startTime, LocalTime endTime);
|
Integer calcIsSaleTime(String days, LocalTime startTime, LocalTime endTime);
|
||||||
|
|
||||||
List<ShopProductVo> queryProductRelatedList(Long productId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package com.czg.product.vo;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品规格详情
|
* 商品规格详情
|
||||||
@@ -109,6 +111,12 @@ public class ShopProductInfoVo implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@JSONField(serialize = false)
|
@JSONField(serialize = false)
|
||||||
private LocalTime endTime;
|
private LocalTime endTime;
|
||||||
|
/**
|
||||||
|
* 相关推荐商品
|
||||||
|
*/
|
||||||
|
private List<ShopProductVo> relatedRecommendJson;
|
||||||
|
@JsonIgnore
|
||||||
|
private String relatedRecommend;
|
||||||
|
|
||||||
public Object getImages() {
|
public Object getImages() {
|
||||||
return JSON.parseArray(Convert.toStr(images, "[]"));
|
return JSON.parseArray(Convert.toStr(images, "[]"));
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.czg.service.product.mapper.ProdGroupMapper;
|
|||||||
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
import com.czg.service.product.mapper.ProdGroupRelationMapper;
|
||||||
import com.czg.service.product.mapper.ProdSkuMapper;
|
import com.czg.service.product.mapper.ProdSkuMapper;
|
||||||
import com.czg.service.product.mapper.ProductMapper;
|
import com.czg.service.product.mapper.ProductMapper;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -132,6 +131,21 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
|||||||
if (data == null) {
|
if (data == null) {
|
||||||
throw new CzgException("商品不可售");
|
throw new CzgException("商品不可售");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StrUtil.isBlank(data.getRelatedRecommend()) || "[]".equals(data.getRelatedRecommend())) {
|
||||||
|
data.setRelatedRecommendJson(new ArrayList<>());
|
||||||
|
} else {
|
||||||
|
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(shopId, JSONArray.parseArray(data.getRelatedRecommend(), Long.class));
|
||||||
|
productAllList.forEach(item -> {
|
||||||
|
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query()
|
||||||
|
.eq(ProdSku::getProductId, item.getId())
|
||||||
|
.eq(ProdSku::getIsGrounding, SystemConstants.OneZero.ONE)
|
||||||
|
.eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
||||||
|
item.setSkuList(skuList);
|
||||||
|
});
|
||||||
|
data.setRelatedRecommendJson(productAllList);
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,31 +249,6 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
|||||||
return SystemConstants.OneZero.ZERO;
|
return SystemConstants.OneZero.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ShopProductVo> queryProductRelatedList(Long productId) {
|
|
||||||
Product product = getOne(QueryWrapper.create().eq(Product::getId, productId)
|
|
||||||
.eq(Product::getShopId, StpKit.USER.getShopId())
|
|
||||||
.eq(Product::getIsDel, SystemConstants.OneZero.ZERO));
|
|
||||||
|
|
||||||
if (product == null) {
|
|
||||||
throw new CzgException("商品信息不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StrUtil.isBlank(product.getRelatedRecommend()) || "[]".equals(product.getRelatedRecommend())) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ShopProductVo> productAllList = productMapper.selectGroupProductList(product.getShopId(), JSONArray.parseArray(product.getRelatedRecommend(), Long.class));
|
|
||||||
productAllList.forEach(item -> {
|
|
||||||
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query()
|
|
||||||
.eq(ProdSku::getProductId, item.getId())
|
|
||||||
.eq(ProdSku::getIsGrounding, SystemConstants.OneZero.ONE)
|
|
||||||
.eq(ProdSku::getIsDel, SystemConstants.OneZero.ZERO), ProdSkuDTO.class);
|
|
||||||
item.setSkuList(skuList);
|
|
||||||
});
|
|
||||||
return productAllList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算是否在可售时间内
|
* 计算是否在可售时间内
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -95,7 +95,8 @@
|
|||||||
t1.pack_fee,
|
t1.pack_fee,
|
||||||
ifnull(t4.sales_volume, 0) as sales_volume,
|
ifnull(t4.sales_volume, 0) as sales_volume,
|
||||||
t1.shop_id,
|
t1.shop_id,
|
||||||
t1.is_stock
|
t1.is_stock,
|
||||||
|
t1.related_recommend
|
||||||
from tb_product t1
|
from tb_product t1
|
||||||
left join (select x.product_id,
|
left join (select x.product_id,
|
||||||
x.id as sku_id,
|
x.id as sku_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user