Просмотр исходного кода

feat(product): 添加共富区PV计算功能

- 在ProductRepository中引入SharedProsperityRecommendConfigRepository依赖
- 实现共富区PV值计算逻辑,包括获取推荐配置和利润比例计算
- 添加产品SKU利润获取和PV值计算方法
- 更新产品详情返回数据结构,增加pv字段
- 修改注释描述从发放共富区PV为计算共富区PV
shichen месяцев назад: 5
Родитель
Сommit
a054938640

+ 14 - 0
app/common/repositories/store/product/ProductRepository.php

@@ -13,6 +13,7 @@ use app\common\model\store\product\Product;
13 13
 use app\common\model\store\product\ProductContent;
14 14
 use app\common\model\user\User;
15 15
 use app\common\repositories\merchant\MerchantRepository;
16
+use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
16 17
 use app\common\repositories\store\coupon\StoreCouponRepository;
17 18
 use app\common\repositories\store\order\StoreOrderRepository;
18 19
 use app\common\repositories\store\order\StoreRefundOrderRepository;
@@ -1065,6 +1066,19 @@ class ProductRepository extends BaseRepository
1065 1066
             $res['yanglao'] = bcmul($res['price'], CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['YangLaoJin']['Ratio']['code'], 2);
1066 1067
             $k['jifen'] = 0;
1067 1068
             $k['gongxian'] = 0;
1069
+
1070
+            // 计算共富区PV
1071
+            /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
1072
+            $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
1073
+            $sharedProsperityRecommendConfigEntityByMaxRewardRatio = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();
1074
+            // 利润 减去 顶格的直推奖,剩下的是PV值
1075
+            $pvProportion = bcsub('1', bcdiv($sharedProsperityRecommendConfigEntityByMaxRewardRatio->getRewardRatio(), '100', 4), 2);
1076
+            // 获取利润
1077
+            $productSku = Db::name('store_product_attr_value')->where('product_id', $res['product_id'])->order('price asc')->find();
1078
+            // 计算pv
1079
+            $pv = bcmul($productSku['plate_mer_profit'], $pvProportion, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
1080
+            $k['pv'] = $pv;
1081
+
1068 1082
         }
1069 1083
 
1070 1084
         $res['pv']=($k['pv']);

+ 1 - 1
app/common/repositories/system/merchant/MerchantRepository.php

@@ -507,7 +507,7 @@ class MerchantRepository extends BaseRepository
507 507
                 $yanglao = bcmul($v['price'], CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['YangLaoJin']['Ratio']['code'], 2);
508 508
                 $v['yanglao'] = $yanglao;
509 509
 
510
-                // 发放共富区PV
510
+                // 计算共富区PV
511 511
                 /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
512 512
                 $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
513 513
                 $sharedProsperityRecommendConfigEntityByMaxRewardRatio = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();