80 lines
2.7 KiB
PHP
Executable File
80 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Enums\BoolEnum;
|
|
use App\Enums\LottState;
|
|
use App\Model\OrderGuanYaResult;
|
|
use App\Model\Zq\JczqGuanYaOdds;
|
|
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 RefreshOrderGuanYaResult implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
protected $jczqGuanYaOddsId;
|
|
|
|
public function __construct($jczqGuanYaOddsId)
|
|
{
|
|
$this->jczqGuanYaOddsId = $jczqGuanYaOddsId;
|
|
$this->queue = config('queue.names.refresh_order_odds');
|
|
}
|
|
public function getData() {
|
|
return [
|
|
'jczqGuanYaOddsId' => $this->jczqGuanYaOddsId
|
|
];
|
|
}
|
|
public function handle()
|
|
{
|
|
Log::info('guanyakaijiang doing RefreshOrderGuanYaResult, guanOddsId:' .$this->jczqGuanYaOddsId);
|
|
$result = JczqGuanYaOdds::find($this->jczqGuanYaOddsId);
|
|
if (!$result) {
|
|
Log::error("RefreshOrderGuanYaResult not found resultId,", $this->getData());
|
|
return;
|
|
}
|
|
|
|
OrderGuanYaResult::leftJoin('order', 'order.id', '=', 'order_guan_ya_result.order_id')
|
|
->select('order_guan_ya_result.*')
|
|
->where('order.lottery_state', LottState::WAIT)
|
|
->where('order_guan_ya_result.published', BoolEnum::NO)
|
|
->where('order_guan_ya_result.jczq_guan_ya_odds_id', $result->id)
|
|
->chunkById(500, function ($data) {
|
|
|
|
if (count($data) <= 0) {
|
|
return;
|
|
}
|
|
|
|
// 更新发布状态
|
|
$orderResultIds = $data->pluck('id')->toArray();
|
|
OrderGuanYaResult::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 = OrderGuanYaResult::where('order_id', $orderId)
|
|
->where('published', BoolEnum::NO)->count();
|
|
Log::info('will dispatch ComputeGuanYaOrderPrize, orderId:', [
|
|
'orderId' => $orderId,
|
|
'$unPublishes' => $unPublishes,
|
|
]);
|
|
// 如果全部已公布,则计算奖金
|
|
if ($unPublishes == 0) {
|
|
Log::info('dispatch ComputeGuanYaOrderPrize, orderId:'.$orderId);
|
|
ComputeGuanYaOrderPrize::dispatch($orderId);
|
|
}
|
|
}
|
|
}
|