예제 #1
1
 public function favorite()
 {
     if (Auth::check()) {
         return view('profile.favorite', ['categories' => Category::getAll(), 'ads' => Favorite::getById(Auth::user()->id)]);
     } else {
         return redirect('/');
     }
 }
예제 #2
1
파일: Favorite.php 프로젝트: elberd/maoh
 public static function getById($id)
 {
     $favorites = Favorite::where('user_id', $id)->get();
     $ad_ids_array = [];
     foreach ($favorites as $favorite) {
         $ad_ids_array[] = $favorite->ad_id;
     }
     $ads = Ad::whereIn('id', $ad_ids_array)->paginate(20);
     return $ads;
 }
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(Auth::user(), $topic)) {
         Auth::user()->favoriteTopics()->detach($topic->id);
     } else {
         Auth::user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', Auth::user(), $topic->user, $topic);
     }
     flash()->success('hello!', lang('Operation succeeded.'));
     return Redirect::route('topics.show', $topic->id);
 }
 public function create($id)
 {
     $favo_product = \DB::table('favorite')->where('product_id', '=', $id)->where('user_id', '=', Auth::user()->id)->first();
     if (is_null($favo_product)) {
         $created_at = Carbon::now('Asia/Kuala_lumpur');
         $updated_at = Carbon::now('Asia/Kuala_lumpur');
         $favorite = new Favorite();
         $favorite->user_id = Auth::user()->id;
         $favorite->product_id = $id;
         $favorite->created_at = $created_at;
         $favorite->updated_at = $updated_at;
         $favorite->save();
         Session::flash('alert-success', 'Product successfully add to your favorite list');
         return Redirect::home();
     } else {
         return 'exist';
     }
 }
예제 #5
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(auth()->user(), $topic)) {
         auth()->user()->favoriteTopics()->detach($topic->id);
     } else {
         auth()->user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', auth()->user(), $topic->user, $topic);
     }
     Flash::success(lang('Operation succeeded.'));
     return redirect()->route('topics.show', $topic->id);
 }
예제 #6
0
 public function favorites(Request $request, $id, $type)
 {
     if ($request->input('sort') == 'rating') {
         $sort = 'rating';
     } else {
         $sort = 'updated_at';
     }
     $favorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title', 'sc');
     }])->select('drama_id', 'type', 'rating', 'tags', 'updated_at')->where('user_id', $id)->where('type', $type)->orderBy($sort, 'desc')->simplePaginate(20);
     return $favorites;
 }
예제 #7
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create($pid)
 {
     $this->msg = "添加失败";
     //如果购物车不存在该物品,则添加到购物车
     if (!$this->favoriteService->exsitObjByUPid($this->user->id, $pid)) {
         $now = time();
         $fid = $pid . $now . rand(10000, 99999);
         $favorite = new Favorite();
         $favorite->pid = $pid;
         $favorite->uid = $this->user->id;
         $favorite->fid = $fid;
         $favorite->ftime = $now;
         $favorite->save();
         $this->msg = "添加成功";
     }
     if (view()->exists('favorite.list')) {
         //            return redirect('/favorite/list')->with('msg',$this->msg);
         return redirect()->back()->with('msg', $this->msg);
     } else {
         return redirect('home');
     }
 }
예제 #8
0
 public static function getFavoriteList(ProductService $productService)
 {
     $favorites = array();
     $list = $productService->getProducts();
     foreach ($list as $product) {
         $favorite = Favorite::find($product->pid);
         if (isset($favorite)) {
             $favorites[$product->fid]['favorite'] = $favorite;
         }
     }
     //        dd($favorites);
     return $favorites;
 }
예제 #9
0
 public function index(Request $request)
 {
     //判断url中是否有性向参数,若没有就默认性向为耽美type=0
     if ($request->has('type')) {
         $type = $request->input('type');
     } else {
         $type = 0;
     }
     //若type为-1,则查询全部新剧,否则按性向即type值查询
     if ($type < 0) {
         $episodes = Episode::join('dramas', function ($join) {
             $join->on('episodes.drama_id', '=', 'dramas.id')->where('episodes.release_date', '>=', date("Y-m-d", strtotime("-7 day")));
         })->select('dramas.title as drama_title', 'dramas.type as type', 'dramas.original as original', 'episodes.id as episode_id', 'episodes.title as episode_title', 'episodes.reviews as reviews', 'episodes.release_date as release_date', 'dramas.sc as sc', 'episodes.alias as alias', 'episodes.poster_url as poster_url', 'dramas.era as era', 'dramas.genre as genre', 'dramas.state as state', 'episodes.duration as duration')->orderBy('episode_id', 'desc')->get();
     } else {
         $episodes = Episode::join('dramas', function ($join) use($type) {
             $join->on('episodes.drama_id', '=', 'dramas.id')->where('dramas.type', '=', $type)->where('episodes.release_date', '>=', date("Y-m-d", strtotime("-7 day")));
         })->select('dramas.title as drama_title', 'dramas.type as type', 'dramas.original as original', 'episodes.id as episode_id', 'episodes.title as episode_title', 'episodes.reviews as reviews', 'episodes.release_date as release_date', 'dramas.sc as sc', 'episodes.alias as alias', 'episodes.poster_url as poster_url', 'dramas.era as era', 'dramas.genre as genre', 'dramas.state as state', 'episodes.duration as duration')->orderBy('episode_id', 'desc')->get();
     }
     $top10 = $episodes->take(10);
     //将一周新剧按发剧日期分组
     $episodes = $episodes->groupBy('release_date');
     //查询60天收藏数前10的剧单
     $lists = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select(DB::raw('count(*) as favorite_count, list_id'))->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-60 day")))->groupBy('list_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //最新剧单
     $newlists = Dramalist::select('id', 'title')->orderBy('id', 'desc')->take(10)->get();
     //查询30天评论数前10的剧集id
     $hotDramas = Review::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, drama_id'))->groupBy('drama_id')->orderBy('review_count', 'desc')->take(10)->get();
     //查询30天收藏前10的剧集id
     $hotFavorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, drama_id'))->groupBy('drama_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //查询最新10条新剧的添加历史
     $versions = Dramaver::select('user_id', 'drama_id', 'created_at')->where('first', 1)->orderBy('drama_id', 'desc')->take(10)->get();
     $versions->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $versions->load(['drama' => function ($query) {
         $query->select('id', 'title', 'sc');
     }]);
     $versions = $versions->filter(function ($version) {
         return isset($version->drama->id);
     });
     return view('index', ['type' => $type, 'episodes' => $episodes, 'top10' => $top10, 'lists' => $lists, 'newlists' => $newlists, 'hotDramas' => $hotDramas, 'hotFavorites' => $hotFavorites, 'versions' => $versions]);
 }
 public function updateFavoriteList(Request $request)
 {
     $data = $request->all();
     $questionResult = $data['question_id'];
     $result = explode(',', $questionResult);
     for ($i = 0; $i < count($result); $i++) {
         Favorite::where('user_id', $data['user_id'])->where('question_id', $result[$i])->delete();
     }
     $Favoritelist = Favorite::where('user_id', $data['user_id'])->get();
     for ($i = 0; $i < count($Favoritelist); $i++) {
         $Favoritelist[$i]['question'] = Question::where('id', $Favoritelist[$i]['question_id'])->first();
         $Favoritelist[$i]['question']['favorite'] = 1;
         $Favoritelist[$i]['question']['practice'] = 0;
         $Favoritelist[$i]['question']['delete'] = 0;
     }
     return response()->json(['RetCode' => '1', 'Content' => $Favoritelist]);
 }
예제 #11
0
 public function lists()
 {
     //最新剧单
     $newLists = Dramalist::select('id', 'title')->orderBy('id', 'desc')->take(10)->get();
     //查询60天收藏数前10的剧单
     $hotLists = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select(DB::raw('count(*) as favorite_count, list_id'))->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-60 day")))->groupBy('list_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //查询30天评论数前10的剧集id
     $hotDramas = Review::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, drama_id'))->groupBy('drama_id')->orderBy('review_count', 'desc')->take(10)->get();
     //查询30天收藏前10的剧集id
     $hotFavorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, drama_id'))->groupBy('drama_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     return ['newLists' => $newLists, 'hotLists' => $hotLists, 'hotDramas' => $hotDramas, 'hotFavorites' => $hotFavorites];
 }
 public function checkFavorite()
 {
     $userId = $this->request->input('userid');
     $friendId = $this->request->input('friendid');
     $UData = User::where('id', $friendId)->first();
     if ($UData) {
         $Favorite = Favorite::where('favorite_person', $friendId)->where('favorite_by', $userId)->first();
         if ($Favorite) {
             $Response = array('success' => '1');
         } else {
             $Response = array('success' => '0');
         }
         return json_encode($Response);
     } else {
         echo 'not found';
     }
 }
예제 #13
0
 public function exportFavorites()
 {
     $favorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title', 'sc');
     }])->select('drama_id', 'type', 'rating', 'updated_at')->where('user_id', Auth::id())->get();
     $str = "剧集,主役,收藏类型,评分,更新时间\n";
     foreach ($favorites as $favorite) {
         switch ($favorite->type) {
             case 0:
                 $type = '想听';
                 break;
             case 1:
                 $type = '在追';
                 break;
             case 2:
                 $type = '听过';
                 break;
             case 3:
                 $type = '搁置';
                 break;
             default:
                 $type = '抛弃';
         }
         $str .= "\"" . str_replace("\"", "\"\"", $favorite->drama->title) . "\",\"" . str_replace("\"", "\"\"", $favorite->drama->sc) . "\"," . $type . ",\"" . ($favorite->rating != 0 ? $favorite->rating : '') . "\"," . $favorite->updated_at . "\n";
     }
     $headers = array('Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="favorites.csv"');
     return response($str, 200, $headers);
 }
예제 #14
0
 public function destroy(Request $request, $id)
 {
     $favorite = Favorite::find($id);
     if ($favorite->user_id == $request->user()->id) {
         if ($favorite->delete()) {
             DB::table('users')->where('id', $favorite->user_id)->decrement('favorite' . $favorite->type);
             DB::table('dramas')->where('id', $favorite->drama_id)->decrement('favorites');
             DB::table('tagmaps')->where('drama_id', $favorite->drama_id)->where('user_id', $favorite->user_id)->delete();
         }
     }
     return redirect()->back();
 }
예제 #15
0
 public function destroy(Request $request, $id)
 {
     $favorite = Favorite::find($id);
     if ($favorite->user_id == $request->user()->id) {
         if ($favorite->delete()) {
             DB::table('users')->where('id', $favorite->user_id)->decrement('favorite' . $favorite->type);
             DB::table('dramas')->where('id', $favorite->drama_id)->decrement('favorites');
             DB::table('tagmaps')->where('drama_id', $favorite->drama_id)->where('user_id', $favorite->user_id)->delete();
         }
         return ['result' => 'success'];
     }
     return response('删除失败', 422);
 }
예제 #16
0
 public function favorites($id)
 {
     $drama = Drama::find($id, ['id', 'title']);
     $favorites = Favorite::with(['user' => function ($query) {
         $query->select('id', 'name');
     }])->select('user_id', 'type', 'updated_at')->where('drama_id', $id)->orderBy('updated_at')->paginate(20);
     return view('drama.favorites')->withDrama($drama)->withFavorites($favorites);
 }
예제 #17
0
 public static function isUserFavoritedTopic(User $user, Topic $topic)
 {
     return Favorite::where('user_id', $user->id)->where('topic_id', $topic->id)->first();
 }
 public function uploadResult(Request $request)
 {
     $data = $request->all();
     $questionResult = $data['question'];
     $result = explode(',', $questionResult);
     for ($i = 0; $i < count($result); $i++) {
         $saveResult = explode('-', $result[$i]);
         Result::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0], 'answer' => $saveResult[1], 'second' => $saveResult[2]]);
         if ($saveResult[3] == '1') {
             $FavoriteRecord = Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->first();
             if ($FavoriteRecord == null || $FavoriteRecord == 'null') {
                 Favorite::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0]]);
             }
         } else {
             if ($saveResult[3] == '0') {
                 Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->delete();
             }
         }
     }
     $UserRecord = UserRecord::where('user_id', $data['user_id'])->get();
     $StageRecord = $UserRecord->where('stages_id', $data['stages_id'])->first();
     $CrementRecord = UserRecord::where('user_id', $data['user_id'])->where('stages_id', $data['stages_id'])->max('stage_score');
     $Crement = $data['score'] - $CrementRecord;
     $User = User::where('id', $data['user_id'])->first();
     if (count($UserRecord) == 0 || $StageRecord == 'null' || $StageRecord == null) {
         $User->increment('score', $data['score']);
     } else {
         if ($Crement > 0) {
             $User->increment('score', $Crement);
         }
     }
     $UserSrcoreRecord = Score::where('user_id', $data['user_id'])->where('category_id', floor($data['stages_id'] / 100));
     if (count($UserSrcoreRecord->get()) == 0) {
         Score::create(['user_id' => $data['user_id'], 'user_name' => $User['name'], 'category_id' => floor($data['stages_id'] / 100), 'score' => $data['score']]);
     } else {
         if ($Crement > 0) {
             $UserSrcoreRecord->first()->increment('score', $Crement);
         }
     }
     UserRecord::create(['user_id' => $data['user_id'], 'stages_id' => $data['stages_id'], 'accuracy' => $data['accuracy'], 'accuracy_detail' => $data['accuracy_detail'], 'status' => $data['status'], 'status_detail' => $data['status_detail'], 'stage_score' => $data['score']]);
     return response()->json(['RetCode' => '1']);
 }
예제 #19
0
 private function getFavorite($request, $param1, $param2)
 {
     $favorite = Favorite::whereUserId($request->user()->id)->whereType($param1)->whereContentIdentifier($param2)->first();
     if ($favorite) {
         return ['response' => 'completed', "result" => true];
     }
     return ['response' => 'completed', "result" => false];
 }
예제 #20
0
 /**
  * 单个用户的购物车分页函数
  * @param $page 页数
  * @param $perPage 每页条数
  * */
 public function getPagesByUser($page, $perPage = 10)
 {
     //翻页的开始-结束
     $from = $page * $perPage - $perPage;
     $to = $perPage;
     //按更新时间倒序输出
     $totalData = DB::table("favorites")->where('uid', $this->user->id)->orderBy("updated_at", "desc")->get();
     $data['favorites'] = DB::table("favorites")->where('uid', $this->user->id)->orderBy("updated_at", "desc")->skip($from)->take($to)->get();
     //相当于limit $from,$to
     $data['products'] = Favorite::getProductList($this);
     //获取购物车相关联的商品表数据
     $data['page']['total'] = count($totalData);
     //计算数据总条数
     $availible = ceil(count($totalData) / $perPage);
     //计算数据可分的总页数
     $last = $page;
     //当前页页码大于1的时候,才能-1
     if ($page > 1) {
         $last = $page - 1;
     }
     //计算上一页的页码
     $data['page']['last'] = $last;
     $next = $page + 1;
     //计算下一页的页码
     if ($next <= $availible) {
         $data['page']['next'] = $page + 1;
     }
     //如果下一页的页码小于或等于可分的总页数,下一页的页码+1
     //把数据存入翻页类中
     $data['paginator'] = new Paginator($data['favorites'], count($totalData), $page);
     //        dd($data);
     return $data;
 }
예제 #21
0
 public function show(Request $request, $id)
 {
     $drama = Drama::find($id, ['id', 'title', 'alias', 'type', 'era', 'genre', 'original', 'count', 'state', 'sc', 'introduction', 'reviews']);
     $drama->load(['episodes' => function ($query) {
         $query->select('id', 'drama_id', 'title', 'alias', 'release_date', 'poster_url')->orderByRaw('release_date, id')->get();
     }]);
     $drama->commtags = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('drama_id', $id)->groupBy('tag_id')->orderBy('count', 'desc')->take(5)->get();
     if (Auth::check()) {
         $user_id = $request->user()->id;
         $drama->userFavorite = Favorite::select('id', 'type', 'rating', 'tags')->where('user_id', $user_id)->where('drama_id', $id)->first();
         $drama->userTags = Tagmap::with('tag')->select(DB::raw('count(*) as count, tag_id'))->where('user_id', $user_id)->groupBy('tag_id')->orderBy('count', 'desc')->take(10)->get();
     }
     return $drama;
 }
예제 #22
0
 public static function boot()
 {
     parent::boot();
     Favorite::observe(new CounterObserver());
 }
예제 #23
0
 public function removefavorite($id)
 {
     if (Auth::check()) {
         Favorite::where('ad_id', $id)->where('user_id', Auth::user()->id)->delete();
     } else {
         return redirect()->back();
     }
 }
예제 #24
0
파일: Ad.php 프로젝트: elberd/maoh
 /**
  * Check is the ad authenticated user's favorite.
  *
  * @return boolean
  */
 public function isTheUsersFavorite()
 {
     if ($user = Auth::user()) {
         // todo: change to relation
         $count = Favorite::where('ad_id', $this->id)->where('user_id', $user->id)->count();
         if ($count > 0) {
             return true;
         }
     }
     return false;
 }