jingcai-php/app/Console/Commands/Zq/JczqResultRepair.php

72 lines
1.9 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Enums\BoolEnum;
use App\Enums\LottState;
use App\Jobs\ComputeJczqOrderPrize;
use App\Model\Order;
use App\Model\OrderJczqResult;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class JczqResultRepair extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:jczq_result_repair';
/**
* 命令的说明描述
* @var string
*/
protected $description = '竞彩足球开奖结果有时候会莫名奇妙的不更新数据,此脚本做补充';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
$orderIds = OrderJczqResult::where('updated_at', '>', date('Y-m-d H:i:s', strtotime('-2 hour')))
->where('updated_at', '<=', date('Y-m-d H:i:s', time() - 30*60))
->where('published', BoolEnum::YES)
->pluck('order_id')
->toArray();
if (!$orderIds) {
return;
}
$orderIds = array_unique($orderIds);
if (!$orderIds) {
return;
}
$orderIds = Order::whereIn('id', $orderIds)->where('lottery_state', LottState::WAIT)->pluck('id')->toArray();
if (!$orderIds) {
return;
}
foreach ($orderIds as $orderId) {
$unPublishes = OrderJczqResult::where('order_id', $orderId)
->where('published', BoolEnum::NO)->count();
// 如果全部已公布,则计算奖金
if ($unPublishes == 0) {
Log::error('repair-- dispatch ComputeJczqOrderPrize, orderId:'.$orderId);
ComputeJczqOrderPrize::dispatch($orderId);
}
}
}
}