优化同步,排除已有的
This commit is contained in:
parent
71a7ae3944
commit
107bdbcf82
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domains\Real\Commands\Sync;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Card\Card;
|
||||
use App\Models\Real\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -116,7 +118,16 @@ class AddedOrderSync extends Command
|
||||
$value['virtual_order_id'] = $orders[$value['sim']][$i]['order_id'] ?? 0;
|
||||
}
|
||||
|
||||
MongoCardJob::dispatch(array_pluck($data, 'sim'))->onQueue('sync');
|
||||
if (Carbon::now()->diffInMonths($this->datetime) < 2) {
|
||||
$exists = Card::select('sim')->whereIn('sim', array_pluck($data, 'sim'))
|
||||
->whereNotNull('virtual_activated_at')->get()->pluck('sim')->toArray();
|
||||
|
||||
$simArray = array_diff(array_pluck($data, 'sim'), $exists);
|
||||
|
||||
if (!empty($simArray)) {
|
||||
MongoCardJob::dispatch($simArray)->onQueue('sync');
|
||||
}
|
||||
}
|
||||
|
||||
$only = ['company_id', 'package_id', 'counts', 'unit_price'];
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Domains\Real\Commands\Sync;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Card\Card;
|
||||
use App\Models\Real\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Card\Jobs\MongoCardJob;
|
||||
@ -36,6 +37,8 @@ class OrderBaseSync extends Command
|
||||
|
||||
try {
|
||||
DB::transaction(function () use ($orders, $cards) {
|
||||
$datetime = $this->getDateTime();
|
||||
|
||||
$this->line('插入订单数据,条数:'.count($orders));
|
||||
foreach (array_chunk($orders, $this->chunks) as $data) {
|
||||
$this->getOutput()->write('.');
|
||||
@ -54,7 +57,16 @@ class OrderBaseSync extends Command
|
||||
$value['virtual_order_id'] = $orders[$value['sim']] ?? 0;
|
||||
}
|
||||
|
||||
MongoCardJob::dispatch(array_pluck($data, 'sim'))->onQueue('sync');;
|
||||
if (Carbon::now()->diffInMonths($datetime) < 2) {
|
||||
$exists = Card::select('sim')->whereIn('sim', array_pluck($data, 'sim'))
|
||||
->whereNotNull('virtual_activated_at')->get()->pluck('sim')->toArray();
|
||||
|
||||
$simArray = array_diff(array_pluck($data, 'sim'), $exists);
|
||||
|
||||
if (!empty($simArray)) {
|
||||
MongoCardJob::dispatch($simArray)->onQueue('sync');
|
||||
}
|
||||
}
|
||||
|
||||
$only = [ 'order_id', 'company_id', 'package_id', 'counts', 'unit_price'];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user