MyController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\DreamInfoModel;
  4. use App\Models\ReplyCommentsInfo;
  5. use Illuminate\Http\Request;
  6. use App\Library\Protocol\ErrorCode;
  7. class MyController extends Controller
  8. {
  9. /**
  10. * @api {get} /api/my/index 个人首页(index)
  11. * @apiDescription 个人首页(index)
  12. * @apiGroup My
  13. * @apiPermission Passport
  14. * @apiSuccessExample {json} Success-Response:
  15. * HTTP/1.1 200 O* "status": true,
  16. * "status_code": 0,
  17. * "message": "",
  18. * "data": {
  19. * "my_care_num": 4,关注
  20. * "my_fens_num": 3,粉丝
  21. * "my_collection_num": 2,收藏
  22. * "my_dream_num": 1,发帖
  23. * "user": {
  24. * "id": 1,
  25. * "tel": "13880642880",
  26. * "password": "",
  27. * "nickname": "",
  28. * "pic": "",
  29. * "sign": 0,
  30. * "money": 0,余额
  31. * "sex": 1,
  32. * "signture": "",个性签名
  33. * "tall": "",
  34. * "job": "",
  35. * "emotion": 1,
  36. * "address": "",
  37. * "detail_address": "",
  38. * "status": 1,
  39. * "remember_token": "",
  40. * "created_at": "2017-06-02 02:30:12",
  41. * "updated_at": "2017-06-02 02:30:12",
  42. * "deleted_at": null,
  43. * }
  44. * @apiErrorExample {json} Error-Response:
  45. * HTTP/1.1 400 Bad Request
  46. *{
  47. *"status": true,
  48. *"status_code": 0,
  49. *"message": "",
  50. *"data": {
  51. *"user": null
  52. * }
  53. *}
  54. */
  55. public function index()
  56. {
  57. $user = $this->getUser();
  58. /*
  59. * 我的关注人数,我的粉丝,收藏
  60. * 点赞?徽章?
  61. * */
  62. $data1 = $user->myCareNum;
  63. $data2 = $user->myFens;
  64. $data3 = $user->myCollection;
  65. $data4 = $user->UserDream;
  66. $my_care_num = count($data1);
  67. $my_fens_num = count($data2);
  68. $my_collection_num = count($data3);
  69. $my_dream_num = count($data4);//发帖数
  70. return $this->api(compact('my_care_num','my_fens_num','my_collection_num','my_dream_num','user'));
  71. }
  72. /**
  73. * @api {get} /api/my/persona 个人信息(persona)
  74. * @apiDescription 个人信息(persona)
  75. * @apiGroup My
  76. * @apiPermission Passport
  77. * @apiVersion 0.1.0
  78. * @apiSuccessExample {json} Success-Response:
  79. * HTTP/1.1 200 OK
  80. *{
  81. *"status": true,
  82. *"status_code": 0,
  83. *"message": "",
  84. *"data": {
  85. *"user": {
  86. *"id": 1,
  87. * "tel": "13880642880",手机
  88. *"nickname": "",昵称
  89. *"sex": 1,性别
  90. *"job": "", 职业
  91. *"emotion": 1,情感状态
  92. *"address": "",
  93. *"detail_address": "",
  94. *"status": 1,
  95. *"tall": 1, 身高
  96. *}
  97. * }
  98. *}
  99. * @apiErrorExample {json} Error-Response:
  100. * HTTP/1.1 400 Bad Request
  101. *{
  102. *"status": true,
  103. *"status_code": 0,
  104. *"message": "",
  105. *"data": {
  106. *"user": null
  107. * }
  108. *}
  109. */
  110. public function persona()
  111. {
  112. $user = $this->getUser();
  113. return $this->api(compact('user'));
  114. }
  115. /**
  116. * @api {get} /api/my/recharge 充值(recharge)
  117. * @apiDescription 充值(recharge)
  118. * @apiGroup My
  119. * @apiPermission Passport
  120. * @apiVersion 0.1.0
  121. * @apiSuccessExample {json} Success-Response:
  122. * HTTP/1.1 200 OK
  123. * @apiErrorExample {json} Error-Response:
  124. * HTTP/1.1 400 Bad Request
  125. */
  126. public function recharge()
  127. {
  128. $user = $this->getUser();
  129. return $this->api(compact('user'));
  130. }
  131. /**
  132. * @api {get} /api/my/system_info 系统消息(systemInfo)
  133. * @apiDescription 系统消息(systemInfo)
  134. * @apiGroup My
  135. * @apiPermission Passport
  136. * @apiVersion 0.1.0
  137. * @apiSuccessExample {json} Success-Response:
  138. * HTTP/1.1 200 OK
  139. *{
  140. *"status": true,
  141. *"status_code": 0,
  142. *"message": "",
  143. * "data": {
  144. *"data": [
  145. *{
  146. *"nickname": "",充值人
  147. *"pivot": {
  148. *"coin": 0 捐赠梦想币数量
  149. *}
  150. * @apiErrorExample {json} Error-Response:
  151. * HTTP/1.1 400 Bad Request
  152. * {
  153. *"status": true,
  154. *"status_code": 0,
  155. *"message": "",
  156. *"data": {
  157. *"data": []
  158. *}
  159. *}
  160. *}
  161. */
  162. public function systemInfo()
  163. {
  164. $user = $this->getUser();
  165. $data = $user->SystemInfo;
  166. return $this->api(compact('data'));
  167. }
  168. /**
  169. * @api {get} /api/my/reply_my 回复我的(replyMy)
  170. * @apiDescription 回复我的(replyMy)
  171. * @apiGroup My
  172. * @apiPermission Passport
  173. * @apiVersion 0.1.0
  174. * @apiSuccessExample {json} Success-Response:
  175. * HTTP/1.1 200 OK
  176. *
  177. * {
  178. *"status": true,
  179. *"status_code": 0,
  180. *"message": "",
  181. *"data": {
  182. *"comments_infos": [
  183. *{
  184. * "id": 1,
  185. *"dream_id": 2,
  186. *"user_id": 2,
  187. *"level": 2,
  188. *"content": "啊哈", 评论内容
  189. *"created_at": null, 评论时间
  190. *"updated_at": null,
  191. *"deleted_at": null,
  192. *"dream_name": "去旅游去旅游2", 梦想介绍
  193. *"dream_pic": "aaaaa", 梦想图片
  194. * "progress": 0, 进度
  195. *"reviewer": "22222", 评论者
  196. *"reviewer_pic": "22222pic", 评论者头像
  197. }
  198. ]
  199. }
  200. }
  201. * @apiErrorExample {json} Error-Response:
  202. * HTTP/1.1 400 Bad Request
  203. */
  204. public function replyMy()
  205. {
  206. $user = $this->getUser();
  207. // 梦想
  208. $dreams = $user->UserDream;
  209. if (count($dreams) == 0)
  210. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  211. foreach ($dreams as $dream){
  212. $comments_infos = $dream->DreamInfo;
  213. if (count($comments_infos) > 0) {
  214. foreach ($comments_infos as $k => $value) {
  215. $value->dream_name = $dream->dream;
  216. $value->dream_about = $dream->about;
  217. $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  218. $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  219. $value->reviewer = $value->CommentUser->nickname;
  220. $value->reviewer_pic = $value->CommentUser->pic;
  221. }
  222. }
  223. }
  224. return $this->api(compact('comments_infos'));
  225. }
  226. /**
  227. * @api {post} /api/my/my_reply 我的回复(myReply)
  228. * @apiDescription 我的回复(recharge)
  229. * @apiGroup My
  230. * @apiParam {text} content 回复内容
  231. * @apiParam {int} comment_id 评论ID
  232. * @apiPermission Passport
  233. * @apiVersion 0.1.0
  234. * @apiSuccessExample {json} Success-Response:
  235. * {
  236. *"status": true,
  237. *"status_code": 0,
  238. *"message": "",
  239. *"data": ""
  240. *}
  241. * HTTP/1.1 200 OK
  242. * @apiErrorExample {json} Error-Response:
  243. * {
  244. *"status": false,
  245. *"status_code": 1000,
  246. *"message": "输入不正确",
  247. *"data": null
  248. *}
  249. * {
  250. *"status": false,
  251. *"status_code": 600,
  252. *"message": "保存用户数据失败",
  253. *"data": null
  254. *}
  255. * HTTP/1.1 400 Bad Request
  256. */
  257. public function myReply(Request $request)
  258. {
  259. $user = $this->getUser();
  260. $data = $request->except('_token');
  261. $data['user_id'] = $user->id;
  262. if (!$request->content)
  263. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS);
  264. $ok = ReplyCommentsInfo::create($data);
  265. if ($ok) {
  266. return $this->api('');
  267. }else{
  268. return $this->error(ErrorCode::SAVE_USER_FAILED);
  269. }
  270. }
  271. /**
  272. * @api {get} /api/my/dream 我的梦想(dream)
  273. * @apiDescription 我的梦想(recharge)
  274. * @apiGroup My
  275. * @apiPermission Passport
  276. * @apiVersion 0.1.0
  277. * @apiSuccessExample {json} Success-Response:
  278. * {
  279. *"status": true,
  280. * "status_code": 0,
  281. * "message": "",
  282. * "data": {
  283. * "dreams": [
  284. *{
  285. *"id": 2,
  286. * "dream": "去旅游去旅游2",
  287. *"about": "欧冠胡234",
  288. * "dream_pic": "aaaaa",
  289. * "progress": 0, 进度
  290. * ]
  291. * }
  292. * }
  293. * HTTP/1.1 200 OK
  294. * @apiErrorExample {json} Error-Response:
  295. * HTTP/1.1 400 Bad Request
  296. */
  297. public function dream()
  298. {
  299. $user = $this->getUser();
  300. // 梦想
  301. $dreams = $user->UserDream;
  302. if (count($dreams) == 0)
  303. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  304. foreach ($dreams as $dream){
  305. $dream->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  306. $dream->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  307. }
  308. return $this->api(compact('dreams'));
  309. }
  310. /**
  311. * @api {get} /api/my/collection 我的收藏(collection)
  312. * @apiDescription 我的收藏(recharge)
  313. * @apiGroup My
  314. * @apiPermission Passport
  315. * @apiVersion 0.1.0
  316. * @apiSuccessExample {json} Success-Response:
  317. * HTTP/1.1 200 OK
  318. * @apiErrorExample {json} Error-Response:
  319. * HTTP/1.1 400 Bad Request
  320. */
  321. public function collection()
  322. {
  323. $user = $this->getUser();
  324. return $this->api(compact('user'));
  325. }
  326. /**
  327. * @api {get} /api/my/setting 设置(setting)
  328. * @apiDescription 设置(setting)
  329. * @apiGroup My
  330. * @apiPermission Passport
  331. * @apiVersion 0.1.0
  332. * @apiSuccessExample {json} Success-Response:
  333. * HTTP/1.1 200 OK
  334. * @apiErrorExample {json} Error-Response:
  335. * HTTP/1.1 400 Bad Request
  336. */
  337. public function setting()
  338. {
  339. $user = $this->getUser();
  340. return $this->api(compact('user'));
  341. }
  342. /**
  343. * @api {post} /api/my/add_dream 发布梦想(addDream)
  344. * @apiDescription 发布梦想(addDream)
  345. * @apiParam {string} pic 梦想图片 数组
  346. * @apiGroup My
  347. * @apiPermission Passport
  348. * @apiVersion 0.1.0
  349. * @apiSuccessExample {json} Success-Response:
  350. * HTTP/1.1 200 OK
  351. * @apiErrorExample {json} Error-Response:
  352. * HTTP/1.1 400 Bad Request
  353. */
  354. public function addDream(Request $request)
  355. {
  356. $user = $this->getUser();
  357. $validator = \Validator::make($request->all(),
  358. [
  359. 'dream' => 'required',
  360. 'about' => 'required',
  361. 'money' => 'required|integer',
  362. ],
  363. [
  364. 'dream.required' => '梦想标题必填',
  365. 'about.required' => '梦想介绍必填',
  366. 'money.required' => '梦想币必填',
  367. 'money.integer' => '梦想币必须是正整数',
  368. ]
  369. );
  370. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  371. $data = $request->except('_token','pic');
  372. $data['created_at'] = date('Y-m-d H:i:s');
  373. $data['updated_at'] = date('Y-m-d H:i:s');
  374. $dream_id = DreamInfoModel::insertGetId($data);
  375. if ($dream_id) {
  376. $data1['dream_id'] = $dream_id;
  377. $data1['user_id'] = $user->id;
  378. $data1['created_at'] = date('Y-m-d H:i:s');
  379. $data1['updated_at'] = date('Y-m-d H:i:s');
  380. }
  381. $arr = $request->pic;
  382. if (is_array($arr)) {
  383. }
  384. return $arr;
  385. }
  386. /**
  387. * @api {get} /api/my/dream_about 梦想介绍(dreamAbout)
  388. * @apiDescription 梦想介绍(dreamAbout)
  389. * @apiGroup My
  390. * @apiPermission Passport
  391. * @apiVersion 0.1.0
  392. * @apiSuccessExample {json} Success-Response:
  393. * HTTP/1.1 200 OK
  394. * @apiErrorExample {json} Error-Response:
  395. * HTTP/1.1 400 Bad Request
  396. */
  397. public function dreamAbout()
  398. {
  399. $user = $this->getUser();
  400. return $this->api(compact('user'));
  401. }
  402. }