MyController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\BaseDictionaryOptionModel;
  4. use App\Models\BaseSettingsModel;
  5. use App\Models\SystemInfoModel;
  6. use App\Models\UserCareDream;
  7. use App\Models\UserInfoModel;
  8. use Illuminate\Http\Request;
  9. use App\Services\Base\ErrorCode;
  10. class MyController extends Controller
  11. {
  12. /**
  13. * @api {get} /api/my/show 个人首页
  14. * @apiDescription 个人首页
  15. * @apiGroup My
  16. * @apiPermission Passport
  17. * @apiSuccessExample {json} Success-Response:
  18. * HTTP/1.1 200 O* "status": true,
  19. *{
  20. * "status": true,
  21. * "status_code": 0,
  22. * "message": "",
  23. * "data": {
  24. * "id": 1,
  25. * "phone": "13880642880",
  26. * "nickname": "name1",
  27. * "avatar": "https://tims%2Fitem%225_kzrcM.thumb.224_0.jpeg",
  28. * "birthday": "2000-06-21",
  29. * "sign": 0,
  30. * "money": 0,
  31. * "coin": 1300,
  32. * "sex": 1,
  33. * "signture": "",
  34. * "height": 170,
  35. * "work": "",
  36. * "emotion": 1,
  37. * "address": "",
  38. * "city": "",
  39. * "detail_address": "",
  40. * "status": 1,
  41. * "wechat": "",
  42. * "weibo": "",
  43. * "remember_token": "",
  44. * "created_at": "2017-06-25 10:27:08",
  45. * "updated_at": "2017-06-25 15:20:11",
  46. * "deleted_at": null,
  47. * "care_dreams_number": 2,
  48. * "fans_number": 0,
  49. * "collection_number": 0,
  50. * "interaction_number": 0,
  51. * }
  52. *}
  53. * @apiErrorExample {json} Error-Response:
  54. * HTTP/1.1 400 Bad Request
  55. *{
  56. * "status": true,
  57. * "status_code": 0,
  58. * "message": "",
  59. * "data": {
  60. * "user": null
  61. * }
  62. *}
  63. */
  64. public function show()
  65. {
  66. $user = $this->getUser();
  67. /*
  68. * 我的关注人数,我的粉丝,收藏
  69. * 点赞?徽章?
  70. * */
  71. $care_num = $user->careDreams;
  72. $user->care_dreams_number = count($care_num);
  73. $fens = UserCareDream::where('dream_user_id',$user->id)->get();
  74. $user->fans_number = count($fens);
  75. $collection = $user->myCollection;
  76. $user->collection_number = count($collection);
  77. $interaction_infos = $user->allInteraction;
  78. $user->interaction_number = count($interaction_infos);
  79. return $this->api($user);
  80. }
  81. /**
  82. * @api {get} /api/my/edit 修改个人信息
  83. * @apiDescription 修改个人信息
  84. * @apiGroup My
  85. * @apiPermission Passport
  86. * @apiVersion 0.1.0
  87. * @apiSuccessExample {json} Success-Response:
  88. * HTTP/1.1 200 OK
  89. *{
  90. * "status": true,
  91. * "status_code": 0,
  92. * "message": "",
  93. "data": {
  94. "emotion": [
  95. {
  96. "value": "1",
  97. "name": "未婚"
  98. },
  99. {
  100. "value": "2",
  101. "name": "已婚"
  102. },
  103. {
  104. "value": "3",
  105. "name": "离异"
  106. }
  107. ],
  108. "sex": [
  109. {
  110. "value": "0",
  111. "name": "男"
  112. },
  113. {
  114. "value": "1",
  115. "name": "女"
  116. }
  117. ]
  118. }
  119. * }
  120. * @apiErrorExample {json} Error-Response:
  121. * HTTP/1.1 400 Bad Request
  122. * {
  123. * "status": false,
  124. * "status_code": 1500,
  125. * "message": "会员不存在",
  126. * "data": null
  127. * }
  128. */
  129. public function edit()
  130. {
  131. $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  132. where('dictionary_code','sex')->get();
  133. $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  134. where('dictionary_code','emotion')->get();
  135. return $this->api(compact('emotion','sex'));
  136. }
  137. /**
  138. * @api {post} /api/my/update 保存个人信息
  139. * @apiDescription 保存个人信息
  140. * @apiParam {string} pic 头像
  141. * @apiParam {int} sex 性别
  142. * @apiParam {string} signture 个性签名
  143. * @apiParam {int} emotion 情感状态
  144. * @apiParam {string} work 职业
  145. * @apiParam {int} height 身高
  146. * @apiGroup My
  147. * @apiPermission Passport
  148. * @apiVersion 0.1.0
  149. * @apiSuccessExample {json} Success-Response:
  150. * HTTP/1.1 200 OK
  151. *{
  152. * "status": true,
  153. * "status_code": 0,
  154. * "message": "",
  155. * "data": ""
  156. *}
  157. * @apiErrorExample {json} Error-Response:
  158. * HTTP/1.1 400 Bad Request
  159. *{
  160. * "status": false,
  161. * "status_code": 600,
  162. * "message": "保存用户数据失败",
  163. * "data": null
  164. * }
  165. */
  166. public function update(Request $request)
  167. {
  168. $user = $this->getUser();
  169. $data = $request->except('_token');
  170. $ok = $user->update($data);
  171. if ($ok == true) {
  172. return $this->api('');
  173. }else{
  174. return $this->error(ErrorCode::SAVE_USER_FAILED);
  175. }
  176. }
  177. /**
  178. * @api {post} /api/my/recharge 充值
  179. * @apiDescription 充值
  180. * @apiGroup My
  181. * @apiParam {int} coin 充值金额
  182. * @apiPermission Passport
  183. * @apiVersion 0.1.0
  184. * @apiSuccessExample {json} Success-Response:
  185. * HTTP/1.1 200 OK
  186. * @apiErrorExample {json} Error-Response:
  187. * HTTP/1.1 400 Bad Request
  188. */
  189. public function recharge(Request $request)
  190. {
  191. $validator = \Validator::make($request->all(),
  192. [
  193. 'coin' => 'required|integer',
  194. ],
  195. [
  196. 'coin.required' => '请填写金额',
  197. 'coin.integer' => '请输入整数',
  198. ]
  199. );
  200. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  201. $user = $this->getUser();
  202. $user->coin += $request->coin;
  203. $user->save();
  204. return $this->api('');
  205. }
  206. /**
  207. * @api {get} /api/my/system_info 系统消息
  208. * @apiDescription 系统消息
  209. * @apiGroup My
  210. * @apiPermission Passport
  211. * @apiVersion 0.1.0
  212. * @apiSuccessExample {json} Success-Response:
  213. * HTTP/1.1 200 OK
  214. *{
  215. * "status": true,
  216. * "status_code": 0,
  217. * "message": "",
  218. * "data": {
  219. * "data": [
  220. * ...
  221. * ]
  222. *}
  223. * @apiErrorExample {json} Error-Response:
  224. * HTTP/1.1 400 Bad Request
  225. */
  226. public function systemInfo()
  227. {
  228. $user = $this->getUser();
  229. $data = SystemInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
  230. return $this->api(compact('data'));
  231. }
  232. // 回复我的
  233. // public function replyMy()
  234. // {
  235. //
  236. // $user = $this->getUser();
  237. //// 梦想
  238. // $dreams = $user->UserDream;
  239. //
  240. // $data = $user->allInteraction;
  241. // foreach ($data as $item) {
  242. // $item->get_money = $item->dream->get_money;
  243. // $item->money = $item->dream->money;
  244. // }
  245. // dd($data) ;
  246. // if (count($dreams) == 0)
  247. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  248. // $comments_infos = [];
  249. // foreach ($dreams as $dream){
  250. // $comments_info = $dream->DreamInfo;
  251. // if (count($comments_info) > 0) {
  252. // foreach ($comments_info as $k => $value) {
  253. // $value->dream_name = $dream->dream;
  254. // $value->dream_about = $dream->about;
  255. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  256. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  257. // $value->reviewer = $value->CommentUser->nickname;
  258. // $value->reviewer_pic = $value->CommentUser->pic;
  259. // }
  260. // $comments_infos[] = $comments_info;
  261. // }
  262. // }
  263. //
  264. // return $this->api(compact('comments_infos'));
  265. // }
  266. /**
  267. * @api {get} /api/my/dream 我的梦想
  268. * @apiDescription 我的梦想
  269. * @apiGroup My
  270. * @apiPermission Passport
  271. * @apiVersion 0.1.0
  272. * @apiSuccessExample {json} Success-Response:
  273. * HTTP/1.1 200 OK
  274. *{
  275. * "status": true,
  276. * "status_code": 0,
  277. * "message": "",
  278. * "data": [
  279. * {
  280. * "id": 5,
  281. * "user_id": 1,
  282. * "name": "梦想标题1",
  283. * "about": "梦想介绍",
  284. * "coin": 2500,
  285. * "time": 21,
  286. * "get_coin": 0,
  287. * "status": 0,
  288. * "video": null,
  289. * "sign": "",
  290. * "created_at": "2017-06-25 12:45:22",
  291. * "updated_at": "2017-06-25 12:45:22",
  292. * "pic": "https://timgsa.baidu.com/timg?image7b14f12f.jpg",
  293. * },
  294. * ]
  295. *}
  296. * @apiErrorExample {json} Error-Response:
  297. * HTTP/1.1 400 Bad Request
  298. */
  299. public function dream()
  300. {
  301. $user = $this->getUser();
  302. $dreams = $user->dreams;
  303. if (count($dreams) == 0)
  304. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  305. foreach ($dreams as $dream){
  306. $dream->pic = count($dream->img) > 0 ? $dream->img->pic : '';
  307. }
  308. return $this->api($dreams);
  309. }
  310. /**
  311. * @api {get} /api/my/collection 我的收藏
  312. * @apiDescription 我的收藏
  313. * @apiGroup My
  314. * @apiPermission Passport
  315. * @apiVersion 0.1.0
  316. * @apiSuccessExample {json} Success-Response:
  317. * HTTP/1.1 200 OK
  318. *{
  319. * "status": true,
  320. * "status_code": 0,
  321. * "message": "",
  322. * "data": {
  323. * "data": [
  324. * { 梦想详情
  325. * "id": 12,
  326. * "user_id": 2,
  327. * "name": "用户2梦想标题166",
  328. * "about": "用户2梦想介绍666",
  329. * "coin": 2500,
  330. * "time": 21,
  331. * "get_coin": 0,
  332. * "status": 0,
  333. * "video": null,
  334. * "sign": "",
  335. * },
  336. * "img": {
  337. * "title": "",
  338. * "pic": "https://f12f.jpg" 梦想封面图片
  339. * }
  340. * ],
  341. * "users": {
  342. * "2": "https://xxx.jpeg" ID号和头像
  343. * }
  344. * }
  345. *}
  346. * @apiErrorExample {json} Error-Response:
  347. * HTTP/1.1 400 Bad Request
  348. */
  349. public function collection()
  350. {
  351. $user = $this->getUser();
  352. $dreams = $user->collection;
  353. $users = [];
  354. foreach ($dreams as $item) {
  355. if ($item->pivot->interaction_number > 0) {
  356. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  357. $avatar = $user_info ? $user_info->avatar : '';
  358. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  359. $users[$item->pivot->dream_user_id] = $avatar;
  360. }
  361. }
  362. $item->img;
  363. }
  364. return $this->api(compact('dreams','users'));
  365. }
  366. /**
  367. * @api {get} /api/my/setting 设置
  368. * @apiDescription 设置
  369. * @apiGroup My
  370. * @apiPermission Passport
  371. * @apiVersion 0.1.0
  372. * @apiSuccessExample {json} Success-Response:
  373. * HTTP/1.1 200 OK
  374. *{
  375. * "status": true,
  376. * "status_code": 0,
  377. * "message": "",
  378. * "data": {
  379. * "key": "2511789", 电话
  380. * "value": "关于喵喵介绍" 关于喵喵
  381. * }
  382. *}
  383. * @apiErrorExample {json} Error-Response:
  384. * HTTP/1.1 400 Bad Request
  385. */
  386. public function setting()
  387. {
  388. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  389. return $this->api($data);
  390. }
  391. }