小程序主页接口
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package com.czg.controller.user;
|
package com.czg.controller.user;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.czg.account.vo.home.HomePageVO;
|
||||||
import com.czg.product.service.HomePageService;
|
import com.czg.product.service.HomePageService;
|
||||||
|
import com.czg.product.vo.RecommendProVO;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -19,8 +22,12 @@ public class HomeController {
|
|||||||
@Resource
|
@Resource
|
||||||
private HomePageService homePageService;
|
private HomePageService homePageService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主页上部分
|
||||||
|
* 快捷菜单区域 今日上新 飙升热榜 免单信息
|
||||||
|
*/
|
||||||
@GetMapping("/homePageUp")
|
@GetMapping("/homePageUp")
|
||||||
public CzgResult<?> homePageUp() {
|
public CzgResult<HomePageVO> homePageUp() {
|
||||||
return CzgResult.success(homePageService.getHomeInfo());
|
return CzgResult.success(homePageService.getHomeInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,13 +36,13 @@ public class HomeController {
|
|||||||
* @param lng 纬度
|
* @param lng 纬度
|
||||||
* @param lat 经度
|
* @param lat 经度
|
||||||
* @param address 城市
|
* @param address 城市
|
||||||
* @param classify 分类 0双人餐 1饮品明细 2咖啡饮品
|
* @param categoryId 分类 0双人餐 1饮品明细 2咖啡饮品
|
||||||
* @param orderType 排序规则 0离我最近 1销量优先 2价格优先
|
* @param orderType 排序规则 0离我最近 1销量优先 2价格优先
|
||||||
* @param distanceType 1一千米
|
* @param distanceType 1000m 2000m
|
||||||
* @return 商品列表
|
* @return 商品列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/product")
|
@GetMapping("/product")
|
||||||
public CzgResult<?> home(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
|
public CzgResult<Page<RecommendProVO>> home(String lng, String lat, String address, Integer categoryId, Integer orderType, Integer distanceType) {
|
||||||
return CzgResult.success(homePageService.getProd(lng, lat, address, classify, orderType, distanceType));
|
return CzgResult.success(homePageService.getProd(lng, lat, address, categoryId, orderType, distanceType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.czg.product.service;
|
package com.czg.product.service;
|
||||||
|
|
||||||
import com.czg.account.vo.home.HomePageVO;
|
import com.czg.account.vo.home.HomePageVO;
|
||||||
|
import com.czg.product.vo.RecommendProVO;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
@@ -8,6 +10,6 @@ import com.czg.account.vo.home.HomePageVO;
|
|||||||
public interface HomePageService {
|
public interface HomePageService {
|
||||||
HomePageVO getHomeInfo();
|
HomePageVO getHomeInfo();
|
||||||
|
|
||||||
Object getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType);
|
Page<RecommendProVO> getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.czg.product.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RecommendProVO {
|
||||||
|
/**
|
||||||
|
* 距离单位km
|
||||||
|
*/
|
||||||
|
private double distance;
|
||||||
|
/**
|
||||||
|
* 商品名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 原始价格
|
||||||
|
*/
|
||||||
|
private BigDecimal originPrice;
|
||||||
|
/**
|
||||||
|
* 售卖价格
|
||||||
|
*/
|
||||||
|
private BigDecimal salePrice;
|
||||||
|
/**
|
||||||
|
* 商品图片
|
||||||
|
*/
|
||||||
|
private String coverImg;
|
||||||
|
/**
|
||||||
|
* 店铺名称
|
||||||
|
*/
|
||||||
|
private String shopName;
|
||||||
|
/**
|
||||||
|
* 市区
|
||||||
|
*/
|
||||||
|
private String districts;
|
||||||
|
/**
|
||||||
|
* 店铺logo
|
||||||
|
*/
|
||||||
|
private String logo;
|
||||||
|
/**
|
||||||
|
* 商品id
|
||||||
|
*/
|
||||||
|
private Long productId;
|
||||||
|
/**
|
||||||
|
* skuId
|
||||||
|
*/
|
||||||
|
private Long skuId;
|
||||||
|
/**
|
||||||
|
* 店铺id
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
/**
|
||||||
|
* 销售量
|
||||||
|
*/
|
||||||
|
private Long saleNum;
|
||||||
|
/**
|
||||||
|
* 折扣
|
||||||
|
*/
|
||||||
|
private float discount;
|
||||||
|
private Long endTime = 1741391999999L;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.czg.service.product.mapper;
|
|||||||
|
|
||||||
import com.czg.product.dto.ProductDTO;
|
import com.czg.product.dto.ProductDTO;
|
||||||
import com.czg.product.entity.Product;
|
import com.czg.product.entity.Product;
|
||||||
|
import com.czg.product.vo.RecommendProVO;
|
||||||
import com.czg.product.vo.ShopProductInfoVo;
|
import com.czg.product.vo.ShopProductInfoVo;
|
||||||
import com.czg.product.vo.ShopProductVo;
|
import com.czg.product.vo.ShopProductVo;
|
||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
@@ -37,4 +38,8 @@ public interface ProductMapper extends BaseMapper<Product> {
|
|||||||
List<Product> selectCouponProBySaleNum();
|
List<Product> selectCouponProBySaleNum();
|
||||||
|
|
||||||
void updateProductStockNum(@Param("id") Long id, @Param("shopId") Long shopId, @Param("type") String type, @Param("num") BigDecimal num);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,10 +15,13 @@ import com.czg.enums.LogoEnum;
|
|||||||
import com.czg.product.entity.Product;
|
import com.czg.product.entity.Product;
|
||||||
import com.czg.product.service.ProdSkuService;
|
import com.czg.product.service.ProdSkuService;
|
||||||
import com.czg.product.service.ProductService;
|
import com.czg.product.service.ProductService;
|
||||||
|
import com.czg.product.vo.RecommendProVO;
|
||||||
import com.czg.service.product.mapper.ProductMapper;
|
import com.czg.service.product.mapper.ProductMapper;
|
||||||
import com.czg.utils.JoinQueryWrapper;
|
import com.czg.utils.JoinQueryWrapper;
|
||||||
|
import com.czg.utils.PageUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -107,14 +110,8 @@ public class HomePageServiceImpl implements HomePageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
|
public Page<RecommendProVO> getProd(String lng, String lat, String address, Integer classify, Integer orderType, Integer distanceType) {
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||||
if (StrUtil.isNotBlank(address)) {
|
return PageUtil.convert(new PageInfo<>(productMapper.selectRecommendProductList(lng, lat, address, classify, orderType, distanceType)));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
t1.pack_fee
|
t1.pack_fee
|
||||||
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,
|
||||||
MIN(x.sale_price) as sale_price,
|
MIN(x.sale_price) as sale_price,
|
||||||
x.origin_price,
|
x.origin_price,
|
||||||
x.member_price,
|
x.member_price,
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
and x.is_grounding = 1
|
and x.is_grounding = 1
|
||||||
and x.shop_id = #{shopId}
|
and x.shop_id = #{shopId}
|
||||||
group by x.product_id) t2 on t1.id = t2.product_id
|
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>
|
</sql>
|
||||||
<select id="selectProductPage" resultType="com.czg.product.dto.ProductDTO">
|
<select id="selectProductPage" resultType="com.czg.product.dto.ProductDTO">
|
||||||
<include refid="productQuery"/>
|
<include refid="productQuery"/>
|
||||||
@@ -160,6 +160,37 @@
|
|||||||
ORDER BY b.real_sales_number
|
ORDER BY b.real_sales_number
|
||||||
LIMIT 2
|
LIMIT 2
|
||||||
</select>
|
</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})) <= #{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 id="updateProductStockNum">
|
||||||
update tb_product
|
update tb_product
|
||||||
<if test="type == 'add'">
|
<if test="type == 'add'">
|
||||||
@@ -169,7 +200,7 @@
|
|||||||
set stock_number = stock_number - #{num}
|
set stock_number = stock_number - #{num}
|
||||||
</if>
|
</if>
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
and is_stock = 1
|
and is_stock = 1
|
||||||
and shop_id = #{shopId}
|
and shop_id = #{shopId}
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user