MyController.php 12 KB

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