小程序主页接口

This commit is contained in:
张松
2025-03-07 11:21:41 +08:00
parent 2568da4a10
commit e0239e0686
6 changed files with 127 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ package com.czg.service.product.mapper;
import com.czg.product.dto.ProductDTO;
import com.czg.product.entity.Product;
import com.czg.product.vo.RecommendProVO;
import com.czg.product.vo.ShopProductInfoVo;
import com.czg.product.vo.ShopProductVo;
import com.mybatisflex.core.BaseMapper;
@@ -37,4 +38,8 @@ public interface ProductMapper extends BaseMapper<Product> {
List<Product> selectCouponProBySaleNum();
void updateProductStockNum(@Param("id") Long id, @Param("shopId") Long shopId, @Param("type") String type, @Param("num") BigDecimal num);
}
List<RecommendProVO> selectRecommendProductList(@Param("lng") String lng, @Param("lat") String lat, @Param("address") String address,
@Param("classify") Integer classify, @Param("orderType") Integer orderType,
@Param("distanceType") Integer distanceType);
}

View File

@@ -15,10 +15,13 @@ import com.czg.enums.LogoEnum;
import com.czg.product.entity.Product;
import com.czg.product.service.ProdSkuService;
import com.czg.product.service.ProductService;
import com.czg.product.vo.RecommendProVO;
import com.czg.service.product.mapper.ProductMapper;
import com.czg.utils.JoinQueryWrapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
@@ -107,14 +110,8 @@ public class HomePageServiceImpl implements HomePageService {
}
@Override
public Object getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
QueryWrapper queryWrapper = new QueryWrapper();
if (StrUtil.isNotBlank(address)) {
queryWrapper.and(JoinQueryWrapper.column(ShopInfo::getCities).like(address).or(JoinQueryWrapper.column(ShopInfo::getDistricts).like(address)));
}
if (classify != null) {
queryWrapper.eq(Product::getCategoryId, classify);
}
return null;
public Page<RecommendProVO> getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(productMapper.selectRecommendProductList(lng, lat, address, classify, orderType, distanceType)));
}
}

View File

@@ -94,7 +94,7 @@
t1.pack_fee
from tb_product t1
left join (select x.product_id,
x.id as sku_id,
x.id as sku_id,
MIN(x.sale_price) as sale_price,
x.origin_price,
x.member_price,
@@ -104,7 +104,7 @@
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
left join tb_shop_prod_unit t3 on t1.unit_id = t3.id
</sql>
<select id="selectProductPage" resultType="com.czg.product.dto.ProductDTO">
<include refid="productQuery"/>
@@ -160,6 +160,37 @@
ORDER BY b.real_sales_number
LIMIT 2
</select>
<select id="selectRecommendProductList" resultType="com.czg.product.vo.RecommendProVO">
select ROUND(
ST_Distance_Sphere(POINT(b.lng, b.lat), POINT(#{lng}, #{lat})) / 1000, 2) AS distance,
c.name, a.origin_price, a.sale_price, b.shop_name, b.districts, c.cover_img, b.logo, c.id,
a.real_sales_number saleNum, round(a.sale_price / a.origin_price, 2) discount,
c.id productId, a.id skuId, b.id shopId
from tb_prod_sku as a
left join tb_product c on c.id=a.product_id
left join tb_shop_info as b on a.shop_id=b.id
where c.id is not null
<if test="address != null and address != ''">
and (b.cities like concat('%', #{address}, '%') or b.districts like concat('%', #{address}, '%'))
</if>
<if test="classify != null">
and c.category_id = #{classify}
</if>
<if test="distanceType != null">
and ST_Distance_Sphere(POINT(b.lng, b.lat), POINT(#{lng}, #{lat})) &lt;= #{distanceType}
</if>
<if test="orderType == 0">
ORDER BY distance
</if>
<if test="orderType == 1">
ORDER BY a.real_sales_number desc
</if>
<if test="orderType == 2">
ORDER BY a.sale_price
</if>
</select>
<update id="updateProductStockNum">
update tb_product
<if test="type == 'add'">
@@ -169,7 +200,7 @@
set stock_number = stock_number - #{num}
</if>
where id = #{id}
and is_stock = 1
and shop_id = #{shopId}
and is_stock = 1
and shop_id = #{shopId}
</update>
</mapper>