出现重复销售卡

This commit is contained in:
邓皓元 2019-08-16 10:49:57 +08:00
parent 4946b9f1fe
commit 8c80e68ab8
2 changed files with 8 additions and 9 deletions

View File

@ -5,7 +5,6 @@ namespace App\Core;
use App\Models\Export\Export;
use Illuminate\Support\Carbon;
use Dipper\Excel\Events\AfterStore;
use Dipper\Excel\Concerns\WithTitle;
use Dipper\Excel\Events\AfterExport;
use Dipper\Excel\Concerns\Exportable;
use Dipper\Excel\Concerns\WithEvents;
@ -16,7 +15,7 @@ use Illuminate\Support\Facades\Storage;
use Dipper\Excel\Concerns\ShouldAutoSize;
use App\Domains\Export\Repositories\ExportRepository;
abstract class AbstractExport implements WithEvents, WithTitle, ShouldAutoSize
abstract class AbstractExport implements WithEvents, ShouldAutoSize
{
use Exportable;

View File

@ -394,15 +394,14 @@ class OrderService extends Service
if (isset($attributes['selected']) && is_array($attributes['selected']) && count($attributes['selected'])) {
if ($attributes['type'] === 0) {
$exists = $this->orderCardPartitionRepository->withConditions([
$exists = $this->orderCardPartitionRepository->select('sim')->withConditions([
'type' => 0,
'sim' => array_pluck($attributes['selected'], 'sim')
])->count();
])->get()->pluck('sim')->toArray();
if ($exists) {
if (!empty($exists)) {
DB::rollBack();
$simArray = implode(',', array_pluck($attributes['selected'], 'sim'));
throw new NotAllowedException("存在已被其他订单使用的卡: ($simArray)");
throw new NotAllowedException("存在已被其他订单使用的卡 #:" . implode(',', $exists));
}
}
@ -1008,8 +1007,9 @@ class OrderService extends Service
$data = array_values($data);
foreach (array_chunk($data, 1000) as $value) {
if ($table === 'virtual_order_cards' && DB::table($table)->whereIn('sim', array_pluck($value, 'sim'))->whereNull('deleted_at')->count()) {
throw new ExistedException('出现重复销售卡');
if ($table === 'virtual_order_cards') {
$exists = DB::table($table)->whereIn('sim', array_pluck($value, 'sim'))->whereNull('deleted_at')->get()->pluck('sim')->toArray();
throw new ExistedException('出现重复销售卡 #:', implode(',', $exists));
}
DB::table($table)->upsert($value, ['sim', 'order_id', 'refunded_at', 'deleted_at']);