コード例 #1
0
 public function actionDeletereply()
 {
     $data = Yii::$app->request->post();
     $id = $data['id'];
     $model = Reply::find()->where(['id' => $id])->one();
     if ($model == null) {
         //throw new \yii\web\NotFoundHttpException("record not found",401);
         throw new \yii\web\HttpException(404, "recode not found");
         //return "no record";
     }
     $err = $model->delete();
     if ($err == false) {
         //throw new \yii\web\HttpException(404,"recode delete error");
     } else {
         echo json_encode(array('flag' => 1, 'msg' => 'Delete success!'));
     }
     //$model=new Reply();
     //$model->fromid=$data['fromid'];
     //$model->toid=$data['toid'];
     //$model->msgid=$data['msgid'];
     //$model->content=$data['content'];
     //$model->isread=false;
     //$model->created_at=time();
     //$model->save();
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Reply::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if ($params != false && !empty($params['ReplySearch'])) {
         foreach ($params['ReplySearch'] as $name => $value1) {
             if ($name === 'fromid' && $value1 != null) {
                 $appinfo = User::findOne(['fromid' => $params['ReplySearch']['fromid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
             if ($name === 'toid' && $value1 != null) {
                 if ($params['ReplySearch']['toid'] == '直接回复消息') {
                     $this->userinc = 0;
                 } else {
                     $appinfo = User::findOne(['phone' => $params['ReplySearch']['toid']]);
                     $this->userinc = $appinfo['id'];
                     if ($appinfo == null) {
                         $this->userinc = 10000000001.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, 'fromid' => $this->value, 'toid' => $this->userinc, 'isread' => $this->isread, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }