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!')); } }
/** * Creates a new Reply model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Reply(); $data = Yii::$app->request->post(); if ($data != false) { $userinfo = User::findOne(['phone' => $data['Reply']['fromid']]); if ($data['Reply']['toid'] == '直接回复消息') { $model->toid = 0; } else { $appinfo = User::findOne(['name' => $data['Reply']['toid']]); $model->toid = $appinfo['id']; } $model->msgid = $data['Reply']['msgid']; $model->fromid = $userinfo['id']; $model->created_at = (string) time(); $model->isread = $data['Reply']['isread']; $model->content = $data['Reply']['content']; if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }