/**
  * Creates a new Push model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Push();
     $allkind2 = (new \yii\db\Query())->select('second distinct')->from('tag')->all();
     //var_dump($allkind2);
     $data = Yii::$app->request->post();
     if ($data != false) {
         $model->load($data);
         unset($model->label);
         $model->created_at = time();
         if ($data['Push']['label'][0] != "全部用户") {
             $like = "";
             $users = (new \yii\db\Query())->from('user')->join("INNER JOIN", "channel", "user.id=channel.userid");
             foreach ($data['Push']['label'] as $label) {
                 $like .= $label . " ";
                 $users = $users->orWhere(['like', 'user.hobby', $label]);
             }
             $query = $users->all();
             $model->label = $like;
             if ($model->save()) {
                 foreach ($query as $first) {
                     $this->push($first['channel'], $model->title, $model->message);
                 }
                 return $this->redirect(['index']);
             } else {
                 echo "<script language='javascript'>;alert('推送失败,请重新推送');</script>";
                 return $this->render('create', ['model' => $model, 'allkind2' => $allkind2]);
             }
         } else {
             $model->label = "全部用户";
             if ($model->save()) {
                 $this->pushtoall($model->title, $model->message);
                 return $this->redirect(['index']);
             } else {
                 echo "<script language='javascript'>;alert('推送失败,请重新推送');</script>";
                 return $this->render('create', ['model' => $model, 'allkind2' => $allkind2]);
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'allkind2' => $allkind2]);
     }
 }