Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Msgtoapp::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if ($params != false && !empty($params['MsgtoappSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['MsgtoappSearch'] as $name => $value1) {
             if ($name === 'appid' && $value1 != null) {
                 $appinfo = app::findOne(['name' => $params['MsgtoappSearch']['appid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
         }
     }
     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, 'msgid' => $this->msgid, 'appid' => $this->value]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 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!'));
 }
 /**
  * Finds the Msgtoapp model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Msgtoapp the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Msgtoapp::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMsgtoapps()
 {
     return $this->hasMany(Msgtoapp::className(), ['msgid' => 'id']);
 }