public function actionSetMsg() { $data = Yii::$app->request->post(); $phone = User::findOne(['phone' => $data['phone']]); $info = CollectInteract::findOne(['userid' => $phone['id'], 'msg' => $data['msg']]); if ($info) { echo json_encode(array('flag' => 0, 'msg' => 'Already collect!')); return; } $to = Message::findOne(['id' => $data['msg']]); $model2 = new Notify(); $model2->from = $phone['id']; $model2->to = $to['userid']; $model2->message = '收藏'; $model2->created_at = time(); if (!$model2->save()) { echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!')); return; } $model = new CollectInteract(); $model->userid = $phone['id']; $model->msg = $data['msg']; $model->created_at = time(); if ($model->save()) { echo json_encode(array('flag' => 1, 'msg' => 'Collect success!')); } else { echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!')); } }
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 Message model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Message the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Message::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }