Ejemplo n.º 1
0
 public function actionSet()
 {
     $data = Yii::$app->request->post();
     $model = new Friend();
     $user = new User();
     $myphone = $user->find()->select('id')->where(['phone' => $data['myphone']])->one();
     $Fphone = $user->find()->select('id')->where(['phone' => $data['fphone'], 'famous' => 1])->one();
     if (!$Fphone) {
         echo json_encode(array('flag' => 0, 'msg' => 'Failed!He/She is not famous.'));
         return;
     }
     if ($model->find()->where(['myid' => $myphone['id'], 'friendid' => $Fphone['id']])->one()) {
         echo json_encode(array('flag' => 0, 'msg' => 'Failed!You have already followed or you are friend.'));
     } else {
         $model->myid = $myphone['id'];
         $model->friendid = $Fphone['id'];
         $model->isfriend = 0;
         $model->save();
         echo json_encode(array('flag' => 1, 'msg' => 'Follow success!'));
     }
 }
Ejemplo n.º 2
0
 public function actionCreatefriend($myselfid)
 {
     $model = new Friend();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $myselfid]);
         $appinfo = User::findOne(['phone' => $data['Friend']['friendid']]);
         $model->myid = (string) $userinfo['id'];
         $model->friendid = $appinfo['id'];
         $model->isfriend = 1;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
 public function actionAcceptadd()
 {
     $data = Yii::$app->request->post();
     $model = new User();
     $myid = $model->find()->select('id')->where(['phone' => $data['myphone']])->one();
     $fid = $model->find()->select('id')->where(['phone' => $data['fphone']])->one();
     $friend = Friend::findOne(['myid' => $myid['id'], 'friendid' => $fid['id']]);
     if ($friend === null) {
         if ($data['agree'] == 1) {
             $model1 = new Friend();
             $model1->myid = $myid['id'];
             $model1->friendid = $fid['id'];
             $model1->isfriend = 1;
             $model1->save();
             $model2 = new Friend();
             $model2->myid = $fid['id'];
             $model2->friendid = $myid['id'];
             $model2->isfriend = 1;
             $model2->save();
             echo json_encode(array('flag' => 1, 'msg' => 'Add friend successfully'));
         } else {
             echo json_encode(array('flag' => 0, 'msg' => 'Refuse to add friend successfully'));
         }
         $row = Reqfriend::findOne(['myid' => $fid['id'], 'friendid' => $myid['id']]);
         if ($row != null) {
             $row->delete();
         }
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'You are already friend.'));
     }
 }