Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function getBooth($id)
 {
     $u_id = Input::get('u_id', 0);
     try {
         if (!$u_id) {
             throw new Exception("需要传入用户ID", 2001);
         }
         $booth = Booth::find($id);
         if (empty($booth->b_id)) {
             throw new Exception("无法获取到请求的店铺", 7001);
         }
         if ($booth->b_status != 1) {
             throw new Exception("店铺当前不可用", 7001);
         }
         $booth->load(['user', 'praises' => function ($q) {
             $q->where('praise.u_id', '=', $this->u_id);
         }, 'favorites' => function ($q) {
             $q->where('favorites.u_id', '=', $this->u_id);
         }]);
         $boothInfo = $booth->showDetail();
         $products_count = Product::where('b_id', '=', $booth->b_id)->where('p_status', '=', 1)->count();
         $chk = BoothFollow::where('b_id', '=', $booth->b_id)->where('u_id', '=', $u_id)->first();
         if (empty($chk)) {
             $is_follow = 0;
         } else {
             $is_follow = 1;
         }
         $boothInfo['prodct_count'] = (int) $products_count;
         $boothInfo['is_follow'] = $is_follow;
         $boothInfo['is_praised'] = 0;
         $boothInfo['is_favorited'] = 0;
         if (count($booth->praises) > 0) {
             $boothInfo['is_praised'] = 1;
         }
         if (count($booth->favorites) > 0) {
             $boothInfo['is_favorited'] = 1;
         }
         $data = ['booth' => $boothInfo];
         $re = Tools::reTrue('获取他的店铺成功', $data);
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '获取他的店铺失败:' . $e->getMessage());
     }
     return Response::json($re);
 }