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;
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReplies()
 {
     return $this->hasMany(Reply::className(), ['fromid' => 'id']);
 }
 public function actionReply()
 {
     $data = Yii::$app->request->post();
     $user = new User();
     $fromphone = $user->find()->select('id')->where(['phone' => $data['fphone']])->one();
     $model = new Reply();
     if ($data['tphone'] == '') {
         $model->toid = 0;
     } else {
         $tophone = $user->find()->select('id')->where(['phone' => $data['tphone']])->one();
         $model->toid = $tophone['id'];
     }
     $to = Message::findOne(['id' => $data['msgid']]);
     if ($fromphone['id'] != $to['id']) {
         $model3 = new Notify();
         $model3->from = $fromphone['id'];
         $model3->to = $to['userid'];
         $model3->message = '评论';
         $model3->created_at = time();
         if (!$model3->save()) {
             echo json_encode(array('flag' => 0, 'msg' => 'Reply failed!'));
             return;
         }
     }
     $model->fromid = $fromphone['id'];
     $model->msgid = $data['msgid'];
     $model->content = $data['content'];
     $model->isread = 0;
     $model->created_at = time();
     if ($model->save()) {
         echo json_encode(array('flag' => 1, 'msg' => 'Reply success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Reply failed!'));
     }
 }
 /**
  * Finds the Reply model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Reply the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Reply::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }