替卡方式
This commit is contained in:
parent
a35fd9569a
commit
0df7e107ec
@ -255,9 +255,8 @@ class OrderService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 用转销售方式创建
|
||||||
* 转销售方式
|
if ($attributes['use_type'] === 1 && count($news)) {
|
||||||
if (count($news)) {
|
|
||||||
// 创建订单
|
// 创建订单
|
||||||
$newOrderData = array_except($attributes, ['selected', 'sign']);
|
$newOrderData = array_except($attributes, ['selected', 'sign']);
|
||||||
$newOrderData['id'] = ++$maxId;
|
$newOrderData['id'] = ++$maxId;
|
||||||
@ -316,18 +315,31 @@ 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);
|
||||||
|
$news = [];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/** 用原有卡替换方式 */
|
// 替卡方式
|
||||||
if (count($news)) {
|
if (count($news) || count($extras)) {
|
||||||
$replacement = DB::table(DB::raw("({$subQuery->toSql()}) as sub"))
|
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
|
||||||
|
|
||||||
|
$having = "MAX(service_end_at) < '%s'";
|
||||||
|
$having = sprintf($having, Carbon::now()->subMonths(6)->endOfMonth());
|
||||||
|
|
||||||
|
$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'])
|
||||||
|
->where('original_sim', 0)
|
||||||
|
->groupBy('sim');
|
||||||
|
|
||||||
|
$replacementQuery = DB::table(DB::raw("({$subQuery->toSql()}) as sub"))
|
||||||
->mergeBindings($subQuery->getQuery())
|
->mergeBindings($subQuery->getQuery())
|
||||||
->select(['sim'])
|
->select(['sim'])
|
||||||
->orderBy('service_end_at')
|
->orderBy('service_end_at')
|
||||||
->where('service_end_at', '<', Carbon::now()->subMonths(6)->endOfMonth())
|
->where('service_end_at', '<', Carbon::now()->subMonths(6)->endOfMonth());
|
||||||
->limit(count($news))
|
|
||||||
->get()->pluck('sim')->toArray();
|
if (count($news)) {
|
||||||
|
$replacement = $replacementQuery->limit(count($news))->get()->pluck('sim')->toArray();
|
||||||
|
|
||||||
if (count($replacement) !== count($news)) {
|
if (count($replacement) !== count($news)) {
|
||||||
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
|
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
|
||||||
@ -354,25 +366,7 @@ class OrderService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($extras)) {
|
if (count($extras)) {
|
||||||
$attributes['package_id'] = $attributes['package_id'] ?? $product->package_id;
|
$replacement = $replacementQuery->limit(count($extras))->get()->pluck('sim')->toArray();
|
||||||
|
|
||||||
$having = "MAX(service_end_at) < '%s'";
|
|
||||||
$having = sprintf($having, Carbon::now()->subMonths(6)->endOfMonth());
|
|
||||||
|
|
||||||
$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'])
|
|
||||||
->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)) {
|
if (count($replacement) !== count($extras)) {
|
||||||
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
|
throw new NotAllowedException('可替换的卡量不足,不能进行转销售操作');
|
||||||
@ -401,6 +395,7 @@ class OrderService extends Service
|
|||||||
DB::statement($sql);
|
DB::statement($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($attributes['counts'] !== 0) {
|
if ($attributes['counts'] !== 0) {
|
||||||
$attributes['id'] = ++$maxId;
|
$attributes['id'] = ++$maxId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user