/** * Creates a new Replys model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Replys(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
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 Replys(); 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->messageid = $data['messageid']; $model->content = $data['content']; $model->isread = 0; $model->created_at = time(); //var_dump($model); if ($model->save()) { return array('flag' => 1, 'msg' => 'Reply success!'); } else { return array('flag' => 0, 'msg' => 'Reply failed!'); } }