82 lines
2.6 KiB
PHP
Executable File
82 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Enums\BoolEnum;
|
|
use App\Enums\LottState;
|
|
use App\Model\OrderGuanResult;
|
|
use App\Model\Zq\JczqGuanOdds;
|
|
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 RefreshOrderGuanResult implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
protected $jczqGuanOddsId;
|
|
|
|
public function __construct($jczqGuanOddsId)
|
|
{
|
|
$this->jczqGuanOddsId = $jczqGuanOddsId;
|
|
$this->queue = config('queue.names.refresh_order_odds');
|
|
}
|
|
public function getData() {
|
|
return [
|
|
'jczqGuanOddsId' => $this->jczqGuanOddsId
|
|
];
|
|
}
|
|
public function handle()
|
|
{
|
|
Log::info('guankaijiang doing RefreshOrderGuanResult, guanOddsId:' .$this->jczqGuanOddsId);
|
|
$result = JczqGuanOdds::find($this->jczqGuanOddsId);
|
|
if (!$result) {
|
|
Log::error("RefreshOrderGuanResult not found resultId,", $this->getData());
|
|
return;
|
|
}
|
|
|
|
OrderGuanResult::leftJoin('order', 'order.id', '=', 'order_guan_result.order_id')
|
|
->select('order_guan_result.*')
|
|
->where('order.lottery_state', LottState::WAIT)
|
|
->where('order_guan_result.published', BoolEnum::NO)
|
|
->where('order_guan_result.jczq_guan_odds_id', $result->id)
|
|
->chunkById(500, function ($data) {
|
|
|
|
if (count($data) <= 0) {
|
|
return;
|
|
}
|
|
|
|
// 更新发布状态
|
|
$orderResultIds = $data->pluck('id')->toArray();
|
|
OrderGuanResult::whereIn('id', $orderResultIds)
|
|
->update(['published' => BoolEnum::YES]);
|
|
|
|
// 执行计算任务
|
|
$orderIds = $data->pluck('order_id')->toArray();
|
|
foreach ($orderIds as $orderId) {
|
|
$this->dispatchComputeOrderPrize($orderId);
|
|
}
|
|
});
|
|
}
|
|
|
|
private function dispatchComputeOrderPrize($orderId)
|
|
{
|
|
$unPublishes = OrderGuanResult::where('order_id', $orderId)
|
|
->where('published', BoolEnum::NO)->count();
|
|
|
|
Log::info('will dispatch ComputeGuanOrderPrize, orderId:', [
|
|
'orderId' => $orderId,
|
|
'$unPublishes' => $unPublishes,
|
|
]);
|
|
|
|
// 如果全部已公布,则计算奖金
|
|
if ($unPublishes == 0) {
|
|
Log::info('dispatch ComputeGuanOrderPrize, orderId:'.$orderId);
|
|
ComputeGuanOrderPrize::dispatch($orderId);
|
|
}
|
|
}
|
|
}
|