Ver código fonte

为你推荐新增渠道逻辑

zhangxin 2 semanas atrás
pai
commit
a6aed6dd6e

+ 8 - 6
yami-shop-api/src/main/java/com/yami/shop/api/controller/ProdController.java

@@ -94,24 +94,26 @@ public class ProdController {
             String userId = user.getUserId();
             if (StringUtils.isNotEmpty(userId)) {
                 UserShopBehavior userShopBehavior = null;
-                userShopBehavior = userShopBehaviorService.findByUserIdAndProd(userId, prodId);
+                userShopBehavior = userShopBehaviorService.findByUserIdAndProd(userId,shopId, prodId,channelId);
                 if (userShopBehavior == null) {
                     int num = userShopBehaviorService.findByUserIdCount(userId);
                     if (num < 6) {
                         userShopBehavior = new UserShopBehavior();
                         userShopBehavior.setUserId(userId);
                         userShopBehavior.setShopId(shopId);
+                        userShopBehavior.setChannelId(channelId);
                         userShopBehavior.setProdId(prodId);
                         userShopBehavior.setCreateTime(new Date());
                         userShopBehaviorService.save(userShopBehavior);
                     } else {
-                        List<UserShopBehavior> userShopBehaviors = userShopBehaviorService.findByUserId(userId, 1);
+                        List<UserShopBehavior> userShopBehaviors = userShopBehaviorService.findByUserId(userId, 1, shopId,channelId);
                         if (userShopBehaviors != null && !userShopBehaviors.isEmpty()) {
                             userShopBehavior = userShopBehaviors.get(0);
                         }
                         if (userShopBehavior != null) {
                             userShopBehavior.setProdId(prodId);
                             userShopBehavior.setShopId(shopId);
+                            userShopBehavior.setChannelId(channelId);
                             userShopBehavior.setCreateTime(new Date());
                             userShopBehaviorService.updateById(userShopBehavior);
                         }
@@ -216,7 +218,7 @@ public class ProdController {
 
     @GetMapping("/prodRecommended")
     @ApiOperation(value = "为你推荐", notes = "为你推荐")
-    public ResponseEntity<IPage<SearchProdDto>> getProdRecommended(PageParam<SearchProdDto> page) {
+    public ResponseEntity<IPage<SearchProdDto>> getProdRecommended(PageParam<SearchProdDto> page,@RequestParam("shopId") Long shopId,@RequestParam("channelId") Long channelId) {
         IPage<SearchProdDto>   searchProdDtos = page;
         List<ProductDto> productDtos = new ArrayList<>();
         YamiUser user = null;
@@ -229,9 +231,9 @@ public class ProdController {
         if (user != null) {
             String userId = user.getUserId();
             if (StringUtils.isNotEmpty(userId)) {
-                List<UserShopBehavior> byUserId = userShopBehaviorService.findByUserId(userId, 5);
+                List<UserShopBehavior> byUserId = userShopBehaviorService.findByUserId(userId, 5,shopId,channelId);
                 for (UserShopBehavior userShopBehavior : byUserId) {
-                    ChannelProd channelProd = userShopBehaviorService.findByProdId(userShopBehavior.getProdId(), userShopBehavior.getShopId());
+                    ChannelProd channelProd = userShopBehaviorService.findByProdId(userShopBehavior.getProdId(), userShopBehavior.getShopId(),channelId);
                     if (channelProd != null) {
                         BigDecimal channelProdPrice = channelProd.getChannelProdPrice();
                         if (channelProdPrice != null) {
@@ -239,7 +241,7 @@ public class ProdController {
                                     .setScale(2, RoundingMode.HALF_UP);
                             BigDecimal decreased = channelProdPrice.multiply(new BigDecimal("0.90"))
                                     .setScale(2, RoundingMode.HALF_UP);
-                            List<ProductDto> productDtoList = userShopBehaviorService.findByProdIdAndShopIdAndPrice(userShopBehavior.getProdId(), userShopBehavior.getShopId(), increased, decreased);
+                            List<ProductDto> productDtoList = userShopBehaviorService.findByProdIdAndShopIdAndPrice(userShopBehavior.getProdId(), userShopBehavior.getShopId(),channelId, increased, decreased);
                             if (productDtoList != null && !productDtoList.isEmpty()) {
                                 productDtos.addAll(productDtoList);
                             }

+ 3 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/UserShopBehavior.java

@@ -40,6 +40,9 @@ public class UserShopBehavior implements Serializable {
     @ApiModelProperty(value = "店铺id",required=true)
     private Long shopId;
 
+    @ApiModelProperty(value = "渠道id",required=true)
+    private Long channelId;
+
     @ApiModelProperty(value = "创建时间",required=true)
     private Date createTime;
 }

+ 2 - 2
yami-shop-service/src/main/java/com/yami/shop/dao/ProductMapper.java

@@ -185,9 +185,9 @@ public interface ProductMapper extends BaseMapper<Product> {
      */
     Product selectByHbSpuId(@Param("hbSpuId") String hbSpuId);
 
-    ChannelProd findByProdIdAndShopId(@Param("prodId")Long prodId,@Param("shopId") Long shopId);
+    ChannelProd findByProdIdAndShopId(@Param("prodId")Long prodId,@Param("shopId") Long shopId,@Param("channelId") Long channelId);
 
-    List<ProductDto> findByProdIdAndShopIdAndPrice(@Param("prodId")Long prodId, @Param("shopId")Long shopId, @Param("increased")BigDecimal increased, @Param("decreased")BigDecimal decreased);
+    List<ProductDto> findByProdIdAndShopIdAndPrice(@Param("prodId")Long prodId, @Param("shopId")Long shopId,@Param("channelId") Long channelId, @Param("increased")BigDecimal increased, @Param("decreased")BigDecimal decreased);
 
     IPage<SearchProdDto> findByProdAndShop(@Param("page") PageParam<SearchProdDto> page, @Param("list")List<ProductDto> productDtos);
 

+ 2 - 2
yami-shop-service/src/main/java/com/yami/shop/dao/UserShopBehaviorMapper.java

@@ -21,7 +21,7 @@ import java.util.List;
 public interface UserShopBehaviorMapper extends BaseMapper<UserShopBehavior> {
     int findByUserIdCount(@Param("userId") String userId);
 
-    List<UserShopBehavior> findByUserId(@Param("userId")String userId,@Param("num")Integer num);
+    List<UserShopBehavior> findByUserId(@Param("userId")String userId,@Param("num")Integer num,@Param("shopId") Long shopId,@Param("channelId") Long channelId);
 
-    UserShopBehavior findByUserIdAndProd(@Param("userId")String userId,@Param("prodId") Long prodId);
+    UserShopBehavior findByUserIdAndProd(@Param("userId")String userId,@Param("shopId")Long shopId,@Param("prodId") Long prodId,@Param("channelId")Long channelId);
 }

+ 5 - 4
yami-shop-service/src/main/java/com/yami/shop/service/UserShopBehaviorService.java

@@ -19,6 +19,7 @@ import com.yami.shop.bean.model.Area;
 import com.yami.shop.bean.model.ChannelProd;
 import com.yami.shop.bean.model.UserShopBehavior;
 import com.yami.shop.common.util.PageParam;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -41,7 +42,7 @@ public interface UserShopBehaviorService extends IService<UserShopBehavior> {
      * @param num 取前几条数据
      * @return
      */
-    List<UserShopBehavior> findByUserId(String userId,Integer num);
+    List<UserShopBehavior> findByUserId(String userId,Integer num, Long shopId, Long channelId);
 
     /**
      * 根据用户id和商品id查询当前用户是否有查询同一商品的痕迹
@@ -49,11 +50,11 @@ public interface UserShopBehaviorService extends IService<UserShopBehavior> {
      * @param prodId
      * @return
      */
-    UserShopBehavior findByUserIdAndProd(String userId, Long prodId);
+    UserShopBehavior findByUserIdAndProd(String userId,Long shopId, Long prodId,Long channelId);
 
-    ChannelProd findByProdId(Long prodId, Long shopId);
+    ChannelProd findByProdId(Long prodId, Long shopId,Long channelId);
 
-    List<ProductDto> findByProdIdAndShopIdAndPrice(Long prodId, Long shopId, BigDecimal increased, BigDecimal decreased);
+    List<ProductDto> findByProdIdAndShopIdAndPrice(Long prodId, Long shopId,Long channelId, BigDecimal increased, BigDecimal decreased);
 
     IPage<SearchProdDto> findByProdAndShop(PageParam<SearchProdDto> page, List<ProductDto> productDtos,String userId);
 

+ 8 - 8
yami-shop-service/src/main/java/com/yami/shop/service/impl/UserShopBehaviorServiceImpl.java

@@ -56,23 +56,23 @@ public class UserShopBehaviorServiceImpl extends ServiceImpl<UserShopBehaviorMap
     }
 
     @Override
-    public List<UserShopBehavior> findByUserId(String userId,Integer num) {
-        return baseMapper.findByUserId(userId,num);
+    public List<UserShopBehavior> findByUserId(String userId,Integer num, Long shopId, Long channelId) {
+        return baseMapper.findByUserId(userId,num,shopId,channelId);
     }
 
     @Override
-    public UserShopBehavior findByUserIdAndProd(String userId, Long prodId) {
-        return baseMapper.findByUserIdAndProd(userId,prodId);
+    public UserShopBehavior findByUserIdAndProd(String userId,Long shopId, Long prodId,Long channelId) {
+        return baseMapper.findByUserIdAndProd(userId,shopId,prodId,channelId);
     }
 
     @Override
-    public ChannelProd findByProdId(Long prodId, Long shopId) {
-        return productMapper.findByProdIdAndShopId(prodId,shopId);
+    public ChannelProd findByProdId(Long prodId, Long shopId,Long channelId) {
+        return productMapper.findByProdIdAndShopId(prodId,shopId,channelId);
     }
 
     @Override
-    public List<ProductDto> findByProdIdAndShopIdAndPrice(Long prodId, Long shopId, BigDecimal increased, BigDecimal decreased) {
-        return productMapper.findByProdIdAndShopIdAndPrice(prodId,shopId,increased,decreased);
+    public List<ProductDto> findByProdIdAndShopIdAndPrice(Long prodId, Long shopId,Long channelId, BigDecimal increased, BigDecimal decreased) {
+        return productMapper.findByProdIdAndShopIdAndPrice(prodId,shopId,channelId,increased,decreased);
     }
 
     @Override

+ 2 - 1
yami-shop-service/src/main/resources/mapper/ProductMapper.xml

@@ -925,7 +925,7 @@
     <select id="findByProdIdAndShopId" resultType="com.yami.shop.bean.model.ChannelProd">
         select a.* from tz_channel_prod a
         INNER join  tz_sku b  on  b.prod_id = #{prodId} and b.sku_id = a.sku_id and b.is_delete = 0
-        where a.shop_id=#{shopId} and a.is_delete = 0 ORDER BY a.channel_prod_price  LIMIT 1
+        where a.shop_id=#{shopId} and a.channel_id = #{channelId} and a.is_delete = 0 ORDER BY a.channel_prod_price  LIMIT 1
     </select>
 
     <select id="findByProdIdAndShopIdAndPrice" resultType="com.yami.shop.bean.app.dto.ProductDto">
@@ -943,6 +943,7 @@
         LEFT JOIN (SELECT count(h.order_item_id) as count,h.prod_id  from  tz_order g LEFT JOIN tz_order_item h on g.order_number = h.order_number where g.refund_status is null and g.delete_status and g.hb_order_status = 80 GROUP BY h.prod_id) i on d.prod_id = i.prod_id -- 统计销量
         WHERE a.prod_id = #{prodId}
         AND d.shop_id = #{shopId}
+        AND f.channel_id = #{channelId}
         AND b.`level` = 2
         and a.is_delete =0
         ORDER BY i.count DESC limit 6

+ 2 - 2
yami-shop-service/src/main/resources/mapper/UserShopBehaviorMapper.xml

@@ -8,9 +8,9 @@
 
     </select>
     <select id="findByUserId" resultType="com.yami.shop.bean.model.UserShopBehavior">
-        select * from tz_user_shop_behavior  where user_id = #{userId} order by create_time limit #{num}
+        select * from tz_user_shop_behavior  where user_id = #{userId} and channel_id = #{channelId} and shop_id = #{shopId} order by create_time limit #{num}
     </select>
     <select id="findByUserIdAndProd" resultType="com.yami.shop.bean.model.UserShopBehavior">
-        select * from tz_user_shop_behavior  where user_id = #{userId} and prod_id =#{prodId}
+        select * from tz_user_shop_behavior  where user_id = #{userId} and prod_id =#{prodId} and channel_id = #{channelId} and shop_id = #{shopId}
     </select>
 </mapper>