商品模块代码提交

This commit is contained in:
Tankaikai
2025-02-19 11:47:57 +08:00
parent a3e1e45a4e
commit 166250c654
9 changed files with 202 additions and 9 deletions

View File

@@ -1,8 +1,12 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.Product;
import com.czg.product.vo.HotsProductVo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 商品
@@ -12,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ProductMapper extends BaseMapper<Product> {
List<HotsProductVo> queryHotsProductList(@Param("shopId") Long shopId);
}

View File

@@ -1,6 +1,8 @@
package com.czg.service.product.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.enums.DeleteEnum;
import com.czg.enums.StatusEnum;
import com.czg.enums.YesNoEnum;
@@ -12,6 +14,7 @@ import com.czg.product.entity.ProdSku;
import com.czg.product.entity.Product;
import com.czg.product.param.MiniHomeProductParam;
import com.czg.product.service.UProductService;
import com.czg.product.vo.HotsProductVo;
import com.czg.product.vo.MiniAppHomeProdGroupVo;
import com.czg.product.vo.MiniAppHomeProductInfoVo;
import com.czg.product.vo.MiniAppHomeProductVo;
@@ -160,6 +163,37 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
return vo;
}
@Override
public List<HotsProductVo> queryHotsProductList() {
Long shopId = StpKit.USER.getShopId(0L);
List<HotsProductVo> list = productMapper.queryHotsProductList(shopId);
list.forEach(item -> {
item.setIsSaleTime(calcIsSaleTime(item.getDays(), item.getStartTime(), item.getEndTime()));
});
return list;
}
/**
* 计算是否在可售时间内
*
* @param days 星期几,例如 "Monday,Tuesday"
* @param startTime 起售时间
* @param endTime 停售时间
* @return 是否可售时间 1-是0-否
*/
private Integer calcIsSaleTime(String days, LocalTime startTime, LocalTime endTime) {
if (StrUtil.isBlank(days) || ObjUtil.isNull(startTime) || ObjUtil.isNull(endTime)) {
return YesNoEnum.NO.value();
}
String today = getWeekDayEnName();
List<String> dayList = StrUtil.split(days, ",");
LocalTime now = LocalTime.now().withNano(0);
if (CollUtil.contains(dayList, today) && now.isAfter(startTime) && now.isBefore(endTime)) {
return YesNoEnum.YES.value();
}
return YesNoEnum.NO.value();
}
/**
* 获取当前日期是星期几的英文名称
*

View File

@@ -3,4 +3,33 @@
<mapper namespace="com.czg.service.product.mapper.ProductMapper">
<select id="queryHotsProductList" resultType="com.czg.product.vo.HotsProductVo">
select
t1.id,
t1.name,
t2.origin_price,
t2.sale_price,
t2.member_price,
t1.cover_img,
t3.name as unit_name,
t1.is_sold_stock,
t1.stock_number,
t1.type,
t1.group_type,
t1.days,
t1.start_time,
t1.end_time
from tb_product t1
left join (select x.product_id,MIN(x.sale_price) as sale_price,x.origin_price,x.member_price from tb_prod_sku x
where x.is_del=0 and x.is_grounding = 1 and x.shop_id = #{shopId} group by x.product_id) t2 on t1.id =
t2.product_id
left join tb_shop_prod_unit t3 on t1.unit_id = t3.id
<where>
and t1.is_del = 0
and t1.is_sale = 1
and t1.is_hot = 1
and t1.shop_id = #{shopId}
</where>
order by t1.sort desc,t1.id desc
</select>
</mapper>