shish пре 4 година
родитељ
комит
c81a92856b

+ 0 - 7
app-ghs/controllers/ProductController.php

@@ -60,13 +60,6 @@ class ProductController extends BaseController
         }
         $where['delStatus'] = 0;
 
-        //给客户开单,价格显示不同客户不同价格
-        $customId = Yii::$app->request->get('customId', 0);
-        if (!empty($customId)) {
-            $custom = CustomClass::getById($customId, true);
-            Yii::$app->params['customDiscount'] = isset($custom->discount) ? $custom->discount : 1;
-        }
-
         $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
         $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
 

+ 0 - 4
app-hd/controllers/ProductController.php

@@ -149,10 +149,6 @@ class ProductController extends BaseController
             $where['status'] = 1;
 
 
-            //客户需要给算折扣
-            Yii::$app->params['customDiscount'] = isset($ghs['giveDiscount']) ? $ghs['giveDiscount'] : 1;
-
-
             $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
             $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
 

+ 16 - 0
biz-ghs/custom/classes/CustomClass.php

@@ -34,6 +34,22 @@ class CustomClass extends BaseClass
         self::LEVEL_ZS => '钻石',
     ];
 
+    public static $levelPriceKeyMap = [
+        self::LEVEL_PT => 'price',
+        self::LEVEL_QT => 'qtPrice',
+        self::LEVEL_BY => 'byPrice',
+        self::LEVEL_HJ => 'hjPrice',
+        self::LEVEL_ZS => 'zsPrice',
+    ];
+
+    public static $levelAddPriceKeyMap = [
+        self::LEVEL_PT => 'addPrice',
+        self::LEVEL_QT => 'qtAddPrice',
+        self::LEVEL_BY => 'byAddPrice',
+        self::LEVEL_HJ => 'hjAddPrice',
+        self::LEVEL_ZS => 'zsAddPrice',
+    ];
+
     //建立客户和供应商关系
     public static function build($ghsShopId, $hdShopId)
     {

+ 56 - 25
biz-ghs/product/classes/ProductClass.php

@@ -98,6 +98,16 @@ class ProductClass extends BaseClass
     //花材图片,名称,大小单位,小单位价格
     public static function groupProductInfo($list)
     {
+
+        $customId = isset(Yii::$app->params['customId']) ? Yii::$app->params['customId'] : 0;
+        $customInfo = [];
+        if (empty($customId)) {
+            $customInfo = CustomClass::getById($customId, true);
+        }
+        $levelPriceKey = CustomClass::$levelPriceKeyMap;
+        $customLevel = $customInfo->level ?? 0;
+        $levelAddPriceKey = CustomClass::$levelAddPriceKeyMap;
+
         foreach ($list as $k => $v) {
             $shortCover = $v['cover'] ?? '';
             $cover = imgUtil::getPrefix() . 'hhb_small.png';
@@ -119,20 +129,30 @@ class ProductClass extends BaseClass
             $list[$k]['bigNum'] = $stockInfo['bigNum'];
             $list[$k]['smallNum'] = $stockInfo['smallNum'];
             $list[$k]['itemName'] = $v['name'] ?? '';
-
             //原价 shish 20210703
             $list[$k]['prePrice'] = $v['price'] ?? 0;
+            $price = $v['price'] ?? 0;
 
-            //特价 shish 20210901
-            $discountPrice = $v['discountPrice'] ?? 0;
-            $price = $discountPrice > 0 && $v['price'] > $discountPrice ? $discountPrice : $v['price'];
-
-            //客户折扣价
-            $customDiscount = isset(Yii::$app->params['customDiscount']) ? Yii::$app->params['customDiscount'] : 1;
-            if ($customDiscount < 1 && $customDiscount > 0) {
-                $price = bcmul($price, $customDiscount, 2);
-                //四舍五入保留整数,涉及多个地方要同步修改,请搜索关键词:round_price!!!!
-                $price = round($price, 0);
+            //价格相关控制!!!!!!!请搜索 price_control
+            if (empty($customInfo)) {
+                $discountPrice = $v['discountPrice'] ?? 0;
+                if ($discountPrice > 0) {
+                    $price = $discountPrice;
+                }
+            } else {
+                $currentPriceKey = $levelPriceKey[$customLevel] ?? 'price';
+                $price = $v[$currentPriceKey] ?? 0;
+
+                //特价
+                $discountPrice = $v['discountPrice'] ?? 0;
+                if ($discountPrice > 0) {
+                    $preAddPriceKey = $levelAddPriceKey[0] ?? 'addPrice';
+                    $preAddPrice = $v[$preAddPriceKey] ?? 0;
+                    $currentAddPriceKey = $levelAddPriceKey[$customLevel] ?? 'addPrice';
+                    $currentAddPrice = $v[$currentAddPriceKey] ?? 0;
+                    $diff = bcsub($preAddPrice, $currentAddPrice, 2);
+                    $price = bcsub($discountPrice, $diff, 2);
+                }
             }
 
             $list[$k]['price'] = $price;
@@ -631,11 +651,13 @@ class ProductClass extends BaseClass
         $totalSmallNum = 0;
 
         //不同的人卖不现价格
-        $discount = 1;
+        $customLevel = 0;
         if (!empty($customId)) {
             $custom = CustomClass::getById($customId, true);
-            $discount = $custom->discount ?? 1;
+            $customLevel = $custom->level ?? 0;
         }
+        $levelPriceKey = CustomClass::$levelPriceKeyMap;
+        $levelAddPriceKey = CustomClass::$levelAddPriceKeyMap;
 
         foreach ($itemInfo as $v) {
             $productId = $v['productId'];
@@ -644,20 +666,29 @@ class ProductClass extends BaseClass
             $cost = $productData[$productId]['cost'] ?? 0;
             //大小数量合并多少扎
             $itemNum = self::mergeItemNum($v['bigNum'], $v['smallNum'], $ratio);
-            //售卖价格
-            $itemPrice = $productData[$productId]['price'] ?? 0;
 
-            //特价
-            $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
-            if ($discountPrice > 0) {
-                $itemPrice = $discountPrice;
-            }
+            //价格相关控制!!!!!!!请搜索 price_control
+            if (empty($customId)) {
+                $itemPrice = $productData[$productId]['price'] ?? 0;
+                $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
+                if ($discountPrice > 0) {
+                    $itemPrice = $discountPrice;
+                }
+            } else {
 
-            //不同的人卖不同价格
-            if ($discount > 0 && $discount < 1) {
-                $itemPrice = bcmul($itemPrice, $discount, 2);
-                //四舍五入保留整数,涉及多个地方要同步修改,请搜索关键词:round_price!!!!
-                $itemPrice = round($itemPrice, 0);
+                $currentPriceKey = $levelPriceKey[$customLevel] ?? 'price';
+                $itemPrice = $productData[$productId][$currentPriceKey] ?? 0;
+
+                //特价
+                $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
+                if ($discountPrice > 0) {
+                    $preAddPriceKey = $levelAddPriceKey[0] ?? 'addPrice';
+                    $preAddPrice = $productData[$productId][$preAddPriceKey] ?? 0;
+                    $currentAddPriceKey = $levelAddPriceKey[$customLevel] ?? 'addPrice';
+                    $currentAddPrice = $productData[$productId][$currentAddPriceKey] ?? 0;
+                    $diff = bcsub($preAddPrice, $currentAddPrice, 2);
+                    $itemPrice = bcsub($discountPrice, $diff, 2);
+                }
             }
 
             //供应商开单可以传单价过来

+ 17 - 13
biz-hd/purchase/classes/PurchaseClass.php

@@ -9,6 +9,7 @@ use biz\shop\classes\ShopCouponClass;
 use biz\sj\classes\SjClass;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\admin\classes\AdminClass;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\order\traits\OrderTrait;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\services\StockRecordService;
@@ -74,7 +75,11 @@ class PurchaseClass extends BaseClass
         $productData = self::getProductMapData($productList, "productId");
         $hdProductData = self::getProductMapData($productList, "hdProductId");
 
-        $giveDiscount = $ghs['giveDiscount'] ?? 1;
+        $giveLevel = $ghs['giveLevel'] ?? 0;
+        $priceKey = CustomClass::$levelPriceKeyMap;
+        $currentPriceKey = $priceKey[$giveLevel] ?? 'price';
+        $levelAddPriceKey = CustomClass::$levelAddPriceKeyMap;
+        $currentAddPriceKey = $levelAddPriceKey[$giveLevel] ?? 'addPrice';
 
         //计算价格= 各个productId的price*num(bigNum,smallNum) + sendCost(配送费)
         $bigNum = 0; //总共多少扎
@@ -95,22 +100,21 @@ class PurchaseClass extends BaseClass
             $stockFormat = ProductClass::formatStock($stock, $ratio);
 
             $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
-            $price = $productData[$productId]['price']; //卖的单价
 
-            //折扣价
+            //价格相关控制!!!!!!!请搜索 price_control
+            //普通价与会员价
+            $price = $productData[$productId][$currentPriceKey];
+            //今日特价
             $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
             if ($discountPrice > 0) {
-                $price = $discountPrice;
-            }
-
-            if ($giveDiscount < 1 && $giveDiscount > 0) {
-                $price = bcmul($price, $giveDiscount, 2);
-                //四舍五入保留整数,涉及多个地方要同步修改,请搜索关键词:round_price!!!!
-                $price = round($price, 0);
+                $addPriceKey = $levelAddPriceKey[0] ?? 'addPrice';
+                $addPrice = $v[$addPriceKey] ?? 0;
+                $currentAddPrice = $v[$currentAddPriceKey] ?? 0;
+                $diff = bcsub($addPrice, $currentAddPrice, 2);
+                $price = bcsub($discountPrice, $diff, 2);
             }
 
-            //花材原价
-            $productPrePrice = bcmul($itemNum, $price, 2); //采购总价
+            $productPrePrice = bcmul($itemNum, $price, 2);
             $productTotalPrice = $productPrePrice;
 
             //供应商开单时修改价格
@@ -205,7 +209,7 @@ class PurchaseClass extends BaseClass
         $data['bigNum'] = $bigNum;
         $data['smallNum'] = $smallNum;
 
-        $data['discount'] = $giveDiscount;
+        $data['discount'] = 1;
 
         //采购单有效期
         $validTime = dict::getDict('sale_purchase_order_valid');