From 6cbe6d2425753f5f449ff86ddd5cbcfa7032db8d Mon Sep 17 00:00:00 2001 From: liapples Date: Sun, 26 Sep 2021 17:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E9=87=91/=E8=AE=A2=E9=87=91=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/OrderController.php | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index d12e006..a17fb89 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -164,6 +164,7 @@ class OrderController extends Controller if ($spec->isEmpty()) { return $this->error('你选择的产品规格不存在'); } + $spec = $spec->toArray(); $spec = array_map(function ($v) { $v = array_merge($v['product_spec'] ?? [], $v); @@ -171,7 +172,8 @@ class OrderController extends Controller return $v; }, $spec); - $order_price = 0; //订单总价 + //订单总价 + $order_price = 0; foreach ($spec as $v) { $order_price += $v['price'] * $formData['num']; } @@ -283,11 +285,11 @@ class OrderController extends Controller //处理预付金额 if ($formData['pay_type'] == PayType::DEPOSIT_PAY) { //订金支付 - $prepayPrice = $ap->deposit * $formData['num']; + $prepayPrice = count($spec) * $ap->deposit * $formData['num']; $prepayTimeout = $ap->deposit_timeout; } else if($formData['pay_type'] == PayType::EARNEST_PAY) { //定金支付 - $prepayPrice = $ap->earnest * $formData['num']; + $prepayPrice = count($spec) * $ap->earnest * $formData['num']; $prepayTimeout = $ap->earnest_timeout; } @@ -429,23 +431,22 @@ class OrderController extends Controller $spec = AgentProductSpec::where('agent_product_id', $formData['id']) ->whereIn('id', $formData['spec_id']) ->get(); + if ($spec->isEmpty()) { return $this->error('你选择的产品规格不存在'); } $spec = $spec->toArray(); + $ap->final_price = 0; if ($formData['pay_type'] == PayType::DEPOSIT_PAY) { //订金支付 - $single_price = $ap->deposit; + $ap->final_price = count($spec) * $ap->deposit * $formData['num']; } else if($formData['pay_type'] == PayType::EARNEST_PAY) { //定金支付 - $single_price = $ap->earnes; + $ap->final_price = count($spec) * $ap->earnes * $formData['num']; } else { - $single_price = $ap->price; - } - - $ap->final_price = 0; - foreach ($spec as $v) { - $ap->final_price += $single_price * $formData['num']; + foreach ($spec as $v) { + $ap->final_price += $v['price'] * $formData['num']; + } } $ap->num = $formData['num'];