MyController.php 13 KB

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