user_id; $care = UserCareUser::where('user_id',$user_id)->get(); $fens = UserCareUser::where('other_user_id',$user_id)->get(); $user = UserInfoModel::find($user_id); if (count($user == 0)) return $this->error(ErrorCode::USER_DOES_NOT_EXIST); $job = BaseSettingsModel::where(['category' => 'job'])->where(['key' => $user->job])->first(); $job = count($job) > 0 ? $job->value : ''; $emotion = BaseSettingsModel::where(['category' => 'emotion'])->where(['key' => $user->emotion])->first(); $emotion = count($emotion) > 0 ? $emotion->value : ''; // 当前梦想 $near_dream_id = UserDream::where('user_id',$user_id)->orderBy('id','desc')->first()->dream_id; $near_dream =DreamInfoModel::find($near_dream_id); // 封面图片 $near_dream_pic = DreamImages::where('dream_id',$near_dream_id)->select('pic')->get(); // 曾经的梦想 $dreams = $user->UserDream; foreach ($dreams as $dream){ $dream->pic = $dream->dreamImgs; } $user->score = 1000;//自定义 算法 $user->care = count($care); $user->fens = count($fens); $user->job = $job; $user->emotion = $emotion; // 支持的梦想 $sup_dreams = $user->supDream; foreach ($sup_dreams as $sup_dream){ $sup_dream->pic = $sup_dream->dreamImgs; } return $this->api(compact('user','near_dream','sup_dreams','near_dream_pic')); } /** * @api {post} /api/user/support 支持梦想 * @apiDescription 支持梦想 * @apiGroup Auth * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} coin 支持梦想币数量 * @apiParam {int} dream_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 [] * } * 可能出现的代码 * { *"status": false, *"status_code": 1303, *"message": "商户余额不足", * "data": null * } * */ public function support(Request $request) { $user = $this->getUser(); $dream_id = $request->dream_id; $dream_info = DreamInfoModel::find($dream_id); $validator = \Validator::make($request->all(), [ 'coin' => 'required', 'dream_id' => 'required', ], [ 'coin.required' => '梦想币不能为空', 'dream_id.required' => '支持对象不能为空', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); $coin = $request->coin; 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, 'other_id'=>$dream_id, 'coin'=>$coin, ]; $ok = SystemInfoModel::create($data); if (!$ok) { return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID); } return $this->api(''); } } /** * @api {post} /api/auth/bank_card/update 更新银行卡 * @apiDescription 更新银行卡 * @apiGroup Auth * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} user_id 用户ID * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "state": true, * "code": 0, * "message": "success", * "data": { * .... * } * } * @apiErrorExample {json} Error-Response: *HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } */ public function interaction(Request $request) { } /** * @api {post} /api/auth/bank_card/update 更新银行卡 * @apiDescription 更新银行卡 * @apiGroup Auth * @apiPermission Passport * @apiVersion 0.1.0 * @apiParam {int} user_id 用户ID * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * "state": true, * "code": 0, * "message": "success", * "data": { * .... * } * } * @apiErrorExample {json} Error-Response: *HTTP/1.1 400 Bad Request * { * "state": false, * "code": 1000, * "message": "传入参数不正确", * "data": null or [] * } */ public function paihang(Request $request) { } }