优化同步机制

This commit is contained in:
邓皓元 2019-08-13 14:35:05 +08:00
parent 97ccf8696c
commit ba1745124a
4 changed files with 16 additions and 6 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console;
use Carbon\Carbon;
use App\Jobs\QueuedCommand;
use Illuminate\Support\Facades\DB;
use Illuminate\Console\Scheduling\Schedule;
@ -28,6 +29,10 @@ class Kernel extends ConsoleKernel
{
$logPath = storage_path('logs/artisan.log');
$schedule->command('real:sync-activated')->cron('* */4 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command(sprintf('real:sync-activated %s', Carbon::now()->subDays(2)->format('Y-m-d')))->cron('0 3 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command(sprintf('real:sync-activated %s', Carbon::now()->subDays(3)->format('Y-m-d')))->cron('0 3 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command(sprintf('real:sync-activated %s', Carbon::now()->subDays(4)->format('Y-m-d')))->cron('0 3 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command(sprintf('real:sync-activated %s', Carbon::now()->subDays(5)->format('Y-m-d')))->cron('0 3 * * *')->withoutOverlapping()->appendOutputTo($logPath);
$schedule->command('virtual:schedule-auto-activate')->cron('* * * 1 *')->withoutOverlapping()->appendOutputTo($logPath);
// $schedule->command('virtual:schedule-vd-activate')->cron('0 2 * * *')->withoutOverlapping()->appendOutputTo($logPath);

View File

@ -23,6 +23,8 @@ class ActivatedSync extends Command
public function handle()
{
$day = $this->getDay();
$this->line('开始' . $this->description . '#:' . $day);
$startMicrotime = new UTCDateTime($day->copy()->startOfDay());
$endMicrotime = new UTCDateTime($day->copy()->endOfDay());
@ -38,7 +40,7 @@ class ActivatedSync extends Command
$total = $query->count();
$this->line('待同步条数:'.$total);
$this->line('待同步条数:' . $total);
$page = 1;
@ -54,7 +56,7 @@ class ActivatedSync extends Command
$array = $res->map(function ($item) {
return [
'sim' => $item['cNo'],
'activated_at' => $item['saDate'] ? (string)Carbon::createFromTimestampMs(strval($item['saDate'])) : null,
'activated_at' => $item['saDate'] ? (string) Carbon::createFromTimestampMs(strval($item['saDate'])) : null,
];
})->all();
@ -62,7 +64,7 @@ class ActivatedSync extends Command
->whereNotNull('virtual_activated_at')->get()->pluck('sim')->toArray();
foreach ($array as $key => $value) {
if(in_array($value['sim'], $exists)){
if (in_array($value['sim'], $exists)) {
unset($array);
}
}

View File

@ -1018,8 +1018,11 @@ class OrderService extends Service
->whereIn('sim', array_pluck($value, 'sim'))->update(['virtual_order_id' => $node['id']]);
}
$simArray = array_pluck($data, 'sim');
MongoCardJob::dispatch($simArray)->onQueue('sync');
// 只要销售订单同步卡信息即可
if ($node['type'] === 0) {
$simArray = array_pluck($data, 'sim');
MongoCardJob::dispatch($simArray)->onQueue('sync');
}
}
public function refundedList(array $conditions = [])

View File

@ -11,7 +11,7 @@ use App\Domains\Stats\Exports\CompanyReportExport;
require_once realpath(dirname(__FILE__) . '/TestCase.php');
$conditions = [
'type' => [0, 1],
'type' => [2, 3],
'company_name' => '福建车媒通网络科技有限公司',
'month' => '2016-01'
];