58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Dealer;
|
|
|
|
use App\Enums\DealerOrderStatus;
|
|
use App\Models\DealerOrder;
|
|
use App\Services\Dealer\OrderService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class OrderAutoAllocate extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'dealer:order-auto-allocate';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '自动分配订单';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
DealerOrder::where('status', DealerOrderStatus::Pending)
|
|
->where('consignor_id', '>', 1)//到1用户或者公司的订单不需要再分配
|
|
->where('allocated_at', '<', now()->subMinutes(app_settings('dealer.order_auto_allocate_times')))
|
|
->chunkById(200, function ($orders) {
|
|
$orders->load([
|
|
'consignor',
|
|
]);
|
|
$orderService = new OrderService();
|
|
foreach ($orders as $order) {
|
|
try {
|
|
DB::beginTransaction();
|
|
$orderService->updateOrderConsignor($order);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
}
|
|
}
|
|
});
|
|
|
|
return 0;
|
|
}
|
|
}
|