50 lines
1.5 KiB
PHP
Executable File
50 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Console\Commands\GenerateCustomerRanking;
|
|
use App\Enums\LottState;
|
|
use App\Enums\OrderType;
|
|
use App\Events\OrderWinedEvent;
|
|
use App\Model\Customer\Customer;
|
|
use App\Model\Order;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class GenerateCustomerRankingJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var OrderWinedEvent */
|
|
protected $event;
|
|
|
|
public function __construct($event)
|
|
{
|
|
$this->event = $event;
|
|
$this->queue = config('queue.names.generate_customer_ranking');
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info('GenerateCustomerRankingJob::start, orderId:' . $this->event->orderId);
|
|
|
|
$order = Order::find($this->event->orderId);
|
|
if (!$order) {
|
|
Log::error('GenerateCustomerRankingJob:: error, not found order, orderId:' . $this->event->orderId);
|
|
return;
|
|
}
|
|
|
|
if ($order->lottery_state == LottState::WIN && $order->type == OrderType::FADAN) {
|
|
$customer = Customer::find($order->customer_id);
|
|
$command = new GenerateCustomerRanking();
|
|
$command->generateRankingData($customer, date('Ymd'));
|
|
} else {
|
|
Log::info('GenerateCustomerRankingJob , is not fadan, or not win' . $this->event->orderId);
|
|
}
|
|
}
|
|
}
|