=1 * "c": "8" * } *} * 排行 *{ * "status": true, * "status_code": 0, * "message": "", * "data": [ * { * "nickname": "ha", 昵称 * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg", 头像 * "score": 112000 支持分 * }, * ] *} * * @apiErrorExample {json} Error-Response: *HTTP/1.1 400 Bad Request *{ * "status": false, * "status_code": 1105, * "message": "用户不存在", * "data": null * } */ public function index(Request $request) { $user = $this->getUser(); $type = $request->type; //类型 $id = $request->id; //梦想ID if (empty($id)) return $this->error(ErrorCode::KEY_ERROR); if ($type == 'paihang') { $data = []; $info = SupportDreamModel::where('dream_id',$id)->get(); $arr = [] ; foreach ($info as $item) { if (!array_key_exists($item->user_id,$arr)) { $arr[$item->user_id] = $item->score; }else{ $arr[$item->user_id] += $item->score; } } arsort($arr); foreach ($arr as $k => $v){ $user = UserInfoModel::find($k); $user->score = $v; $data[] = $user; } return $this->api($data); } elseif ($type == 'interaction') { }else{ // 梦想 图片 支持者前三 支持乘数参数 用户余额 梦想分数 $score = 0 ; $a = SupportDreamModel::where('dream_id',$id)->get(); foreach ($a as $value){ $score += $value->score; } $money = $user->money; $number = BaseSettingsModel::where('category','score')->select('key','value')->first(); $a = count($number) > 0 ? $number->key : ''; $c = count($number) > 0 ? $number->value : ''; $dream = DreamInfoModel::find($id); $imgs = DreamImages::where('dream_id',$id)->orderBy('id','desc')->get(); $info = SupportDreamModel::where('dream_id',$id)->get(); $arr = [] ; foreach ($info as $item) { if (!array_key_exists($item->user_id,$arr)) { $arr[$item->user_id] = $item->score; }else{ $arr[$item->user_id] += $item->score; } } arsort($arr); foreach ($arr as $k => $v){ $arr[$k] = UserInfoModel::find($k)->pic; } return $this->api(compact('dream','imgs','money','arr','a','c','score')); } } /** * @api {post} /api/dream/support 支持梦想 * @apiDescription 支持梦想 * @apiGroup Dream * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} coin 支持梦想币数量 * @apiParam {int} id 梦想ID * @apiParam {int} number 支持乘数 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK *{ * "status": true, * "status_code": 0, * "message": "", * "data": "" *} * @apiErrorExample {json} Error-Response: *HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } * 可能出现的代码 * { * "status": false, * "status_code": 1303, * "message": "商户余额不足", * "data": null * } * */ public function support(Request $request) { $validator = \Validator::make($request->all(), [ 'coin' => 'required', 'id' => 'required', 'number' => 'required', ], [ 'coin.required' => '梦想币不能为空', 'id.required' => '支持梦想不能为空', 'number.required' => '支持乘数不能为空', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); $user = $this->getUser(); $dream_id = $request->id; $dream_info = DreamInfoModel::find($dream_id); $user_id = $dream_info->user_id; $coin = $request->coin; $number = $request->number; if ($user->money < $coin) { return $this->error(ErrorCode::MERCHANT_BALANCE_NOT_ENOUGH); }else{ $user->money = $user->money - $coin; $user->save(); $dream_info->get_money += $coin; $dream_info->save(); $data = [ 'user_id'=>$user->id, 'dream_id'=>$dream_id, 'to_user_id'=>$user_id, 'coin'=>$coin, 'score'=>$coin*$number, ]; $ok = SupportDreamModel::create($data); if (!$ok) { return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID); } // 记录充值记录 $data = [ 'from_id' =>$user->id, 'to_id' => $user_id, 'from_amount' => $coin, 'to_amount' => $coin, 'from_type' => AccountLog::TYPE_COIN, 'to_type' => AccountLog::TYPE_COIN, 'op' => AccountLog::OP_SUPPORT, ]; AccountLog::create($data); return $this->api(''); } } // 收藏关注梦想 /** * @api {get} /api/dream/collection 收藏梦想 * @apiDescription 收藏梦想 * @apiGroup Dream * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} id 梦想ID * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK *{ * "status": true, * "status_code": 0, * "message": "", * "data": "" *} * @apiErrorExample {json} Error-Response: *HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } * */ public function collection(Request $request) { if (empty($request->id)) return $this->error(ErrorCode::KEY_ERROR); $user = $this->getUser(); $data = [ 'user_id' =>$user->id, 'dream_id' =>$request->id, ]; $info = UserCareDream::where('user_id',$user->id)-> where('dream_id',$request->id)->first(); if (count($info) == 0) { UserCareDream::create($data); } return $this->api(''); } }