Example #1
0
 public function unfollow()
 {
     $chk = BoothFollow::where('b_id', '=', $this->b_id)->where('u_id', '=', $this->u_id)->first();
     if (!empty($chk)) {
         $chk->delete();
     } else {
         throw new Exception("已取消关注", 7004);
     }
     $booth = Booth::find($this->b_id);
     $booth->b_fans_count -= 1;
     if ($booth->b_fans_count <= 0) {
         $booth->b_fans_count = 0;
     }
     $booth->save();
     return true;
 }
Example #2
0
 public function listFollowingBooth()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     $type = Input::get('type', 0);
     $per_page = Input::get('per_page');
     try {
         $user = User::chkUserByToken($token, $u_id);
         $query = BoothFollow::select('booth_follows.*')->with(['booth'])->where('booth_follows.u_id', '=', $u_id)->leftJoin('booths', function ($q) use($type) {
             $q->on('booths.b_id', '=', 'booth_follows.b_id');
         });
         if ($type) {
             $query->where('booths.b_type', '=', $type);
         }
         $list = $query->paginate($per_page);
         $data = [];
         foreach ($list as $key => $follow) {
             $data[] = $follow->showInList();
         }
         $re = Tools::reTrue('获取我收藏的店铺成功', $data, $list);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取我收藏的店铺失败:' . $e->getMessage());
     }
     return Response::json($re);
 }
 public function listBoothFollow($id)
 {
     $u_id = Input::get('u_id', 0);
     $school = Input::get('school', 0);
     $profession = Input::get('prof', 0);
     $entry_year = Input::get('entry_year', 0);
     $gender = Input::get('gender', 0);
     $key = Input::get('key', '');
     $per_page = Input::get('per_page', 30);
     try {
         $user = User::find($u_id);
         $user_contact = UserProfileBase::find($u_id);
         $query = BoothFollow::with(['follower', 'follower.school'])->where('b_id', '=', $id)->select('booth_follows.*')->leftJoin('users', function ($q) {
             $q->on('users.u_id', '=', 'booth_follows.u_id');
         })->leftJoin('users_contact_peoples', function ($q) {
             $q->on('users_contact_peoples.u_id', '=', 'booth_follows.u_id');
         })->leftJoin('dic_schools', function ($q) {
             $q->on('users.u_school_id', '=', 'dic_schools.t_id');
         });
         if ($school) {
             $query = $query->where('users.u_school_id', '=', $user->u_school_id);
         }
         if (!empty($user_contact)) {
             if ($profession) {
                 $query = $query->where('users_contact_peoples.u_prof', '=', $user_contact->u_prof);
             }
             if ($entry_year) {
                 $query = $query->where('users_contact_peoples.u_entry_year', '=', $user_contact->u_entry_year);
             }
         }
         if ($gender) {
             $query = $query->where('users.u_sex', '=', $gender);
         }
         if ($key) {
             $query = $query->where('users.u_name', 'LIKE', '%' . $key . '%')->orWhere('users.u_nickname', 'LIKE', '%' . $key . '%')->orWhere('dic_schools.t_name', 'LIKE', '%' . $key . '%');
         }
         $list = $query->groupBy('users.u_id')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $follow) {
             $data[] = $follow->follower->showInList();
         }
         $re = Tools::reTrue('获取粉丝成功', $data, $list);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取粉丝失败:' . $e->getMessage());
     }
     return Response::json($re);
 }