<?php
namespace app\common\command;

use app\common\model\bank_account\BankAccount;
use app\common\model\master_worker\MasterWorker;
use app\common\model\master_worker\MasterWorkerInfo;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;

/**
 *  工程师每日开启接单的通知【给工程师的通知】
 * Class OpenObtainOrder
 * @package app\command
 */
class OpenObtainOrder extends Command
{
    protected function configure()
    {
        $this->setName('open_obtain_order')->setDescription('每天定时发送工程师开启接单提醒');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $infoWorkerIds = MasterWorkerInfo::where(['audit_state'=>1])->column('worker_id');
            $bankWorkerIds = BankAccount::where(['audit_state'=>1])->column('worker_id');
            $ids = array_intersect($infoWorkerIds,$bankWorkerIds);
            $workerIds = MasterWorker::where([['audit_state',"IN",($ids?:[0])],['accept_order_status','=',0]])->column('id')?:[9];
            Log::write('OpenObtainOrder:workerIds:'.json_encode($workerIds));
            foreach ($workerIds as $workerId) {
                event('Notice',  [
                    'scene_id' => 112,
                    'params' => [
                        'user_id' => $workerId,
                    ]
                ]);
            }
            return true;
        } catch (\Exception $e) {
            Log::write('OpenObtainOrder:'.$e->getMessage());
            return false;
        }

    }
}