Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Message::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if ($params != false && !empty($params['MessageSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['MessageSearch'] as $name => $value1) {
             if ($name === 'userid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['MessageSearch']['userid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->userinc = 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, 'userid' => $this->value, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'kind', $this->kind])->andFilterWhere(['like', 'area', $this->area]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function actionDeletemsg()
 {
     $data = Yii::$app->request->post();
     $id = $data['id'];
     $msg = new Message();
     $msg = Message::find()->where(['id' => $id])->one();
     if ($msg == null) {
         // throw new \yii\web\NotFoundHttpException("record not found",401);
         //throw new \yii\web\HttpException ( 404, "recode not found" );
         // return "no record";
         echo json_encode(array('flag' => 0, 'msg' => 'Message do not exist!'));
         return;
     }
     // $msg->id = $id;
     $err = $msg->delete();
     if ($err == false) {
         //throw new \yii\web\HttpException ( 404, "recode delete error" );
         echo json_encode(array('flag' => 0, 'msg' => 'Delete failed!'));
     } else {
         echo json_encode(array('flag' => 1, 'msg' => 'Delete success!'));
     }
 }
Exemplo n.º 3
0
 public function actionGetmsg()
 {
     $data = Yii::$app->request->post();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $phone = User::findOne(['phone' => $data['phone']]);
     //$data = Message::find ()->select ( 'msg.id' )->join ( 'INNER JOIN', 'friends', ' msg.userid =friends.friendid and msg.userid = :id ', [':id' => Yii::$app->user->id ]);
     $m = new Message();
     $data = $m->find()->where(['userid' => $phone['id']]);
     $pages = new \yii\data\Pagination(['totalCount' => $data->count(), 'pageSize' => '10']);
     $models = $data->orderBy("msg.created_at desc")->offset($pages->offset)->limit($pages->limit)->all();
     $result = array();
     $result['item'] = array();
     foreach ($models as $model) {
         $info = array();
         $infi['basic'] = array();
         $info['basic'] = $model;
         $info['apps'] = (new \yii\db\Query())->select(['app.*'])->from('msgtoapp')->join('INNER JOIN', 'app', 'msgtoapp.appid = app.id and msgtoapp.msgid = :id', [':id' => $model['id']])->all();
         $info['replys'] = (new \yii\db\Query())->select(['reply.*', 'user1.nickname as fromnickname', 'user1.phone as fromphone', 'user2.nickname as tonickname', 'user2.phone as tophone'])->from('reply')->join('INNER JOIN', 'user user1', 'user1.id = reply.fromid and reply.msgid= :id', [':id' => $model['id']])->join('Left JOIN', 'user user2', 'user2.id = reply.toid')->orderBy("reply.created_at")->all();
         $info['zan'] = (new \yii\db\Query())->select('u.phone,u.nickname')->from('zan z')->join('INNER JOIN', 'user u', 'u.id=z.myid and z.msgid=:id', [':id' => $model['id']])->all();
         $result['item'][] = $info;
     }
     $result['_meta'] = array('pageCount' => $pages->pageCount, 'currentPage' => $pages->page + 1);
     return $result;
 }