同步优化
This commit is contained in:
parent
fd2bb26303
commit
a7773e5c07
@ -6,6 +6,7 @@ use App\Models\Real\Order;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Domains\Real\Services\CommonService;
|
use App\Domains\Real\Services\CommonService;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use App\Domains\Real\Repositories\OrderRepository;
|
use App\Domains\Real\Repositories\OrderRepository;
|
||||||
use App\Domains\Real\Repositories\CompanyRepository;
|
use App\Domains\Real\Repositories\CompanyRepository;
|
||||||
use App\Domains\Real\Repositories\PackageRepository;
|
use App\Domains\Real\Repositories\PackageRepository;
|
||||||
@ -99,6 +100,7 @@ class AddedOrderSync extends Command
|
|||||||
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
|
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
|
||||||
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
|
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
|
||||||
|
|
||||||
|
if ($this->option('with-vd')) {
|
||||||
$orders = DB::table($virtualTable)->selectRaw('sim, order_id, unit_price, counts')
|
$orders = DB::table($virtualTable)->selectRaw('sim, order_id, unit_price, counts')
|
||||||
->where('created_at', '>=', $starttime->format('Y-m-d H:i:s'))
|
->where('created_at', '>=', $starttime->format('Y-m-d H:i:s'))
|
||||||
->where('created_at', '<=', $endtime->format('Y-m-d H:i:s'))
|
->where('created_at', '<=', $endtime->format('Y-m-d H:i:s'))
|
||||||
@ -113,15 +115,16 @@ class AddedOrderSync extends Command
|
|||||||
foreach ($data as &$value) {
|
foreach ($data as &$value) {
|
||||||
$i = array_count_values($simArray)[$value['sim']] ?? 0;
|
$i = array_count_values($simArray)[$value['sim']] ?? 0;
|
||||||
array_push($simArray, $value['sim']);
|
array_push($simArray, $value['sim']);
|
||||||
$valueOrders = $orders[$value['sim']] ?? [];
|
$virtualOrders = $orders[$value['sim']] ?? [];
|
||||||
|
|
||||||
$value['virtual_order_id'] = 0;
|
$value['virtual_order_id'] = 0;
|
||||||
|
|
||||||
foreach ($valueOrders as $key => $order) {
|
foreach ($virtualOrders as $key => $order) {
|
||||||
if ($order['counts'] === $value['counts'] && $order['unit_price'] === $value['unit_price']) {
|
if ($order['counts'] === $value['counts'] && $order['unit_price'] === $value['unit_price']) {
|
||||||
$value['virtual_order_id'] = $valueOrders[0]['order_id'] ?? 0;
|
$value['virtual_order_id'] = $virtualOrders[0]['order_id'] ?? 0;
|
||||||
unset($valueOrders[$key]);
|
unset($virtualOrders[$key]);
|
||||||
$orders[$value['sim']] = array_values($valueOrders);
|
$orders[$value['sim']] = array_values($virtualOrders);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,4 +270,11 @@ class AddedOrderSync extends Command
|
|||||||
|
|
||||||
return $orderArray;
|
return $orderArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getOptions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['--with-vd', null, InputOption::VALUE_NONE, '同步VD订单编号'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Domains\Real\Commands\Sync;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use App\Models\Real\Order;
|
use App\Models\Real\Order;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use App\Domains\Real\Repositories\OrderRepository;
|
use App\Domains\Real\Repositories\OrderRepository;
|
||||||
use App\Domains\Real\Repositories\CompanyRepository;
|
use App\Domains\Real\Repositories\CompanyRepository;
|
||||||
use App\Domains\Real\Repositories\PackageRepository;
|
use App\Domains\Real\Repositories\PackageRepository;
|
||||||
@ -50,6 +51,8 @@ class OrderBaseSync extends Command
|
|||||||
$this->line('插入订单关联数据,条数:' . count($cards));
|
$this->line('插入订单关联数据,条数:' . count($cards));
|
||||||
foreach (array_chunk($cards, $this->chunks) as $data) {
|
foreach (array_chunk($cards, $this->chunks) as $data) {
|
||||||
$this->getOutput()->write('.');
|
$this->getOutput()->write('.');
|
||||||
|
|
||||||
|
if ($this->option('with-vd')) {
|
||||||
$orders = DB::table('virtual_order_cards')->select(['sim', 'order_id'])
|
$orders = DB::table('virtual_order_cards')->select(['sim', 'order_id'])
|
||||||
->whereIn('sim', array_pluck($data, 'sim'))
|
->whereIn('sim', array_pluck($data, 'sim'))
|
||||||
->whereNull('refunded_at')
|
->whereNull('refunded_at')
|
||||||
@ -61,6 +64,9 @@ class OrderBaseSync extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
$only = ['company_id', 'package_id', 'counts', 'unit_price', 'virtual_order_id'];
|
$only = ['company_id', 'package_id', 'counts', 'unit_price', 'virtual_order_id'];
|
||||||
|
} else {
|
||||||
|
$only = ['company_id', 'package_id', 'counts', 'unit_price'];
|
||||||
|
}
|
||||||
|
|
||||||
DB::table('real_order_cards')->upsert($data, ['sim', 'order_id'], $only);
|
DB::table('real_order_cards')->upsert($data, ['sim', 'order_id'], $only);
|
||||||
}
|
}
|
||||||
@ -257,4 +263,12 @@ class OrderBaseSync extends Command
|
|||||||
|
|
||||||
return $orderItems;
|
return $orderItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getOptions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['--with-vd', null, InputOption::VALUE_NONE, '同步VD订单编号'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user