public function actionAlarmFindBak()
 {
     $configs = SmsConfig::find()->all();
     foreach ($configs as $config) {
         $LastId = Yii::$app->cache->get("config_last_id_" . $config->id);
         if (!$LastId) {
             $LastId = 0;
         }
         $phones = implode(',', array_filter($this->getPhoneNum($config->receivers)));
         if (empty($phones)) {
             continue;
         }
         $condition = $config->alarmCondition;
         $alarms = DeviceAlarm::find()->where(['and', 'serial_num > ' . $LastId, 'faultTime>=' . strtotime($config->update_time)])->andWhere($condition)->select(array_merge(SmsTemplate::$template_fields, ["serial_num" => "serial_num"]))->asArray()->all();
         $template = $this->getTemplate($config->smsTemplate_id);
         foreach ($alarms as $alarm) {
             $model = new SmsList();
             $model->receivers = $phones;
             $model->content = strtr($template, $alarm);
             if (!$model->save()) {
                 Yii::error(print_r($model->getErrors(), true), 'sms/find');
             }
             if ($alarm["serial_num"] > $LastId) {
                 $LastId = $alarm["serial_num"];
             }
         }
         Yii::$app->cache->set("config_last_id_" . $config->id, $LastId);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SmsConfig::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'smsTemplate_id' => $this->smsTemplate_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'alarmSet', $this->alarmSet])->andFilterWhere(['like', 'alarmCondition', $this->alarmCondition])->andFilterWhere(['like', 'receivers', $this->receivers]);
     return $dataProvider;
 }
 /**
  * Finds the SmsConfig model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SmsConfig the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SmsConfig::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }