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.'));
     }
 }
Esempio n. 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReqfriends0()
 {
     return $this->hasMany(Reqfriend::className(), ['myid' => 'id']);
 }