/** * * @SWG\Api( * path="/comments", * description="评论(新20160216)", * @SWG\Operation( * method="GET", summary="评论列表", notes="评论列表", * type="UserComment", * @SWG\ResponseMessage(code=0, message="成功"), * @SWG\Parameter( * name="type", * description="类型,0---》商品 1---》主题", * paramType="query", * required=true, * allowMultiple=false, * type="integer" * ),@SWG\Parameter( * name="item_id", * description="项id", * paramType="query", * required=true, * allowMultiple=false, * type="integer" * ), * @SWG\Parameter( * name="PageNum", * description="分页开始位置", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=1 * ),@SWG\Parameter( * name="PerPage", * description="取得长度", * paramType="query", * required=false, * allowMultiple=false, * type="integer", * defaultValue=10 * ) * ) * ) */ public function index(Request $request) { $start = $request->input('PageNum', 0); $length = $request->input('PerPage', 10); $type = $request->input('type'); $item_id = $request->input('item_id'); $start = ($start - 1) * $length; $response = new BaseResponse(); $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', $type)->where('user_comments.item_id', $item_id); $rows = $comments->skip($start)->take($length)->orderBy('user_comments.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']; } $response->rows = $rows; $response->total = $comments->count(); return $response->toJson(); }
/** * * @SWG\Api( * path="/user_levels/{user_id}", * description="用户等级(新20160220)", * @SWG\Operation( * method="GET", summary="查询用户等级", notes="查询用户等级 level代表用户当前等级(1-5中的一个)sum代表用户消费总金额", * @SWG\ResponseMessage(code=0, message="成功"), * @SWG\Parameter( * name="user_id", * description="用户id", * paramType="path", * required=true, * allowMultiple=false, * type="integer", * ) * * ) * ) */ public function show($id) { $response = new BaseResponse(); $sum = Order::select(DB::raw('SUM(total_fee) as total_pay'))->where('user_id', $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(); $ret['level'] = $level['id']; $ret['sum'] = $sum; $response->Data = $ret; return $response->toJson(); }
/** * * @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(); }
/** * * @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(); }