Browse Source

定金/订金价格处理

master
李可松 4 years ago
parent
commit
6cbe6d2425
  1. 21
      app/Http/Controllers/Api/OrderController.php

21
app/Http/Controllers/Api/OrderController.php

@ -164,6 +164,7 @@ class OrderController extends Controller
if ($spec->isEmpty()) { if ($spec->isEmpty()) {
return $this->error('你选择的产品规格不存在'); return $this->error('你选择的产品规格不存在');
} }
$spec = $spec->toArray(); $spec = $spec->toArray();
$spec = array_map(function ($v) { $spec = array_map(function ($v) {
$v = array_merge($v['product_spec'] ?? [], $v); $v = array_merge($v['product_spec'] ?? [], $v);
@ -171,7 +172,8 @@ class OrderController extends Controller
return $v; return $v;
}, $spec); }, $spec);
$order_price = 0; //订单总价
//订单总价
$order_price = 0;
foreach ($spec as $v) { foreach ($spec as $v) {
$order_price += $v['price'] * $formData['num']; $order_price += $v['price'] * $formData['num'];
} }
@ -283,11 +285,11 @@ class OrderController extends Controller
//处理预付金额 //处理预付金额
if ($formData['pay_type'] == PayType::DEPOSIT_PAY) { if ($formData['pay_type'] == PayType::DEPOSIT_PAY) {
//订金支付 //订金支付
$prepayPrice = $ap->deposit * $formData['num'];
$prepayPrice = count($spec) * $ap->deposit * $formData['num'];
$prepayTimeout = $ap->deposit_timeout; $prepayTimeout = $ap->deposit_timeout;
} else if($formData['pay_type'] == PayType::EARNEST_PAY) { } else if($formData['pay_type'] == PayType::EARNEST_PAY) {
//定金支付 //定金支付
$prepayPrice = $ap->earnest * $formData['num'];
$prepayPrice = count($spec) * $ap->earnest * $formData['num'];
$prepayTimeout = $ap->earnest_timeout; $prepayTimeout = $ap->earnest_timeout;
} }
@ -429,23 +431,22 @@ class OrderController extends Controller
$spec = AgentProductSpec::where('agent_product_id', $formData['id']) $spec = AgentProductSpec::where('agent_product_id', $formData['id'])
->whereIn('id', $formData['spec_id']) ->whereIn('id', $formData['spec_id'])
->get(); ->get();
if ($spec->isEmpty()) { if ($spec->isEmpty()) {
return $this->error('你选择的产品规格不存在'); return $this->error('你选择的产品规格不存在');
} }
$spec = $spec->toArray(); $spec = $spec->toArray();
$ap->final_price = 0;
if ($formData['pay_type'] == PayType::DEPOSIT_PAY) { //订金支付 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) { //定金支付 else if($formData['pay_type'] == PayType::EARNEST_PAY) { //定金支付
$single_price = $ap->earnes;
$ap->final_price = count($spec) * $ap->earnes * $formData['num'];
} else { } else {
$single_price = $ap->price;
}
$ap->final_price = 0;
foreach ($spec as $v) { foreach ($spec as $v) {
$ap->final_price += $single_price * $formData['num'];
$ap->final_price += $v['price'] * $formData['num'];
}
} }
$ap->num = $formData['num']; $ap->num = $formData['num'];

Loading…
Cancel
Save