|
|
@@ -131,10 +131,13 @@ class OrderService extends \app\BaseService
|
|
|
$total_sales_tax = 0;
|
|
|
$advisor_1_ids = [];
|
|
|
$product_names = [];
|
|
|
+ $total_annual_fee = 0;
|
|
|
$order_no = $this->orderModel->genOrderNo($store->id, $store->abbr);
|
|
|
for ($i = 0; $i < count($store_products_params); $i++) {
|
|
|
$store_products_param = $store_products_params[$i];
|
|
|
$store_product = $fmt_store_products[$store_products_param->store_product_id];
|
|
|
+ if($store_product['now_stock'] < $store_products_param->quantity)
|
|
|
+ return $this->fail(lang("inventory shortage"));
|
|
|
array_push($advisor_1_ids, $store_products_param->adviser_1_id);
|
|
|
for ($j = 0; $j < $store_products_param->quantity; $j++) {
|
|
|
array_push($product_names, $store_product['product']['name']);
|
|
|
@@ -169,13 +172,18 @@ class OrderService extends \app\BaseService
|
|
|
]);
|
|
|
$product_amount += $store_product['product']['real_price'];
|
|
|
$total_sales_tax += $store_product['product']['sales_tax'];
|
|
|
- $rental_amount += ($store_product['product']['real_price'] + $store_product['product']['sales_tax']);
|
|
|
+ if($store_product['product']['is_gather_annuity'] == 1) {
|
|
|
+ $total_annual_fee += $store_product['product']['annuity'];
|
|
|
+ $rental_amount += ($store_product['product']['real_price'] + $store_product['product']['sales_tax'] + $store_product['product']['annuity']);
|
|
|
+ } else {
|
|
|
+ $rental_amount += ($store_product['product']['real_price'] + $store_product['product']['sales_tax']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
$order = $this->orderModel->create([
|
|
|
'no' => $order_no,
|
|
|
'customer_id' => $customer->id,
|
|
|
- 'customer_name' => $customer->name_en,
|
|
|
+ 'customer_name' => "{$customer->name_en}|{$customer->name_zh}",
|
|
|
'obj_names' => join(',',array_unique($product_names)),
|
|
|
'rental_amount' => $rental_amount,
|
|
|
'receivable_amount' => $rental_amount,
|
|
|
@@ -184,6 +192,7 @@ class OrderService extends \app\BaseService
|
|
|
'product_amount' => $product_amount,
|
|
|
'total_sales_tax' => $total_sales_tax,
|
|
|
'service_charge_amount' => 0,
|
|
|
+ 'total_annual_fee' => $total_annual_fee,
|
|
|
'type' => 2,
|
|
|
'store_id' => $store->id,
|
|
|
'advisor_ids' => join(',', $advisor_1_ids),
|
|
|
@@ -218,7 +227,10 @@ class OrderService extends \app\BaseService
|
|
|
return $this->fail('订单不存在!');
|
|
|
if($order->type == 1)
|
|
|
return $this->fail('订单状态为历史订单!不支持付款');
|
|
|
-
|
|
|
+ // 客户
|
|
|
+ $customer = $this->customerModel->findById($order->customer_id);
|
|
|
+ if (!$customer)
|
|
|
+ return $this->fail(lang("The Customer does not exist"));
|
|
|
$pay_channels = $this->paymentChannelModel->where('is_delete', 0)->select()->toArray();
|
|
|
$fmt_pay_channels = array_reduce($pay_channels, function ($result, $item) {
|
|
|
$result[$item['id']] = $item;
|
|
|
@@ -310,12 +322,13 @@ class OrderService extends \app\BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 总共需要收取这么多费用; (商品的价格 + 手续费 + 税费) - 御龙币抵扣的费用
|
|
|
- $imposed_amount = fixed2Float($order->product_amount + ($order->service_charge_amount + $service_charge) + $order->total_sales_tax);
|
|
|
+ // 信用卡手续费
|
|
|
+ $total_service_charge_amount = ($order->service_charge_amount + $service_charge);
|
|
|
+ // 总共需要收取这么多费用; (商品的价格 + 商品税费 + 年费 + 信用卡手续费) - 御龙币抵扣的费用
|
|
|
+ $imposed_amount = fixed2Float($order->product_amount + $order->total_sales_tax + $order->total_annual_fee + $total_service_charge_amount);
|
|
|
// 总计实收金额
|
|
|
$receive_amount = fixed2Float($order->receive_amount + $total_fee);
|
|
|
- if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 应该支付 {$imposed_amount}");
|
|
|
-
|
|
|
+ if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 应该支付 {$imposed_amount} (商品总价:{$order->product_amount} + 商品总消费税:{$order->total_sales_tax} + 第一年年费:{$order->total_annual_fee} + 信用卡总手续费:{$total_service_charge_amount})");
|
|
|
$order_annual_fees = [];
|
|
|
$update_store_products = [];
|
|
|
if (round($receive_amount) == round($imposed_amount)) { // 减库存
|
|
|
@@ -336,14 +349,22 @@ class OrderService extends \app\BaseService
|
|
|
if ($order_product['is_gather_annuity']) {
|
|
|
array_push($order_annual_fees, [
|
|
|
'order_id' => $order->id,
|
|
|
- 'order_product_id' => $order_product['product_id'],
|
|
|
+ 'customer_id' => $customer->id,
|
|
|
+ 'customer_name' => "{$customer->name_en}|{$customer->name_zh}",
|
|
|
+ 'customer_mobile' => $customer->mobile,
|
|
|
+ 'customer_create_username' => $customer->create_username,
|
|
|
+ 'index' => 1,
|
|
|
+ 'order_product_id' => $order_product['id'],
|
|
|
'order_product_name' => $order_product['product_name'],
|
|
|
'fee' => $order_product['annuity'],
|
|
|
- 'is_pay' => 0,
|
|
|
+ 'is_pay' => 1,
|
|
|
'start_time' => time(),
|
|
|
'end_time' => time() + (365 * 24 * 60 * 60),
|
|
|
+ 'order_create_time' => $order->create_time,
|
|
|
+ 'adviser_1_id' => $order_product['adviser_1_id'],
|
|
|
+ 'store_id' => $order->store_id,
|
|
|
'create_time' => time(),
|
|
|
- 'update_time' => time(),
|
|
|
+ 'update_time' => time()
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
@@ -406,7 +427,6 @@ class OrderService extends \app\BaseService
|
|
|
return $this->ok(true);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function fetch($params) {
|
|
|
$is_look_all = AuthService::is_look_all($params['admin_id'],$params['type'] == 1 ? 10003 : 10004);
|
|
|
$res = $this->orderModel->search($params, $is_look_all);
|
|
|
@@ -435,8 +455,6 @@ class OrderService extends \app\BaseService
|
|
|
return [$items, $res['total']];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public function upload_numerology($order_product_id, $report) {
|
|
|
$order_product = $this->orderProductModel->findById($order_product_id);
|
|
|
if (!$order_product) return $this->fail('订单商品不存在,无法上传命理报告!');
|
|
|
@@ -447,11 +465,23 @@ class OrderService extends \app\BaseService
|
|
|
return $this->ok($order_product);
|
|
|
}
|
|
|
|
|
|
+ public function fetchWaitGatherAnnualFee($admin_id, $text = null, $start_time = null, $end_time = null, $page = 1, $size = 10) {
|
|
|
+ $res = $this->orderAnnualFeeModel->fetchByAdviser($admin_id, $text, $start_time, $end_time, $page, $size);
|
|
|
+ return [$res->items(),$res->total()];
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ public function paymentAnnualFee($annual_fee_id) {
|
|
|
+ $annual_fee = $this->orderAnnualFeeModel->findById($annual_fee_id);
|
|
|
+ if(!$annual_fee_id) {
|
|
|
+ return $this->fail('年费记录不存在!');
|
|
|
+ }
|
|
|
+ if($annual_fee->is_pay == 1)
|
|
|
+ return $this->fail('该条年费记录已经支付!');
|
|
|
+ $annual_fee->is_pay = 1;
|
|
|
+ $annual_fee->update_time = time();
|
|
|
+ $annual_fee->save();
|
|
|
+ return $this->ok($annual_fee);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|