Browse Source

订单金额

shish 4 years ago
parent
commit
176a807b83
2 changed files with 18 additions and 5 deletions
  1. 6 2
      app-mall/controllers/OrderController.php
  2. 12 3
      biz-mall/order/services/OrderService.php

+ 6 - 2
app-mall/controllers/OrderController.php

@@ -52,10 +52,13 @@ class OrderController extends BaseController
             $post['deadline'] = date("Y-m-d H:i:s", strtotime('+360 day'));
             $return = OrderService::createOrder($post);
             $transaction->commit();
-            util::success($return);
+            $orderSn = $return->orderSn ?? '';
+            $orderPrice = $return->orderPrice ?? 0;
+            $id = $return->id ?? 0;
+            util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id]);
         } catch (\Exception $e) {
             $transaction->rollBack();
-            Yii::error("下单失败原因:" . $e->getMessage());
+            Yii::error("失败原因:" . $e->getMessage());
             util::fail('下单失败');
         }
     }
@@ -142,6 +145,7 @@ class OrderController extends BaseController
             $post['orderPrice'] = $actPrice;
             $post['actPrice'] = $actPrice;
             $post['realPrice'] = $actPrice;
+            $post['mainId'] = $this->mainId;
             $order = OrderClass::addOrder($post);
             $orderId = $order['id'];
             $orderSn = $order['orderSn'];

+ 12 - 3
biz-mall/order/services/OrderService.php

@@ -69,20 +69,21 @@ class OrderService extends BaseService
             if (isset($val['property']) == false) {
                 util::fail('没有找到产品属性');
             }
-            $currentPrice = $val['price'] ?? 0;
-            $goodsPrice = bcadd($goodsPrice, $currentPrice, 2);
             $property = $val['property'];
-            $unitPrice = $val['unitPrice'] ?? 0;
             $unitType = $val['unitType'] ?? 0;
             $currentId = $val['productId'] ?? 0;
             $num = $val['num'] ?? 0;
+            $currentPrice = 0;
+            $unitPrice = 0;
             if ($property == dict::getDict('property', 'goods')) {
                 $name = $goodsInfo[$currentId]['name'] ?? '';
                 $cover = $goodsInfo[$currentId]['cover'] ?? '';
                 if (!empty($groupCover)) {
                     $groupCover = $cover;
                 }
+                $currentPrice = $goodsInfo[$currentId]['price'] ?? 0;
                 $currentMainId = $goodsInfo[$currentId]['mainId'] ?? 0;
+                $unitPrice = $currentPrice;
                 if ($currentMainId != $mainId) {
                     util::fail('不是您的商品');
                 }
@@ -111,6 +112,7 @@ class OrderService extends BaseService
                 }
                 $ratio = $itemInfo[$currentId]['ratio'] ?? 20;
                 $currentMainId = $itemInfo[$currentId]['mainId'] ?? 0;
+                $currentPrice = $itemInfo[$currentId]['skPrice'] ?? 0;
                 if ($currentMainId != $mainId) {
                     util::fail('不是您的花材' . $mainId . ' ' . $currentMainId);
                 }
@@ -118,10 +120,14 @@ class OrderService extends BaseService
                     $unitName = $itemInfo[$currentId]['bigUnit'] ?? '';
                     $unitId = $itemInfo[$currentId]['bigUnitId'] ?? 0;
                     $totalNum = $num;
+                    $unitPrice = $currentPrice;
                 } else {
                     $unitName = $itemInfo[$currentId]['smallUnit'] ?? '';
                     $unitId = $itemInfo[$currentId]['smallUnitId'] ?? 0;
                     $totalNum = bcdiv($num, $ratio, 2);
+                    $div = bcdiv($currentPrice, $ratio, 2);
+                    $smallRatio = $itemInfo[$currentId]['smallRatio'] ?? 0;
+                    $unitPrice = bcmul($div, $smallRatio, 2);
                 }
                 $ptItemId = $itemInfo[$currentId]['itemId'] ?? 0;
                 $currentItemData = [
@@ -148,6 +154,9 @@ class OrderService extends BaseService
                 //库存变化在这里
                 OrderItemClass::addData($currentItemData, $custom);
             }
+
+            $goodsPrice = bcadd($goodsPrice, bcmul($unitPrice, $num, 2), 2);
+
         }
         $sendCost = $data['sendCost'] ?? 0;
         $totalPrice = bcadd($goodsPrice, $sendCost, 2);