|
@@ -84,7 +84,8 @@ class OrderService extends \app\BaseService
|
|
|
$ids = [];
|
|
$ids = [];
|
|
|
if(isset($store_products_param->adviser_1_id)) array_push($ids, $store_products_param->adviser_1_id);
|
|
if(isset($store_products_param->adviser_1_id)) array_push($ids, $store_products_param->adviser_1_id);
|
|
|
if(isset($store_products_param->adviser_2_id)) array_push($ids, $store_products_param->adviser_2_id);
|
|
if(isset($store_products_param->adviser_2_id)) array_push($ids, $store_products_param->adviser_2_id);
|
|
|
- if(isset($store_products_param->teacher_id)) array_push($ids, $store_products_param->teacher_id);
|
|
|
|
|
|
|
+ if(isset($store_products_param->teacher_1_id)) array_push($ids, $store_products_param->teacher_1_id);
|
|
|
|
|
+ if(isset($store_products_param->teacher_2_id)) array_push($ids, $store_products_param->teacher_2_id);
|
|
|
$user_ids = array_unique(array_merge($user_ids, $ids));
|
|
$user_ids = array_unique(array_merge($user_ids, $ids));
|
|
|
array_push($store_product_ids, $store_products_param->store_product_id);
|
|
array_push($store_product_ids, $store_products_param->store_product_id);
|
|
|
}
|
|
}
|
|
@@ -132,7 +133,7 @@ class OrderService extends \app\BaseService
|
|
|
$product_amount = 0;
|
|
$product_amount = 0;
|
|
|
// 总消费税
|
|
// 总消费税
|
|
|
$total_sales_tax = 0;
|
|
$total_sales_tax = 0;
|
|
|
- $advisor_1_ids = [];
|
|
|
|
|
|
|
+ $advisor_ids = [];
|
|
|
$product_names = [];
|
|
$product_names = [];
|
|
|
$total_annual_fee = 0;
|
|
$total_annual_fee = 0;
|
|
|
$order_no = $this->orderModel->genOrderNo($store->id, $store->abbr);
|
|
$order_no = $this->orderModel->genOrderNo($store->id, $store->abbr);
|
|
@@ -141,7 +142,11 @@ class OrderService extends \app\BaseService
|
|
|
$store_product = $fmt_store_products[$store_products_param->store_product_id];
|
|
$store_product = $fmt_store_products[$store_products_param->store_product_id];
|
|
|
if($store_product['now_stock'] < $store_products_param->quantity)
|
|
if($store_product['now_stock'] < $store_products_param->quantity)
|
|
|
return $this->fail(lang("inventory shortage"));
|
|
return $this->fail(lang("inventory shortage"));
|
|
|
- array_push($advisor_1_ids, $store_products_param->adviser_1_id);
|
|
|
|
|
|
|
+ array_push($advisor_ids, $store_products_param->adviser_1_id);
|
|
|
|
|
+ if(isset($store_products_param->adviser_2_id)) {
|
|
|
|
|
+ array_push($advisor_ids, $store_products_param->adviser_2_id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for ($j = 0; $j < $store_products_param->quantity; $j++) {
|
|
for ($j = 0; $j < $store_products_param->quantity; $j++) {
|
|
|
array_push($product_names, $store_product['product']['name']);
|
|
array_push($product_names, $store_product['product']['name']);
|
|
|
array_push($order_products, [
|
|
array_push($order_products, [
|
|
@@ -157,8 +162,10 @@ class OrderService extends \app\BaseService
|
|
|
'adviser_1_name' => isset($store_products_param->adviser_1_id) ? $fmt_users[$store_products_param->adviser_1_id]['nickname'] : null,
|
|
'adviser_1_name' => isset($store_products_param->adviser_1_id) ? $fmt_users[$store_products_param->adviser_1_id]['nickname'] : null,
|
|
|
'adviser_2_id' => isset($store_products_param->adviser_2_id) ? $store_products_param->adviser_2_id : null,
|
|
'adviser_2_id' => isset($store_products_param->adviser_2_id) ? $store_products_param->adviser_2_id : null,
|
|
|
'adviser_2_name' => isset($store_products_param->adviser_2_id) ? $fmt_users[$store_products_param->adviser_2_id]['nickname'] : null,
|
|
'adviser_2_name' => isset($store_products_param->adviser_2_id) ? $fmt_users[$store_products_param->adviser_2_id]['nickname'] : null,
|
|
|
- 'teacher_id' => isset($store_products_param->teacher_id) ? $store_products_param->teacher_id : null,
|
|
|
|
|
- 'teacher_name' => isset($store_products_param->teacher_id) ? $fmt_users[$store_products_param->teacher_id]['nickname'] : null,
|
|
|
|
|
|
|
+ 'teacher_1_id' => isset($store_products_param->teacher_1_id) ? $store_products_param->teacher_1_id : null,
|
|
|
|
|
+ 'teacher_1_name' => isset($store_products_param->teacher_1_id) ? $fmt_users[$store_products_param->teacher_1_id]['nickname'] : null,
|
|
|
|
|
+ 'teacher_2_id' => isset($store_products_param->teacher_2_id) ? $store_products_param->teacher_2_id : null,
|
|
|
|
|
+ 'teacher_2_name' => isset($store_products_param->teacher_2_id) ? $fmt_users[$store_products_param->teacher_2_id]['nickname'] : null,
|
|
|
'is_upload_numerology' => $store_product['product']['is_upload_numerology'],
|
|
'is_upload_numerology' => $store_product['product']['is_upload_numerology'],
|
|
|
'is_upload' => 0,
|
|
'is_upload' => 0,
|
|
|
'report' => null,
|
|
'report' => null,
|
|
@@ -170,6 +177,8 @@ class OrderService extends \app\BaseService
|
|
|
'reduce_type' => $store_product['activity'] ? $store_product['activity']['type'] : 0,
|
|
'reduce_type' => $store_product['activity'] ? $store_product['activity']['type'] : 0,
|
|
|
'sales_tax_rate' => $store_product['product']['sales_tax_rate'],
|
|
'sales_tax_rate' => $store_product['product']['sales_tax_rate'],
|
|
|
'sales_tax' => $store_product['product']['sales_tax'],
|
|
'sales_tax' => $store_product['product']['sales_tax'],
|
|
|
|
|
+ 'transaction_price' => 0,
|
|
|
|
|
+ 'zue_coin' => 0,
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
'update_time' => time(),
|
|
|
]);
|
|
]);
|
|
@@ -198,7 +207,7 @@ class OrderService extends \app\BaseService
|
|
|
'total_annual_fee' => $total_annual_fee,
|
|
'total_annual_fee' => $total_annual_fee,
|
|
|
'type' => 2,
|
|
'type' => 2,
|
|
|
'store_id' => $store->id,
|
|
'store_id' => $store->id,
|
|
|
- 'advisor_ids' => join(',', $advisor_1_ids),
|
|
|
|
|
|
|
+ 'advisor_ids' => join(',', $advisor_ids),
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time()
|
|
'update_time' => time()
|
|
|
]);
|
|
]);
|
|
@@ -335,8 +344,11 @@ class OrderService extends \app\BaseService
|
|
|
$order_use_zue_coin = $order->zue_coin;
|
|
$order_use_zue_coin = $order->zue_coin;
|
|
|
$order_use_zue_coin_amount = $order->zue_coin_amount;
|
|
$order_use_zue_coin_amount = $order->zue_coin_amount;
|
|
|
|
|
|
|
|
|
|
+ $change_zue_coin_record = null;
|
|
|
if($zue_coin > 0) {
|
|
if($zue_coin > 0) {
|
|
|
$zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
|
|
$zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
|
|
|
|
|
+ if(!$zue_coin_model)
|
|
|
|
|
+ return $this->fail("当前客户御龙币账户余额: 0");
|
|
|
if ($zue_coin > $zue_coin_model->zue_coin)
|
|
if ($zue_coin > $zue_coin_model->zue_coin)
|
|
|
return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
|
|
return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
|
|
|
$zue_coin_config = $fmt_pay_channels['11'];
|
|
$zue_coin_config = $fmt_pay_channels['11'];
|
|
@@ -361,16 +373,20 @@ class OrderService extends \app\BaseService
|
|
|
$now_can_consume_zue_coin = $total_can_zue_coin - $order_use_zue_coin;
|
|
$now_can_consume_zue_coin = $total_can_zue_coin - $order_use_zue_coin;
|
|
|
// 判断当前还能使用
|
|
// 判断当前还能使用
|
|
|
if ($now_can_consume_zue_coin - $zue_coin < 0)
|
|
if ($now_can_consume_zue_coin - $zue_coin < 0)
|
|
|
- return $this->fail("
|
|
|
|
|
- 当前已使用御龙币数额: {$order_use_zue_coin}/{$total_can_zue_coin},
|
|
|
|
|
- 当前已兑换金额: {$order_use_zue_coin_amount}/{$total_consume_amount},
|
|
|
|
|
- 御龙币兑换比例: {$zue_coin_exchange_rate},
|
|
|
|
|
- 御龙币报销比例:{$zue_coin_consume_rate}
|
|
|
|
|
- ");
|
|
|
|
|
|
|
+ return $this->fail("当前已使用御龙币数额: {$order_use_zue_coin}/{$total_can_zue_coin},当前已兑换金额: {$order_use_zue_coin_amount}/{$total_consume_amount},御龙币兑换比例: {$zue_coin_exchange_rate},御龙币报销比例:{$zue_coin_consume_rate}");
|
|
|
// 总共使用了这么多御龙币
|
|
// 总共使用了这么多御龙币
|
|
|
$order_use_zue_coin += $zue_coin;
|
|
$order_use_zue_coin += $zue_coin;
|
|
|
// 总共兑换了这么多钱
|
|
// 总共兑换了这么多钱
|
|
|
$order_use_zue_coin_amount = fixed2Float($order_use_zue_coin * $zue_coin_exchange_rate);
|
|
$order_use_zue_coin_amount = fixed2Float($order_use_zue_coin * $zue_coin_exchange_rate);
|
|
|
|
|
+ $change_zue_coin_record = [
|
|
|
|
|
+ 'zue_coin_id' => $zue_coin_model->id,
|
|
|
|
|
+ 'origin' => $zue_coin_model->zue_coin,
|
|
|
|
|
+ 'change' => $zue_coin,
|
|
|
|
|
+ 'after' => $zue_coin_model->zue_coin - $zue_coin,
|
|
|
|
|
+ 'reason' => 1,
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
// 总计费用 - 御龙币抵消费用;
|
|
// 总计费用 - 御龙币抵消费用;
|
|
|
$imposed_amount -= $order_use_zue_coin_amount;
|
|
$imposed_amount -= $order_use_zue_coin_amount;
|
|
@@ -380,6 +396,7 @@ class OrderService extends \app\BaseService
|
|
|
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})");
|
|
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 = [];
|
|
$order_annual_fees = [];
|
|
|
$update_store_products = [];
|
|
$update_store_products = [];
|
|
|
|
|
+ $update_order_products = [];
|
|
|
if (round($receive_amount) == round($imposed_amount)) { // 减库存
|
|
if (round($receive_amount) == round($imposed_amount)) { // 减库存
|
|
|
$order_products = $this->orderProductModel->findByOrderId($order->id)->toArray();
|
|
$order_products = $this->orderProductModel->findByOrderId($order->id)->toArray();
|
|
|
$store_products = $this->storeProductModel->findByIds(array_map(function ($r) {return $r['store_product_id'];}, $order_products))->toArray();
|
|
$store_products = $this->storeProductModel->findByIds(array_map(function ($r) {return $r['store_product_id'];}, $order_products))->toArray();
|
|
@@ -387,6 +404,13 @@ class OrderService extends \app\BaseService
|
|
|
$result[$item['id']] = $item;
|
|
$result[$item['id']] = $item;
|
|
|
return $result;
|
|
return $result;
|
|
|
},[]);
|
|
},[]);
|
|
|
|
|
+ // 商品本身的价格 | 年费 | 消费税 | 信用卡支付的服务费 | 御龙币使用的御龙币退还
|
|
|
|
|
+ $total_ = $imposed_amount - ($order->service_charge_amount + $service_charge);
|
|
|
|
|
+
|
|
|
|
|
+ // 每一块钱所占的比例
|
|
|
|
|
+ $item_service_charge = ($order->service_charge_amount + $service_charge) / $total_;
|
|
|
|
|
+ // 每一个御龙币所占的比例
|
|
|
|
|
+ $item_zue_coin = $order_use_zue_coin / $total_;
|
|
|
foreach ($order_products as $order_product) {
|
|
foreach ($order_products as $order_product) {
|
|
|
predicate($fmt_store_products[$order_product['store_product_id']]['now_stock'] > 0, lang('inventory shortage'));
|
|
predicate($fmt_store_products[$order_product['store_product_id']]['now_stock'] > 0, lang('inventory shortage'));
|
|
|
$fmt_store_products[$order_product['store_product_id']]['now_stock'] -= 1;
|
|
$fmt_store_products[$order_product['store_product_id']]['now_stock'] -= 1;
|
|
@@ -409,17 +433,23 @@ class OrderService extends \app\BaseService
|
|
|
'is_pay' => 1,
|
|
'is_pay' => 1,
|
|
|
'start_time' => time(),
|
|
'start_time' => time(),
|
|
|
'end_time' => time() + (365 * 24 * 60 * 60),
|
|
'end_time' => time() + (365 * 24 * 60 * 60),
|
|
|
- 'order_create_time' => $order->create_time,
|
|
|
|
|
|
|
+ 'order_create_time' => strtotime($order->create_time),
|
|
|
'adviser_1_id' => $order_product['adviser_1_id'],
|
|
'adviser_1_id' => $order_product['adviser_1_id'],
|
|
|
'store_id' => $order->store_id,
|
|
'store_id' => $order->store_id,
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time()
|
|
'update_time' => time()
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
+ $now = $order_product['real_price'] + $order_product['annuity'] + $order_product['sales_tax'];
|
|
|
|
|
+ array_push($update_order_products, [
|
|
|
|
|
+ 'id' => $order_product['id'],
|
|
|
|
|
+ 'service_charge' => $now * $item_service_charge,
|
|
|
|
|
+ 'zue_coin' => $now * $item_zue_coin,
|
|
|
|
|
+ 'transaction_price' => $now + ($now * $item_service_charge),
|
|
|
|
|
+ 'is_pay' => 1
|
|
|
|
|
+ ]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return $this->ok(true);
|
|
|
|
|
-
|
|
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
|
try {
|
|
try {
|
|
|
$update_order = [
|
|
$update_order = [
|
|
@@ -432,16 +462,21 @@ class OrderService extends \app\BaseService
|
|
|
'zue_coin_amount' => $order_use_zue_coin_amount,
|
|
'zue_coin_amount' => $order_use_zue_coin_amount,
|
|
|
'remarks' => $params['remarks']
|
|
'remarks' => $params['remarks']
|
|
|
];
|
|
];
|
|
|
|
|
+
|
|
|
if (round($receive_amount) == round($imposed_amount)) { // 支付满了
|
|
if (round($receive_amount) == round($imposed_amount)) { // 支付满了
|
|
|
$update_order['type'] = 1;
|
|
$update_order['type'] = 1;
|
|
|
- Db::table('erp_order_product')->where('order_id', $order->id)->update(['is_pay' => 1]);
|
|
|
|
|
|
|
+ if(count($update_order_products) > 0) {
|
|
|
|
|
+ foreach ($update_order_products as $item) {
|
|
|
|
|
+ Db::table('erp_order_product')->where('order_id', $item['id'])->update($item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if(count($order_annual_fees) > 0) {
|
|
if(count($order_annual_fees) > 0) {
|
|
|
Db::table('erp_order_annual_fee')->insertAll($order_annual_fees);
|
|
Db::table('erp_order_annual_fee')->insertAll($order_annual_fees);
|
|
|
}
|
|
}
|
|
|
if(count($update_store_products) > 0) {
|
|
if(count($update_store_products) > 0) {
|
|
|
foreach ($update_store_products as $update) {
|
|
foreach ($update_store_products as $update) {
|
|
|
- Db::table('erp_store_product')->where('id', $update['id'])->dec('now_stock',1);
|
|
|
|
|
- Db::table('erp_store_product')->where('id', $update['id'])->inc('sale_stock',1);
|
|
|
|
|
|
|
+ Db::table('erp_store_product')->where('id', $update['id'])->dec('now_stock',1)->update();
|
|
|
|
|
+ Db::table('erp_store_product')->where('id', $update['id'])->inc('sale_stock',1)->update();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -454,6 +489,10 @@ class OrderService extends \app\BaseService
|
|
|
'create_time' => time(),
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
'update_time' => time(),
|
|
|
]);
|
|
]);
|
|
|
|
|
+ if ($zue_coin > 0 && $change_zue_coin_record != null) {
|
|
|
|
|
+ Db::table('erp_zue_coin_record')->save($change_zue_coin_record);
|
|
|
|
|
+ Db::table('erp_customer_zue_coin')->where('id', $change_zue_coin_record['zue_coin_id'])->dec('zue_coin', $zue_coin)->update();
|
|
|
|
|
+ }
|
|
|
if(count($order_payments) > 0) {
|
|
if(count($order_payments) > 0) {
|
|
|
Db::table('erp_order_payment')->insertAll(array_map(function ($data) {
|
|
Db::table('erp_order_payment')->insertAll(array_map(function ($data) {
|
|
|
return [
|
|
return [
|