转销售优化
This commit is contained in:
parent
e81521e899
commit
86e5b508d6
@ -235,6 +235,7 @@ class OrderService extends Service
|
||||
|
||||
if ($attributes['type'] !== 0) {
|
||||
$simArray = array_unique(array_pluck($attributes['selected'], 'sim'));
|
||||
$simArray = array_map('intval', $simArray);
|
||||
$simCompany = $this->orderCardPartitionRepository->select(['sim', 'company_id'])
|
||||
->where('type', 0)->whereIn('sim', $simArray)
|
||||
->get()->pluck('company_id', 'sim')->toArray();
|
||||
@ -255,13 +256,6 @@ class OrderService extends Service
|
||||
}
|
||||
|
||||
if (count($news)) {
|
||||
// 按订单时间激活
|
||||
$array = array_map(function ($item) use ($newOrderData) {
|
||||
return ['sim' => $item, 'virtual_activated_at' => $newOrderData['order_at']];
|
||||
}, $news);
|
||||
|
||||
Card::upsert($array, 'sim', ['virtual_activated_at']);
|
||||
|
||||
// 创建订单
|
||||
$newOrderData = array_except($attributes, ['selected', 'sign']);
|
||||
$newOrderData['id'] = ++$maxId;
|
||||
@ -277,6 +271,13 @@ class OrderService extends Service
|
||||
|
||||
$newOrder = $this->orderRepository->create($newOrderData);
|
||||
|
||||
// 按订单时间激活
|
||||
$array = array_map(function ($item) use ($newOrderData) {
|
||||
return ['sim' => $item, 'virtual_activated_at' => $newOrderData['order_at']];
|
||||
}, $news);
|
||||
|
||||
Card::upsert($array, 'sim', ['virtual_activated_at']);
|
||||
|
||||
// 创建订单卡关联
|
||||
$this->upsertOrderCards(array_map(function ($item) {
|
||||
return ['sim' => $item, 'counts' => 1];
|
||||
@ -321,12 +322,19 @@ class OrderService extends Service
|
||||
$having = "MAX(service_end_at) < '%s'";
|
||||
$having = sprintf($having, Carbon::now()->subMonths(6)->endOfMonth());
|
||||
|
||||
$replacement = $this->orderCardPartitionRepository->select(['sim'])
|
||||
$subQuery = OrderCardPartition::select(['sim', DB::raw('MAX(service_end_at) as service_end_at')])
|
||||
->whereIn('type', [0, 1])
|
||||
->where('company_id', $attributes['company_id'])
|
||||
->where('package_id', $attributes['package_id'])
|
||||
->whereIn('type', [0, 1])
|
||||
->groupBy('sim')
|
||||
->havingRaw($having)
|
||||
->where('original_sim', 0)
|
||||
->groupBy('sim');
|
||||
|
||||
$replacement = DB::table(DB::raw("({$subQuery->toSql()}) as sub"))
|
||||
->mergeBindings($subQuery->getQuery())
|
||||
->select(['sim'])
|
||||
->orderBy('service_end_at')
|
||||
->where('service_end_at', '<', Carbon::now()->subMonths(6)->endOfMonth())
|
||||
->limit(count($extras))
|
||||
->get()->pluck('sim')->toArray();
|
||||
|
||||
if (count($replacement) !== count($extras)) {
|
||||
@ -341,7 +349,19 @@ class OrderService extends Service
|
||||
];
|
||||
}
|
||||
|
||||
$this->orderCardPartitionRepository->updateBatch($updates, 'sim');
|
||||
$parameters = implode(',', array_map(function ($item) {
|
||||
return "({$item['sim']}, {$item['original_sim']})";
|
||||
}, $updates));
|
||||
|
||||
$sql = "WITH RECURSIVE as_table(sim, original_sim) AS (VALUES {$parameters}), update_olds AS (
|
||||
UPDATE virtual_order_cards_partition SET sim = as_table.sim, original_sim = as_table.original_sim
|
||||
FROM as_table WHERE virtual_order_cards_partition.sim = as_table.original_sim
|
||||
)
|
||||
UPDATE virtual_order_cards_partition SET sim = as_table.original_sim, original_sim = as_table.sim
|
||||
FROM as_table WHERE virtual_order_cards_partition.sim = as_table.sim;
|
||||
";
|
||||
|
||||
DB::statement($sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
1
public/css/chunk-6ea47298.6166dab5.css
Normal file
1
public/css/chunk-6ea47298.6166dab5.css
Normal file
@ -0,0 +1 @@
|
||||
[data-v-c9ef48cc] .ivu-table-cell{word-break:keep-all}
|
2
public/css/chunk-8064e07e.03f6c57e.css
Normal file
2
public/css/chunk-8064e07e.03f6c57e.css
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.bd7825a5.js
Normal file
1
public/js/app.bd7825a5.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-6ea47298.07ba845a.js
Normal file
1
public/js/chunk-6ea47298.07ba845a.js
Normal file
File diff suppressed because one or more lines are too long
14
public/js/chunk-8064e07e.d32c31eb.js
Normal file
14
public/js/chunk-8064e07e.d32c31eb.js
Normal file
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-00bf5f96.b87abb00.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/js/chunk-00ae0766.d130b440.js rel=prefetch><link href=/js/chunk-00bf5f96.60fa58d1.js rel=prefetch><link href=/js/chunk-07a274ec.55e1b3b0.js rel=prefetch><link href=/js/chunk-996b1e80.92847c4e.js rel=prefetch><link href=/css/app.8e379248.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.2c6fccfd.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.8e379248.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.2c6fccfd.js></script></body></html>
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-6ea47298.6166dab5.css rel=prefetch><link href=/css/chunk-8064e07e.03f6c57e.css rel=prefetch><link href=/js/chunk-00ae0766.d130b440.js rel=prefetch><link href=/js/chunk-07a274ec.55e1b3b0.js rel=prefetch><link href=/js/chunk-6ea47298.07ba845a.js rel=prefetch><link href=/js/chunk-8064e07e.d32c31eb.js rel=prefetch><link href=/css/app.8e379248.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.bd7825a5.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.8e379248.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.bd7825a5.js></script></body></html>
|
Loading…
x
Reference in New Issue
Block a user