예제 #1
0
 public function listFavoriteBooth()
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id');
     $per_page = Input::get('per_page', 0);
     try {
         $user = User::chkUserByToken($token, $u_id);
         $list = Booth::select('booths.*', 'favorites.created_at')->with(['user', 'school', 'city', 'praises' => function ($q) {
             $q->where('praises.u_id', '=', $this->u_id);
         }])->join('favoriables', function ($q) {
             $q->on('booths.b_id', '=', 'favoriables.favoriable_id')->where('favoriables.favoriable_type', '=', 'Booth');
         })->join('favorites', function ($q) {
             $q->on('favorites.id', '=', 'favoriables.favorite_id')->where('favorites.u_id', '=', $this->u_id);
         })->orderBy('favorites.created_at', 'DESC')->paginate($per_page);
         $data = [];
         foreach ($list as $key => $booth) {
             $tmp = $booth->showInList();
             $tmp['is_praised'] = 0;
             if (count($booth->praises) > 0) {
                 $tmp['is_praised'] = 1;
             }
             $data[] = $tmp;
         }
         $re = Tools::reTrue('获取店铺成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取店铺失败:' . $e->getMessage());
     }
     return Response::json($re);
 }