70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Order;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class OrderGrowthValue extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'order:growth-value {order?}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '发放订单成长值';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$service = new \App\Services\DistributeService();
|
|
while (true) {
|
|
try {
|
|
DB::beginTransaction();
|
|
$query = Order::where('status', Order::STATUS_COMPLETED);
|
|
if ($id = $this->argument('order')) {
|
|
$query->whereIn('id', explode(',', $id));
|
|
}
|
|
$orders = $query->get();
|
|
$this->line('总数: ' . $orders->count());
|
|
$count = 0;
|
|
foreach($orders as $order) {
|
|
$profit = $service->incrementGrowthValue($order);
|
|
if ($profit) {
|
|
$count++;
|
|
}
|
|
}
|
|
$this->info('符合要求: ' . $count);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
$this->line($th);
|
|
}
|
|
sleep(60);
|
|
}
|
|
}
|
|
}
|