MyController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. * }
  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. * }
  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. public function systemInfo()
  164. {
  165. $user = $this->getUser();
  166. $data = $user->SystemInfo;
  167. return $this->api(compact('data'));
  168. }
  169. /**
  170. * @api {get} /api/my/reply_my 回复我的(replyMy)
  171. * @apiDescription 回复我的(replyMy)
  172. * @apiGroup My
  173. * @apiPermission Passport
  174. * @apiVersion 0.1.0
  175. * @apiSuccessExample {json} Success-Response:
  176. * HTTP/1.1 200 OK
  177. *
  178. * {
  179. * "status": true,
  180. * "status_code": 0,
  181. * "message": "",
  182. * "data": {
  183. * "comments_infos": [
  184. * {
  185. * "id": 1,
  186. * "dream_id": 2,
  187. * "user_id": 2,
  188. * "level": 2,
  189. * "content": "啊哈", 评论内容
  190. * "created_at": null, 评论时间
  191. * "updated_at": null,
  192. * "deleted_at": null,
  193. * "dream_name": "去旅游去旅游2", 梦想介绍
  194. * "dream_pic": "aaaaa", 梦想图片
  195. * "progress": 0, 进度
  196. * "reviewer": "22222", 评论者
  197. * "reviewer_pic": "22222pic", 评论者头像
  198. * }
  199. * ]
  200. * }
  201. * }
  202. * @apiErrorExample {json} Error-Response:
  203. * HTTP/1.1 400 Bad Request
  204. */
  205. public function replyMy()
  206. {
  207. $user = $this->getUser();
  208. // 梦想
  209. $dreams = $user->UserDream;
  210. if (count($dreams) == 0)
  211. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  212. foreach ($dreams as $dream){
  213. $comments_infos = $dream->DreamInfo;
  214. if (count($comments_infos) > 0) {
  215. foreach ($comments_infos as $k => $value) {
  216. $value->dream_name = $dream->dream;
  217. $value->dream_about = $dream->about;
  218. $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  219. $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  220. $value->reviewer = $value->CommentUser->nickname;
  221. $value->reviewer_pic = $value->CommentUser->pic;
  222. }
  223. }
  224. }
  225. return $this->api(compact('comments_infos'));
  226. }
  227. /**
  228. * @api {post} /api/my/my_reply 我的回复(myReply)
  229. * @apiDescription 我的回复(recharge)
  230. * @apiGroup My
  231. * @apiParam {text} content 回复内容
  232. * @apiParam {int} comment_id 评论ID
  233. * @apiPermission Passport
  234. * @apiVersion 0.1.0
  235. * @apiSuccessExample {json} Success-Response:
  236. * {
  237. * "status": true,
  238. * "status_code": 0,
  239. * "message": "",
  240. * "data": ""
  241. *}
  242. * HTTP/1.1 200 OK
  243. * @apiErrorExample {json} Error-Response:
  244. * {
  245. * "status": false,
  246. * "status_code": 1000,
  247. * "message": "输入不正确",
  248. * "data": null
  249. *}
  250. *{
  251. * "status": false,
  252. * "status_code": 600,
  253. * "message": "保存用户数据失败",
  254. * "data": null
  255. *}
  256. * HTTP/1.1 400 Bad Request
  257. */
  258. public function myReply(Request $request)
  259. {
  260. $user = $this->getUser();
  261. $data = $request->except('_token');
  262. $data['user_id'] = $user->id;
  263. if (!$request->content)
  264. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS);
  265. $ok = ReplyCommentsInfo::create($data);
  266. if ($ok) {
  267. return $this->api('');
  268. }else{
  269. return $this->error(ErrorCode::SAVE_USER_FAILED);
  270. }
  271. }
  272. /**
  273. * @api {get} /api/my/dream 我的梦想(dream)
  274. * @apiDescription 我的梦想(recharge)
  275. * @apiGroup My
  276. * @apiPermission Passport
  277. * @apiVersion 0.1.0
  278. * @apiSuccessExample {json} Success-Response:
  279. * {
  280. * "status": true,
  281. * "status_code": 0,
  282. * "message": "",
  283. * "data": {
  284. * "dreams": [
  285. * {
  286. * "id": 2,
  287. * "dream": "去旅游去旅游2",
  288. * "about": "欧冠胡234",
  289. * "dream_pic": "aaaaa",
  290. * "progress": 0, 进度
  291. * ]
  292. * }
  293. * }
  294. * HTTP/1.1 200 OK
  295. * @apiErrorExample {json} Error-Response:
  296. * HTTP/1.1 400 Bad Request
  297. */
  298. public function dream()
  299. {
  300. $user = $this->getUser();
  301. // 梦想
  302. $dreams = $user->UserDream;
  303. if (count($dreams) == 0)
  304. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  305. foreach ($dreams as $dream){
  306. $dream->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  307. $dream->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  308. }
  309. return $this->api(compact('dreams'));
  310. }
  311. /**
  312. * @api {get} /api/my/collection 我的收藏(collection)
  313. * @apiDescription 我的收藏(recharge)
  314. * @apiGroup My
  315. * @apiPermission Passport
  316. * @apiVersion 0.1.0
  317. * @apiSuccessExample {json} Success-Response:
  318. * HTTP/1.1 200 OK
  319. * @apiErrorExample {json} Error-Response:
  320. * HTTP/1.1 400 Bad Request
  321. */
  322. public function collection()
  323. {
  324. $user = $this->getUser();
  325. return $this->api(compact('user'));
  326. }
  327. /**
  328. * @api {get} /api/my/setting 设置(setting)
  329. * @apiDescription 设置(setting)
  330. * @apiGroup My
  331. * @apiPermission Passport
  332. * @apiVersion 0.1.0
  333. * @apiSuccessExample {json} Success-Response:
  334. * HTTP/1.1 200 OK
  335. * @apiErrorExample {json} Error-Response:
  336. * HTTP/1.1 400 Bad Request
  337. */
  338. public function setting()
  339. {
  340. $user = $this->getUser();
  341. return $this->api(compact('user'));
  342. }
  343. /**
  344. * @api {post} /api/my/add_dream 发布梦想(addDream)
  345. * @apiDescription 发布梦想(addDream)
  346. * @apiParam {string} pic 梦想图片 数组
  347. * @apiParam {string} videos 梦想视频
  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. $videos = $request->videos;
  399. if (empty($arr) && empty($videos)) return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
  400. $ok = UserDream::create($data1);
  401. $arr1 = [];
  402. if ($ok) {
  403. if (is_array($arr)) {
  404. foreach ($arr as $k => $v){
  405. $arr1[] = [
  406. 'dream_id'=>$dream_id,
  407. 'pic' => $v,
  408. 'created_at' =>date('Y-m-d H:i:s'),
  409. 'updated_at' =>date('Y-m-d H:i:s'),
  410. ];
  411. }
  412. DreamImages::insert($arr1);
  413. }
  414. return $this->api('');
  415. }else{
  416. DreamInfoModel::destroy($dream_id);
  417. return $this->error(ErrorCode::SAVE_USER_FAILED);
  418. }
  419. }else{
  420. return $this->error(ErrorCode::SAVE_USER_FAILED);
  421. }
  422. }
  423. /**
  424. * @api {get} /api/my/dream_about 梦想介绍(dreamAbout)
  425. * @apiDescription 梦想介绍(dreamAbout)
  426. * @apiGroup My
  427. * @apiPermission Passport
  428. * @apiVersion 0.1.0
  429. * @apiSuccessExample {json} Success-Response:
  430. * HTTP/1.1 200 OK
  431. * @apiErrorExample {json} Error-Response:
  432. * HTTP/1.1 400 Bad Request
  433. */
  434. public function dreamAbout()
  435. {
  436. $user = $this->getUser();
  437. return $this->api(compact('user'));
  438. }
  439. }