用原有卡替换方式

This commit is contained in:
邓皓元 2019-04-18 09:12:30 +08:00
parent 86e5b508d6
commit a35fd9569a

View File

@ -255,6 +255,8 @@ class OrderService extends Service
}
}
/**
* 转销售方式
if (count($news)) {
// 创建订单
$newOrderData = array_except($attributes, ['selected', 'sign']);
@ -315,6 +317,41 @@ class OrderService extends Service
$attributes['counts'] = array_sum(array_pluck($selectedNews, 'counts'));
$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)) {
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;