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!'));
 }
 public function actionCreateofmsg($msgid)
 {
     $model = new Msgtoapp();
     $data = Yii::$app->request->post();
     //$msgid= $data['msgid'];
     //return var_dump($msgid);
     if ($data != false) {
         $appinfo = app::findOne(['name' => $data['Msgtoapp']['appid']]);
         $model->appid = (string) $appinfo['id'];
         $model->msgid = $msgid;
         if ($model->save()) {
             return $this->redirect(['indexofmsg?MsgtoappSearch%5Bmsgid%5D=' . $msgid]);
         } else {
             return $this->render('create_msg', ['model' => $model, 'msgid' => $msgid]);
         }
     } else {
         return $this->render('create_msg', ['model' => $model, 'msgid' => $msgid]);
     }
 }