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\Plw;
|
|
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 RefreshOrderPlwResult implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
protected $plwId;
|
|
|
|
public function __construct($plwId)
|
|
{
|
|
$this->plwId = $plwId;
|
|
$this->queue = config('queue.names.refresh_order_odds');
|
|
}
|
|
public function getData() {
|
|
return [
|
|
'$plwId' => $this->plwId
|
|
];
|
|
}
|
|
public function handle()
|
|
{
|
|
Log::info('RefreshOrderPlwResult::start, plwId:' . $this->plwId);
|
|
$lotteryType = LotteryType::where('type', LottType::PLW)->first();
|
|
if (!$lotteryType) {
|
|
Log::error('RefreshOrderPlwResult 无排列五彩种');
|
|
return;
|
|
}
|
|
|
|
$plw = Plw::find($this->plwId);
|
|
if (!$plw) {
|
|
Log::error('RefreshOrderPlwResult plwId not found:' . $this->plwId);
|
|
return;
|
|
}
|
|
if ($plw->state != BoolEnum::YES) {
|
|
Log::error('RefreshOrderPlwResult plwId not publish result:' . $this->plwId);
|
|
return;
|
|
}
|
|
Order::where('lottery_type_id', $lotteryType->id)
|
|
->where('issue_num', $plw->issue_num)
|
|
->where('pay_state', PayState::SUCCESS)
|
|
->where('lottery_state', LottState::WAIT)
|
|
->chunkById(500, function($orders) use ($plw) {
|
|
foreach ($orders as $order) {
|
|
$this->dispatchComputeOrderPrize($order->id);
|
|
}
|
|
});
|
|
}
|
|
|
|
private function dispatchComputeOrderPrize($orderId)
|
|
{
|
|
Log::info('dispatch ComputePlwOrderPrize, orderId:'.$orderId);
|
|
ComputePlwOrderPrize::dispatch($orderId);
|
|
}
|
|
}
|