Ejemplo n.º 1
0
 public function getCommentsCountAttribute()
 {
     return UserComment::where('type', 1)->where('item_id', $this->id)->count();
 }
Ejemplo n.º 2
0
 /**
  *
  * @SWG\Api(
  *   path="/goods/{id}",
  *   description="商品",
  *   @SWG\Operation(
  *     method="GET", summary="获得商品详情", notes="获得商品详情",
  *     type="Goods",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="商品id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     ),
  *     @SWG\Parameter(
  *         name="user_id",
  *         description="用户id",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=-1
  *     )
  *
  *   )
  * )
  */
 public function show(Request $request, $id)
 {
     $user_id = $request->input('user_id', -1);
     $response = new BaseResponse();
     $theme = Goods::find($id);
     $theme['has_collection'] = 0;
     if ($user_id != -1) {
         $c = Collection::where('user_id', $user_id)->where('type', 0)->where('item_id', $theme['id'])->first();
         if ($c != null) {
             $theme['has_collection'] = 1;
         }
     }
     //var_dump($theme);exit;
     $comments = UserComment::select('user_comments.*', 'user_infos.nick_name', 'user_infos.head_icon')->leftJoin('user_infos', 'user_infos.id', '=', 'user_comments.user_id')->where('user_comments.type', 0)->where('user_comments.item_id', $theme['id']);
     $rows = $comments->skip(0)->take(10)->orderBy('id', 'desc')->get()->toArray();
     foreach ($rows as &$v) {
         //$v['']
         $sum = Order::select(DB::raw('SUM(total_fee) as total_pay'))->where('user_id', $v['user_id'])->where('status', 4)->first()->toArray();
         if ($sum == null || $sum['total_pay'] == null) {
             $sum = 0;
         } else {
             $sum = $sum['total_pay'];
         }
         $level = UserLevel::where('sum_lowest', '<=', $sum)->where('sum_highest', '>', $sum)->first()->toArray();
         //var_dump($level);exit;
         $v['level'] = $level['img'];
     }
     $theme['comments'] = $rows;
     $response->Data = $theme;
     return $response->toJson();
 }
Ejemplo n.º 3
0
 /**
  *
  * @SWG\Api(
  *   path="/comments/{id}",
  *   @SWG\Operation(
  *     method="DELETE", summary="删除评论", notes="删除评论",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="评论id",
  *         paramType="path",
  *         required=true,
  *         type="integer"
  *     )
  *   )
  * )
  */
 public function destroy($id)
 {
     $response = new BaseResponse();
     $comment = UserComment::find($id);
     if ($comment != null) {
         $comment->delete();
     }
     return $response->toJson();
 }
Ejemplo n.º 4
0
 /**
  *
  * @SWG\Api(
  *   path="/home/{id}",
  *   description="获取首页项详情",
  *   @SWG\Operation(
  *     method="GET", summary="获得主题详情", notes="获得主题详情",
  *     type="Home",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     ),@SWG\Parameter(
  *         name="device_token",
  *         description="设备号",
  *         paramType="query",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer"
  *     ),@SWG\Parameter(
  *         name="user_id",
  *         description="用户id",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=-1
  *     ),
  *
  *   )
  * )
  */
 public function show(Request $request, $id)
 {
     //
     $response = new BaseResponse();
     $user_id = $request->input('user_id', -1);
     $device_token = $request->input('device_token', '');
     $home = Home::find($id);
     if ($home == null) {
         $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
         $response->Message = '数据不存在';
         return $response->toJson();
     }
     if ($device_token != '') {
         $readRecords = new ReadRecords();
         $readRecords->device_token = $device_token;
         $readRecords->home_id = $id;
         $readRecords->save();
     }
     $home = $home->toArray();
     if ($home['type'] == 1) {
         $home['has_collection'] = 0;
         if ($user_id != -1) {
             $collection = Collection::where('user_id', $user_id)->where('type', 1)->where('item_id', $home['item_id'])->first();
             if ($collection != null) {
                 $home['has_collection'] = 1;
             }
         }
         $comments = UserComment::select('user_comments.*', 'user_infos.nick_name', 'user_infos.head_icon')->leftJoin('user_infos', 'user_infos.id', '=', 'user_comments.user_id')->where('user_comments.type', 1)->where('user_comments.item_id', $home['item']['id']);
         $rows = $comments->skip(0)->take(10)->orderBy('id', 'desc')->get()->toArray();
         foreach ($rows as &$v) {
             //$v['']
             $sum = Order::select(DB::raw('SUM(total_fee) as total_pay'))->where('user_id', $v['user_id'])->where('status', 4)->first()->toArray();
             if ($sum == null || $sum['total_pay'] == null) {
                 $sum = 0;
             } else {
                 $sum = $sum['total_pay'];
             }
             $level = UserLevel::where('sum_lowest', '<=', $sum)->where('sum_highest', '>', $sum)->first()->toArray();
             //var_dump($level);exit;
             $v['level'] = $level['name'];
         }
         $home['comments'] = $rows;
     }
     $response->Data = $home;
     return $response->toJson();
 }