<?php


namespace console\controllers;

use common\models\LwtPhoneMessageList;
use common\util\PhoneMessage;
use yii\console\Controller;

class PhoneController extends Controller
{
    public function actionSend()
    {
        $resultList = [];
        $idList = [];
        $LwtPhoneMessageList = LwtPhoneMessageList::find()->where(["is_send" => 0])->all();
        foreach ($LwtPhoneMessageList as $LwtPhoneMessage) {
            /** @var LwtPhoneMessageList $LwtPhoneMessage */
            foreach (PhoneMessage::$phoneList as $phone) {
                $resultList[] = PhoneMessage::sendNoticeMsg($phone, $LwtPhoneMessage->company_name, $LwtPhoneMessage->code);
            }
            $idList[] = $LwtPhoneMessage->id;
        }
        if ($idList != []) {
            LwtPhoneMessageList::updateAll(["is_send" => 1, "update_time" => time()], ["id" => $idList]);
        }
        var_dump($resultList);
    }
}