Ejemplo n.º 1
0
 public function actionCancel()
 {
     $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']])->one();
     $ans = Friend::findOne(['myid' => $myphone['id'], 'friendid' => $Fphone['id'], 'isfriend' => 0]);
     if ($ans) {
         $ans->delete();
         echo json_encode(array('flag' => 1, 'msg' => 'Cancel follow.'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Do not exist.'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     //$query = Friend::find()->join('INNER JOIN','user','friends.friendid=user.id');
     $this->load($params);
     if (isset($params['FollowSearch']['mynickname']) && !empty($params['FollowSearch']['mynickname'])) {
         $query = Friend::find()->join('INNER JOIN', 'user', 'friends.myid=user.id');
         $query->andFilterWhere(['like', 'user.nickname', $params['FollowSearch']['mynickname']]);
     } else {
         $query = Friend::find()->join('INNER JOIN', 'user', 'friends.friendid=user.id');
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->andFilterWhere(['friends.isfriend' => 0]);
     if ($params != false && !empty($params['FollowSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['FollowSearch'] as $name => $value1) {
             if ($name === 'myid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['FollowSearch']['myid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
             if ($name === 'friendid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['FollowSearch']['friendid']]);
                 $this->userinc = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->userinc = 0;
                 }
             }
         }
     }
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['myid' => $this->value, 'friendid' => $this->userinc]);
     if (isset($params['FollowSearch']) && isset($params['FollowSearch']['friendnickname'])) {
         $query->andFilterWhere(['like', 'user.nickname', $params['FollowSearch']['friendnickname']]);
     }
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * Finds the Friend model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Friend the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Friend::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 4
0
 public function actionDelete()
 {
     $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();
     $row1 = Friend::findOne(['myid' => $fid['id'], 'friendid' => $myid['id'], 'isfriend' => 1]);
     if ($row1 != null) {
         $row1->delete();
         $row2 = Friend::findOne(['myid' => $myid['id'], 'friendid' => $fid['id'], 'isfriend' => 1]);
         $row2->delete();
         echo json_encode(array('flag' => 1, 'msg' => 'Delete friend successfully'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'You are not friend.'));
     }
 }
Ejemplo n.º 5
0
 public function actionSearch()
 {
     $data = Yii::$app->request->post();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $model = new User();
     $myid = $model->find()->select('id')->from('user')->where(['phone' => $data['myphone']])->one();
     $fid = $model->find()->select('*')->from('user')->where(['phone' => $data['fphone']])->one();
     $model = new Friend();
     // 		$info=$model->find()->where([
     // 				'myid'=>$myid['id'],
     // 				'friendid'=>$fid['id']
     // 		]);
     $info = Friend::findOne(['myid' => $myid['id'], 'friendid' => $fid['id']]);
     $ans = array();
     if ($fid) {
         $ans['id'] = $fid['id'];
         $ans['phone'] = $fid['phone'];
         $ans['thumb'] = $fid['thumb'];
         $ans['nickname'] = $fid['nickname'];
         $ans['gender'] = $fid['gender'];
         $ans['area'] = $fid['area'];
         $ans['job'] = $fid['job'];
         $ans['hobby'] = $fid['hobby'];
         $ans['signature'] = $fid['signature'];
         if ($info) {
             $ans['isfriend'] = 1;
         } else {
             $ans['isfriend'] = 0;
         }
     } else {
         $ans['id'] = '';
         $ans['phone'] = '';
         $ans['thumb'] = '';
         $ans['nickname'] = '';
         $ans['gender'] = '';
         $ans['area'] = '';
         $ans['job'] = '';
         $ans['hobby'] = '';
         $ans['signature'] = '';
         $ans['isfriend'] = 0;
     }
     return $ans;
 }