jingcai-php/app/Jobs/RefreshOrderQxcResult.php

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