=1 * "c": "8" * } *} * 排行 *{ * "status": true, * "status_code": 0, * "message": "", * "data": [ * { * "nickname": "ha", 昵称 * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg", 头像 * "score": 112000 支持分 * }, * ] *} * 互动 *{ * "status": true, * "status_code": 0, * "message": "", * "data": { * "data": [ * { * "id": 7, * "dream_id": 2, * "title": "梦想动态有力来了", * "pic1": "http\"//www.baidu.com", * "created_at": "2017-06-22 21:09:18", * "updated_at": "2017-06-22 21:09:18", * "deleted_at": null, * "comments": [ 评论 * { * "interaction_id": 7, * "user_id": 1, * "level": 0, * "content": "不错的梦想", * "updated_at": null, * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg", 评论者头像 * "replay": [ 回复 * { * "user_id": 1, * "level": 0, * "content": "我也觉得不错", * "updated_at": null, * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg" 回复者头像 * }, * { * "user_id": 6, * "level": 0, * "content": "祝你梦想成真", * "updated_at": null, * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg" * } * } * ] * ] * }, * "times": 720000 梦想实现倒计时(s) * } *} * @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') { $times = DreamInfoModel::find($id)->time; $data = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get(); foreach ($data as $item) { $item->comments = $item->comments; foreach ($item->comments as $comment) { $comment->pic = UserInfoModel::find($comment->user_id)->pic; $comment->replay = $comment->replay; foreach ($comment->replay as $k1 => $v1){ $v1->pic = UserInfoModel::find($v1->user_id)->pic; } } } return $this->api(compact('data','times')); }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); $message = UserInfoModel::find($user->id)->nickname.'为你的梦想捐赠'.$coin.'梦想币'; $info = [ 'user_id' => $user_id, 'message' => $message, ]; SystemInfoModel::create($info); 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, 'dream_user_id' =>DreamInfoModel::find($request->id)->user_id, ]; $info = UserCareDream::where('user_id',$user->id)-> where('dream_id',$request->id)->first(); if (count($info) == 0) { UserCareDream::create($data); } return $this->api(''); } // 发布关于梦想的动态 /** * @api {post} /api/dream/add_info 新增动态 * @apiDescription 新增动态 * @apiGroup Dream * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} id 梦想ID * @apiParam {string} title 梦想标题 * @apiParam {array} pics[] 图片数组 * @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 addInfo(Request $request) { $validator = \Validator::make($request->all(), [ 'id' => 'required', 'title' => 'required', ], [ 'dream_id.required' => '梦想ID不能为空', 'title.required' => '动态标题不能为空', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); $pics = $request->pics; if (empty($pics) || !is_array($pics)) { return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST); } $data = []; foreach ($pics as $k => $pic) { $data['pic'.($k+1)] = $pic; } $dream_id = $request->id; $title = $request->title; $data['dream_id'] = $dream_id; $data['title'] = $title; $ok = InteractionInfo::create($data); if ($ok) { // 收藏梦想最新动态加一 UserCareDream::where('dream_id',$dream_id)->increment('interaction_number',1); return $this->api(''); }else{ return $this->error(ErrorCode::SAVE_USER_FAILED); } } }