zoujiajian 2 年之前
父节点
当前提交
03bafe626c
共有 1 个文件被更改,包括 43 次插入17 次删除
  1. 43 17
      netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

+ 43 - 17
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -41,6 +41,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -464,31 +465,56 @@ public class UserController {
                 }
             }
             if (e.getIsSkuRate()) {
+                BigDecimal price = e.getPrice();
+                GoodsDonSku sku = skuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
+                        .eq(GoodsDonSku::getGoodsId, e.getGoodsId())
+                        .eq(GoodsDonSku::getPrice, price)
+                        .last("limit 1"));
+                //先获取价格最低的规格对应的 比例
+                //渠道
                 if (userDistribute != null) {
-                    UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
+                    UserPlatSkuDistributeRate minPriceSkuRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
                             .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
                             .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
-                            .ne(UserPlatSkuDistributeRate::getRate, 0)
-                            //上架
-                            .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
-                            .orderByAsc(UserPlatSkuDistributeRate::getRate)
+                            .eq(UserPlatSkuDistributeRate::getSkuId, sku.getId())
                             .last("limit 1"));
-                    if (userPlatSkuDistributeRate != null) {
-                        e.setRate(userPlatSkuDistributeRate.getRate());
-                        GoodsDonSku sku = skuMapper.selectById(userPlatSkuDistributeRate.getSkuId());
-                        e.setPrice(sku.getPrice());
+                    if (minPriceSkuRate != null && minPriceSkuRate.getRate() != 0) {
+                        e.setRate(minPriceSkuRate.getRate());
+                    } else {
+                        UserPlatSkuDistributeRate userPlatSkuDistributeRate = userPlatSkuDistributeRateMapper.selectOne(Wrappers.lambdaQuery(UserPlatSkuDistributeRate.class)
+                                .eq(UserPlatSkuDistributeRate::getDistributeId, userDistribute.getId())
+                                .eq(UserPlatSkuDistributeRate::getGoodsId, e.getGoodsId())
+                                .ne(UserPlatSkuDistributeRate::getRate, 0)
+                                //上架
+                                .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
+                                .orderByAsc(UserPlatSkuDistributeRate::getRate)
+                                .last("limit 1"));
+                        if (userPlatSkuDistributeRate != null) {
+                            e.setRate(userPlatSkuDistributeRate.getRate());
+                            sku = skuMapper.selectById(userPlatSkuDistributeRate.getSkuId());
+                            e.setPrice(sku.getPrice());
+                        }
                     }
                 } else {
-                    DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
+                    //普通
+                    DistributeGeneralSkuRate minPriceRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
                             .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
-                            .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
-                            .ne(DistributeGeneralSkuRate::getRate, 0)
-                            .orderByAsc(DistributeGeneralSkuRate::getRate)
+                            .eq(DistributeGeneralSkuRate::getSkuId, sku.getId())
                             .last("limit 1"));
-                    if (distributeGeneralSkuRate != null) {
-                        e.setRate(distributeGeneralSkuRate.getRate());
-                        GoodsDonSku sku = skuMapper.selectById(distributeGeneralSkuRate.getSkuId());
-                        e.setPrice(sku.getPrice());
+                    if (minPriceRate != null && minPriceRate.getRate() > 0) {
+                        e.setRate(minPriceRate.getRate());
+                    } else {
+                        DistributeGeneralSkuRate distributeGeneralSkuRate = distributeGeneralSkuRateMapper.selectOne(Wrappers.lambdaQuery(DistributeGeneralSkuRate.class)
+                                .eq(DistributeGeneralSkuRate::getGoodsId, e.getGoodsId())
+                                .apply("exists (select 1 from goods_don_sku sku where sku.id = sku_id and sku.status is true limit 1)")
+                                .ne(DistributeGeneralSkuRate::getRate, 0)
+                                .orderByAsc(DistributeGeneralSkuRate::getRate)
+                                .last("limit 1"));
+                        if (distributeGeneralSkuRate != null) {
+                            e.setRate(distributeGeneralSkuRate.getRate());
+                            sku = skuMapper.selectById(distributeGeneralSkuRate.getSkuId());
+                            e.setPrice(sku.getPrice());
+                        }
                     }
                 }
             }