shish 4 жил өмнө
parent
commit
64f9e419e6

+ 2 - 1
biz-ghs/order/classes/OrderItemClass.php

@@ -48,7 +48,8 @@ class OrderItemClass extends BaseClass
     //添加修改花材 ssh 2021.1.22
     public static function replaceItem($orderSn, $product, $post = null)
     {
-        $respond = ProductClass::formatProductInfo($product);
+        $customId = $post['customId'] ?? 0;
+        $respond = ProductClass::formatProductInfo($product, $customId);
         $product = $respond['product'];
         self::deleteByCondition(['orderSn' => $orderSn]);
         foreach ($product as $key => $val) {

+ 16 - 3
biz-ghs/product/classes/ProductClass.php

@@ -9,6 +9,7 @@ use biz\item\classes\UnitClass;
 use biz\shop\services\ShopService;
 use biz\wx\classes\WxMessageClass;
 use bizGhs\base\classes\BaseClass;
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\merchant\classes\ShopClass;
@@ -575,7 +576,7 @@ class ProductClass extends BaseClass
     //2021.7.26增加前端传的价格 (小程序有传,但pc端不穿)
     //itemInfo :[{"classId":5,"productId":3,"bigNum":1,"smallNum":2,"price":0}]
     //返回 [{"productId":3,"price":2.1}]
-    public static function formatProductInfo(array $itemInfo)
+    public static function formatProductInfo($itemInfo, $customId = 0)
     {
         $data = [];
         if (empty($itemInfo)) {
@@ -590,6 +591,13 @@ class ProductClass extends BaseClass
         $totalBigNum = 0;
         $totalSmallNum = 0;
 
+        //商家给客户打折
+        $discount = 1;
+        if (!empty($customId)) {
+            $custom = CustomClass::getById($customId, true);
+            $discount = $custom->discount ?? 1;
+        }
+
         foreach ($itemInfo as $v) {
             $productId = $v['productId'];
             $itemId = $productData[$productId]['itemId'] ?? 0;
@@ -599,7 +607,7 @@ class ProductClass extends BaseClass
             //售卖价格
             $itemPrice = $productData[$productId]['price'] ?? 0;
 
-            //折扣
+            //
             $discountPrice = $productData[$productId]['discountPrice'] ?? 0;
             if ($discountPrice > 0) {
                 $itemPrice = $discountPrice;
@@ -638,6 +646,11 @@ class ProductClass extends BaseClass
             $smallUnitPrice = bcdiv($itemPrice, $tmp['ratio'], 2);
             $tmp['smallUnitPrice'] = $smallUnitPrice;
 
+            $discountPrice = bcmul($itemPrice,$discount,2);
+            $discountSmallPrice = bcdiv($discountPrice, $tmp['ratio'], 2);
+            $tmp['discountPrice'] = $discountPrice;
+            $tmp['smallUnitPrice'] = $discountSmallPrice;
+
             $totalBigNum += $v['bigNum'];
             $totalSmallNum += $v['smallNum'];
 
@@ -1171,7 +1184,7 @@ class ProductClass extends BaseClass
                 $ids = [];
                 $shopId = $shop->id ?? 0;
                 $stockWarningListKey = 'stockWarningList_' . $shopId;
-                echo $stockWarningListKey."\n";
+                echo $stockWarningListKey . "\n";
                 while ($count = Yii::$app->redis->executeCommand('LLEN', [$stockWarningListKey])) {
                     $productId = Yii::$app->redis->executeCommand('RPOP', [$stockWarningListKey]);
                     if (is_numeric($productId)) {