70 lines
2.0 KiB
PHP
Executable File
70 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Enums\BoolEnum;
|
|
use App\Enums\LottState;
|
|
use App\Enums\LottType;
|
|
use App\Enums\PayState;
|
|
use App\Model\Pls;
|
|
use App\Model\LotteryType;
|
|
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 RefreshOrderPlsResult implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
protected $plsId;
|
|
|
|
public function __construct($plsId)
|
|
{
|
|
$this->plsId = $plsId;
|
|
$this->queue = config('queue.names.refresh_order_odds');
|
|
}
|
|
public function getData() {
|
|
return [
|
|
'$plsId' => $this->plsId
|
|
];
|
|
}
|
|
public function handle()
|
|
{
|
|
Log::info('RefreshOrderPlsResult::start, plsId:' . $this->plsId);
|
|
$lotteryType = LotteryType::where('type', LottType::PLS)->first();
|
|
if (!$lotteryType) {
|
|
Log::error('RefreshOrderPlsResult 无排列三彩种');
|
|
return;
|
|
}
|
|
|
|
$pls = Pls::find($this->plsId);
|
|
if (!$pls) {
|
|
Log::error('RefreshOrderPlsResult plsId not found:' . $this->plsId);
|
|
return;
|
|
}
|
|
if ($pls->state != BoolEnum::YES) {
|
|
Log::error('RefreshOrderPlsResult plsId not publish result:' . $this->plsId);
|
|
return;
|
|
}
|
|
Order::where('lottery_type_id', $lotteryType->id)
|
|
->where('issue_num', $pls->issue_num)
|
|
->where('pay_state', PayState::SUCCESS)
|
|
->where('lottery_state', LottState::WAIT)
|
|
->chunkById(500, function($orders) use ($pls) {
|
|
foreach ($orders as $order) {
|
|
$this->dispatchComputeOrderPrize($order->id);
|
|
}
|
|
});
|
|
}
|
|
|
|
private function dispatchComputeOrderPrize($orderId)
|
|
{
|
|
Log::info('dispatch ComputePlsOrderPrize, orderId:'.$orderId);
|
|
ComputePlsOrderPrize::dispatch($orderId);
|
|
}
|
|
}
|