getUser(); /* * 我的关注人数,我的粉丝,收藏 * 点赞?徽章? * */ $data1 = $user->myCareNum; $user->care_num = count($data1); $data2 = $user->myFans; $user->fans_num = count($data2); $data3 = $user->myCollection; $user->collection_num = count($data3); $data4 = $user->UserDream; $user->dream_num = count($data4); return $this->api($user); } /** * @api {get} /api/my/edit_user_info 修改个人信息 * @apiDescription 修改个人信息 * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK *{ * "status": true, * "status_code": 0, * "message": "", "data": { "emotion": [ { "value": "1", "name": "未婚" }, { "value": "2", "name": "已婚" }, { "value": "3", "name": "离异" } ], "sex": [ { "value": "0", "name": "男" }, { "value": "1", "name": "女" } ] } * } * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request * { * "status": false, * "status_code": 1500, * "message": "会员不存在", * "data": null * } */ public function editUserInfo (Request $request) { $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')-> where('dictionary_code','sex')->paginate(20); $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')-> where('dictionary_code','emotion')->paginate(20); return $this->api(compact('emotion','sex')); } /** * @api {post} /api/my/update_user_info 保存个人信息 * @apiDescription 保存个人信息 * @apiParam {string} pic 头像 * @apiParam {int} sex 性别 * @apiParam {string} signture 个性签名 * @apiParam {int} emotion 情感状态 * @apiParam {string} job 职业 * @apiParam {int} tall 身高 * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @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 *{ * "status": false, * "status_code": 600, * "message": "保存用户数据失败", * "data": null * } */ public function updateUserInfo(Request $request) { $user = $this->getUser(); $data = $request->except('_token'); $ok = $user->update($data); if ($ok == true) { return $this->api(''); }else{ return $this->error(ErrorCode::SAVE_USER_FAILED); } } /** * @api {get} /api/my/recharge 充值(recharge) * @apiDescription 充值(recharge) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function recharge(Request $request) { $validator = \Validator::make($request->all(), [ 'money' => 'required|integer', ], [ 'money.required' => '请输入金额', 'money.integer' => '请输入整数', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); $user = $this->getUser(); $user->coin += $request->money; $user->save(); return $this->api(compact('user')); } /** * @api {get} /api/my/system_info 系统消息(systemInfo) * @apiDescription 系统消息(systemInfo) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK *{ * "status": true, * "status_code": 0, * "message": "", * "data": { * "data": [ * ... * ] *} * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request * { * "status": true, * "status_code": 0, * "message": "", * "data": { * "data": [] * } *} */ public function systemInfo() { $user = $this->getUser(); $data = SystemInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get(); return $this->api(compact('data')); } /** * @api {get} /api/my/reply_my 回复我的(replyMy) * @apiDescription 回复我的(replyMy) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * * { * "status": true, * "status_code": 0, * "message": "", * "data": { * "comments_infos": [ * { * "id": 1, * "dream_id": 2, * "user_id": 2, * "level": 2, * "content": "啊哈", 评论内容 * "created_at": null, 评论时间 * "updated_at": null, * "deleted_at": null, * "dream_name": "去旅游去旅游2", 梦想介绍 * "dream_pic": "aaaaa", 梦想图片 * "progress": 0, 进度 * "reviewer": "22222", 评论者 * "reviewer_pic": "22222pic", 评论者头像 * } * ] * } * } * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function replyMy() { $user = $this->getUser(); // 梦想 $dreams = $user->UserDream; $data = $user->allInteraction; foreach ($data as $item) { $item->get_money = $item->dream->get_money; $item->money = $item->dream->money; } dd($data) ; if (count($dreams) == 0) return $this->error(ErrorCode::DREAM_NOT_EXIST); $comments_infos = []; foreach ($dreams as $dream){ $comments_info = $dream->DreamInfo; if (count($comments_info) > 0) { foreach ($comments_info as $k => $value) { $value->dream_name = $dream->dream; $value->dream_about = $dream->about; $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : ''; $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money); $value->reviewer = $value->CommentUser->nickname; $value->reviewer_pic = $value->CommentUser->pic; } $comments_infos[] = $comments_info; } } return $this->api(compact('comments_infos')); } /** * @api {post} /api/my/my_reply 我的回复(myReply) * @apiDescription 我的回复(recharge) * @apiGroup My * @apiParam {text} content 回复内容 * @apiParam {int} comment_id 评论ID * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * { * "status": true, * "status_code": 0, * "message": "", * "data": "" *} * HTTP/1.1 200 OK * @apiErrorExample {json} Error-Response: * { * "status": false, * "status_code": 1000, * "message": "输入不正确", * "data": null *} *{ * "status": false, * "status_code": 600, * "message": "保存用户数据失败", * "data": null *} * HTTP/1.1 400 Bad Request */ public function myReply(Request $request) { $user = $this->getUser(); $data = $request->except('_token'); $data['user_id'] = $user->id; if (!$request->content) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS); $ok = ReplyCommentsInfo::create($data); if ($ok) { return $this->api(''); }else{ return $this->error(ErrorCode::SAVE_USER_FAILED); } } /** * @api {get} /api/my/dream 我的梦想(dream) * @apiDescription 我的梦想(recharge) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * { * "status": true, * "status_code": 0, * "message": "", * "data": { * "dreams": [ * { * "id": 2, * "dream": "去旅游去旅游2", * "about": "欧冠胡234", * "dream_pic": "aaaaa", 封面图片 * "progress": 0, 进度 * ] * } * } * HTTP/1.1 200 OK * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function dream() { $user = $this->getUser(); // 梦想 $dreams = $user->UserDream; if (count($dreams) == 0) return $this->error(ErrorCode::DREAM_NOT_EXIST); foreach ($dreams as $dream){ $dream->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : ''; $dream->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money); } return $this->api($dreams); } /** * @api {get} /api/my/collection 我的收藏(collection) * @apiDescription 我的收藏(recharge) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function collection() { $user = $this->getUser(); $data = $user->myCollection; return $this->api(compact('data')); } /** * @api {get} /api/my/setting 设置(setting) * @apiDescription 设置(setting) * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK *{ * "status": true, ** "status_code": 0, * "message": "", * "data": { * "data": { * "key": "2511789", 电话 * "value": "关于喵喵介绍" 介绍 * } * } *} * @apiErrorExample {json} Error-Response: * HTTP/1.1 400 Bad Request */ public function setting() { $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first(); return $this->api(compact('data')); } /** * @api {post} /api/my/store_dream 发布梦想 * @apiDescription 发布梦想 * @apiParam {string} pics 梦想图片 数组 * @apiParam {string} video 梦想视频 * @apiParam {string} name 梦想标题 * @apiParam {string} about 梦想介绍 * @apiParam {int} coin 梦想币 * @apiParam {int} time 实现时间默认21*3600 * @apiGroup My * @apiPermission Passport * @apiVersion 0.1.0 * @apiSuccessExample {json} Success-Response: * { * "status": true, * "status_code": 0, * "message": "", * "data": "" *} * HTTP/1.1 200 OK * @apiErrorExample {json} Error-Response: * { * "status": false, * "status_code": 600, * "message": "保存用户数据失败", * "data": null * } * HTTP/1.1 400 Bad Request */ public function storeDream(Request $request) { $user = $this->getUser(); $validator = \Validator::make($request->all(), [ 'name' => 'required', 'about' => 'required', 'coin' => 'required|integer', 'time' => 'required|integer', ], [ 'name.required' => '梦想标题必填', 'about.required' => '梦想介绍必填', 'coin.required' => '梦想币必填', 'coin.integer' => '梦想币必须是正整数', 'time.required' => '实现时间必填', 'time.integer' => '实现时间必须是正整数', ] ); if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS); \Log::debug($user); $data2 = $user->myCareNum; $care_num = count($data2); $setting = BaseSettingsModel::where('category','paihang')->first(); $a = $setting?$setting->key:1; $b = $setting?$setting->value:1; $t = 21*3600 / 60; $data = $request->except('_token','pics'); $data['user_id'] = $user->id; \Log::debug(' care_num:'.$care_num.' a:'.$a.' b:'.$b.' t:'.$t); if ($care_num == 0) { $data['score'] = (($a/$t) + $b)*100000000 ; }else{ $data['score'] = (log($care_num) + ($a/$t) + $b)*100000000 ; } $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); $dream_id = DreamInfoModel::insertGetId($data); if ($dream_id) { // 梦想创建成功 关联关系中最新动态+1 /* $info = UserCareUser::where('other_user_id',$user->id)->paginate(20); foreach ($info as $item) { $item->dream_num += 1; $item->updated_at = date('Y-m-d H:i:s'); $item->save(); }*/ $pics = $request->pics; $video = $request->video; if (empty($pics) && empty($video)) { DreamInfoModel::destroy($dream_id); return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST); } $data = []; if (is_array($pics)) { foreach ($pics as $v){ $data[] = [ 'dream_id'=>$dream_id, 'pic' => $v, 'created_at' =>date('Y-m-d H:i:s'), 'updated_at' =>date('Y-m-d H:i:s'), ]; } DreamImages::insert($data); } return $this->api(''); } } }