예제 #1
0
 /**
  * 
  * @param int $data
  * @return \yii\data\ActiveDataProvider
  */
 public static function findFriends($data = array())
 {
     if (!isset($data['limit'])) {
         $data['limit'] = 10;
     }
     $model = new Friend();
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('user_id=:user_id', [':user_id' => $data['user_id']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * 添加好友
  * @return boolean
  */
 public function addFriend()
 {
     $friendUser = User::find()->where("username=:username AND type_id=2", [':username' => $this->username])->one();
     $userCount = Friend::find()->where("user_id=:user_id AND friend_id=:friend_id", [':user_id' => $this->user_id, ':friend_id' => $friendUser->user_id])->count();
     if ($userCount > 0) {
         return TRUE;
     }
     $newFreind = new Friend();
     $newFreind->user_id = $this->user_id;
     $newFreind->friend_id = $friendUser->user_id;
     $newFreind->addtime = time();
     $newFreind->addip = \Yii::$app->request->userIp;
     if ($newFreind->save()) {
         return true;
     } else {
         $this->addError("username", '添加失败,请重试');
         return FALSE;
     }
 }
예제 #3
0
 /**
  * 获得活动分类
  * @return type
  */
 public function showUsername()
 {
     $fitArray = [];
     $result = Friend::find()->where('user_id=:user_id', [':user_id' => $this->user_id])->indexBy('id')->all();
     if ($result) {
         foreach ($result as $key => $value) {
             $fitArray[$value->friend_id] = $value->user->username;
         }
     }
     $fitArray[0] = '所有用户';
     return $fitArray;
 }
예제 #4
0
 public function actionFriend()
 {
     $mFriend = new Friend();
     $result = $mFriend->mytest();
     //        var_dump($result);
 }