用原有卡替换方式
This commit is contained in:
parent
86e5b508d6
commit
a35fd9569a
@ -255,6 +255,8 @@ class OrderService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转销售方式
|
||||||
if (count($news)) {
|
if (count($news)) {
|
||||||
// 创建订单
|
// 创建订单
|
||||||
$newOrderData = array_except($attributes, ['selected', 'sign']);
|
$newOrderData = array_except($attributes, ['selected', 'sign']);
|
||||||
@ -315,6 +317,41 @@ class OrderService extends Service
|
|||||||
$attributes['counts'] = array_sum(array_pluck($selectedNews, 'counts'));
|
$attributes['counts'] = array_sum(array_pluck($selectedNews, 'counts'));
|
||||||
$attributes['selected'] = array_values($selectedNews);
|
$attributes['selected'] = array_values($selectedNews);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** 用原有卡替换方式 */
|
||||||
|
if (count($news)) {
|
||||||
|
$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($news))
|
||||||
|
->get()->pluck('sim')->toArray();
|
||||||
|
|
||||||
|
if (count($replacement) !== count($news)) {
|
||||||
|
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
|
||||||
|
}
|
||||||
|
|
||||||
|
$updates = [];
|
||||||
|
foreach ($news as $key => $value) {
|
||||||
|
$updates[] = [
|
||||||
|
'sim' => $value,
|
||||||
|
'original_sim' => $replacement[$key],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$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 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
|
||||||
|
";
|
||||||
|
|
||||||
|
DB::statement($sql);
|
||||||
|
}
|
||||||
|
|
||||||
if (count($extras)) {
|
if (count($extras)) {
|
||||||
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
|
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user