MyController.php 11 KB

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