Пример #1
0
 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!'));
     }
 }
Пример #2
0
 public function actionNotify()
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     if (!$phone) {
         echo json_encode(array('flag' => 0, 'msg' => 'Phone does not exist!'));
         return;
     }
     $ans = (new \yii\db\Query())->select('nickname,phone,thumb,message')->from('notify n')->join('INNER JOIN', 'user u', 'u.id=n.from and n.to=:id', [':id' => $phone['id']])->all();
     $dels = Notify::findAll(['to' => $phone['id']]);
     foreach ($dels as $del) {
         $del->delete();
     }
     return $ans;
 }