/**
  * Creates a new Message model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Message();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $data['Message']['userid']]);
         $model->userid = $userinfo['id'];
         $model->content = $data['Message']['content'];
         $model->kind = $data['Message']['kind'];
         $model->area = $data['Message']['area'];
         $model->created_at = (string) time();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionSend()
 {
     $data = Yii::$app->request->post();
     $msg = new Message();
     $phone = User::findOne(['phone' => $data['phone']]);
     // $msg->userid = Yii::$app->user->id;
     $msg->userid = $phone['id'];
     $msg->content = $data['content'];
     $msg->kind = $data['kind'];
     $msg->area = $data['area'];
     $msg->created_at = time();
     $err = $msg->save();
     if ($err == false) {
         echo json_encode(array('flag' => 0, 'msg' => 'Send fail!'));
         // throw new \yii\web\HttpException(404,"msg recode insert error");
     }
     foreach ($data['apps'] as $app) {
         // echo $app;
         $msgtoapp = new Msgtoapp();
         $msgtoapp->msgid = $msg->id;
         $msgtoapp->appid = $app['id'];
         $err = $msgtoapp->save();
         if ($err == false) {
             echo json_encode(array('flag' => 1, 'msg' => 'Send fail!'));
             // throw new \yii\web\HttpException(404,"msgtoapp recode insert error");
         }
     }
     echo json_encode(array('flag' => 1, 'msg' => 'Send success!'));
 }