예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tbreplys::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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, 'tbmessageid' => $this->tbmessageid, 'fromid' => $this->fromid, 'toid' => $this->toid, 'isread' => $this->isread, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTbreplys()
 {
     return $this->hasMany(Tbreplys::className(), ['tbmessageid' => 'id']);
 }
예제 #3
0
 /**
  * Finds the Tbreplys model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tbreplys the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tbreplys::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 public function actionReply()
 {
     $data = Yii::$app->request->post();
     //$user=new Users();
     $fromphone = Users::find()->select('id')->where(['phone' => $data['fphone']])->one();
     //var_dump($fromphone);
     $model = new Tbreplys();
     if ($data['tphone'] == '') {
         $model->toid = 0;
     } else {
         $tophone = Users::find()->select('id')->where(['phone' => $data['tphone']])->one();
         //var_dump($tophone);
         $model->toid = $tophone['id'];
     }
     // 		$to=Messages::findOne(['id'=>$data['msgid']]);
     // 		if($fromphone['id']!=$to['id']){
     // 			$model3=new Notify();
     // 			$model3->from=$fromphone['id'];
     // 			$model3->to=$to['userid'];
     // 			//$model3->kind='评论';
     // 			$model3->kind=$data['content'];
     // 			$model3->created_at=time();
     // 			$model3->msg_id=$data['msgid'];
     // 			if(!$model3->save()){
     // 				echo json_encode ( array (
     // 						'flag' => 0,
     // 						'msg' => 'Reply failed!'
     // 				));
     // 				return;
     // 			}
     // 		}
     $model->fromid = $fromphone['id'];
     $model->tbmessageid = $data['tbmessageid'];
     $model->content = $data['content'];
     $model->isread = 0;
     $model->created_at = time();
     //var_dump($model);
     $tbmessage = $this->findModel($data['tbmessageid']);
     $connection = Yii::$app->db;
     $transaction = $connection->beginTransaction();
     try {
         if (!$model->save()) {
             throw new Exception("dsfgsdfg");
         }
         $tbmessage->replycount++;
         if (!$tbmessage->save()) {
             throw new Exception("asdfgsdfg");
         }
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         //var_dump("133435465");
         //Yii::$app->log->logger->
         return array('flag' => 0, 'msg' => 'Reply fail!');
     }
     return array('flag' => 1, 'msg' => 'Reply success!');
 }