Quellcode durchsuchen

多款式的价格

shish vor 5 Jahren
Ursprung
Commit
ef19f435fb
1 geänderte Dateien mit 7 neuen und 5 gelöschten Zeilen
  1. 7 5
      app-hd/controllers/OrderController.php

+ 7 - 5
app-hd/controllers/OrderController.php

@@ -83,6 +83,7 @@ class OrderController extends BaseController
                 $unitPrice = $currentGoodsInfo['price'];
                 $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
                 if (!empty($goodsStyleId)) {
+                    $idKeyStyleList = array_column($goodsStyleList, null, 'id');
                     if (empty($goodsStyleList)) {
                         util::fail('商品款式没有找到');
                     }
@@ -90,11 +91,13 @@ class OrderController extends BaseController
                     if (in_array($goodsStyleId, $styleIdList) == false) {
                         util::fail('商品款式没有找到!');
                     }
-                    $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
+                    if (isset($idKeyStyleList[$goodsStyleId]['price']) == false) {
+                        util::fail('没有找到多款式的价格');
+                    }
+                    $unitPrice = $idKeyStyleList[$goodsStyleId]['price'];
                 }
                 $goodsPrice = $unitPrice * $goodsNum;
                 $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
-
                 $orderGoods[] = [
                     'goodsId' => $currentGoodsId,
                     'userId' => $this->adminId,
@@ -109,7 +112,6 @@ class OrderController extends BaseController
                 ];
 
             }
-
             $user = $this->custom;
             $post['bookName'] = isset($user['name']) ? $user['name'] : '';
             $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
@@ -159,10 +161,10 @@ class OrderController extends BaseController
             if (empty($product)) {
                 util::fail('请选择花材');
             }
-            $actPrice = $post['packingFee']??0; //包装费
+            $actPrice = $post['packingFee'] ?? 0; //包装费
             $orderProduct = [];
             $productInfo = ProductClass::formatProductInfo($product);
-            $actPrice = bcadd($actPrice,$productInfo['price'],2);
+            $actPrice = bcadd($actPrice, $productInfo['price'], 2);
             foreach ($product as $key => $val) {
                 $productId = $val['productId'];
                 $bigNum = $val['bigNum'];