MyController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\BaseDictionaryOptionModel;
  4. use App\Models\BaseSettingsModel;
  5. use App\Models\DreamImages;
  6. use App\Models\DreamInfoModel;
  7. use App\Models\ReplyCommentsInfo;
  8. use App\Models\UserDream;
  9. use Illuminate\Http\Request;
  10. use App\Services\Base\ErrorCode;
  11. class MyController extends Controller
  12. {
  13. /**
  14. * @api {get} /api/my/index 个人首页(index)
  15. * @apiDescription 个人首页(index)
  16. * @apiGroup My
  17. * @apiPermission Passport
  18. * @apiSuccessExample {json} Success-Response:
  19. * HTTP/1.1 200 O* "status": true,
  20. * "status_code": 0,
  21. * "message": "",
  22. * "data": {
  23. * "my_care_num": 4,关注
  24. * "my_fens_num": 3,粉丝
  25. * "my_collection_num": 2,收藏
  26. * "my_dream_num": 1,发帖
  27. * "user": {
  28. * "id": 1,
  29. * "tel": "13880642880",
  30. * "password": "",
  31. * "nickname": "",
  32. * "pic": "",
  33. * "sign": 0,
  34. * "money": 0,余额
  35. * "sex": 1,
  36. * "signture": "",个性签名
  37. * "tall": "",
  38. * "job": "",
  39. * "emotion": 1,
  40. * "address": "",
  41. * "detail_address": "",
  42. * "status": 1,
  43. * "remember_token": "",
  44. * }
  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 {post} /api/my/nickname 修改昵称(nickname)
  119. * @apiDescription 修改昵称(nickname)
  120. * @apiGroup My
  121. * @apiParam {string} nickname 昵称
  122. * @apiPermission Passport
  123. * @apiVersion 0.1.0
  124. * @apiSuccessExample {json} Success-Response:
  125. * HTTP/1.1 200 OK
  126. * {
  127. * " status": true,
  128. * "status_code": 0,
  129. * "message": "",
  130. * "data": ""
  131. *}
  132. * @apiErrorExample {json} Error-Response:
  133. * HTTP/1.1 400 Bad Request
  134. * {
  135. * "status": false,
  136. * "status_code": 600,
  137. * "message": "保存用户数据失败",
  138. * "data": null
  139. * }
  140. */
  141. public function nickname(Request $request)
  142. {
  143. $user = $this->getUser();
  144. $validator = \Validator::make($request->all(),
  145. [
  146. 'nickname' => 'required',
  147. ],
  148. [
  149. 'nickname.required' => '昵称不能为空',
  150. ]
  151. );
  152. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  153. $nickname = $request->nickname;
  154. $user->nickname = $nickname;
  155. $ok = $user->save();
  156. if ($ok) return $this->api('');
  157. return $this->error(ErrorCode::SAVE_USER_FAILED);
  158. }
  159. /**
  160. * @api {post} /api/my/sex 修改性别(sex get or post)
  161. * @apiDescription 修改性别(sex)
  162. * @apiGroup My
  163. * @apiParam {sex} sex 性别
  164. * @apiPermission Passport
  165. * @apiVersion 0.1.0
  166. * @apiSuccessExample {json} Success-Response:
  167. * HTTP/1.1 200 OK
  168. * get
  169. *{
  170. * "status": true,
  171. * "status_code": 0,
  172. * "message": "",
  173. * "data": [
  174. * {
  175. * "value": "0",
  176. * "name": "男"
  177. * },
  178. * {
  179. * "value": "1",
  180. * "name": "女"
  181. * }
  182. * ]
  183. *}
  184. * post
  185. * {
  186. * " status": true,
  187. * "status_code": 0,
  188. * "message": "",
  189. * "data": ""
  190. *}
  191. * @apiErrorExample {json} Error-Response:
  192. * HTTP/1.1 400 Bad Request
  193. * {
  194. * "status": false,
  195. * "status_code": 600,
  196. * "message": "保存用户数据失败",
  197. * "data": null
  198. * }
  199. */
  200. public function sex(Request $request)
  201. {
  202. if ($request->method() == 'GET') {
  203. $data = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  204. where('dictionary_code','sex')->get();
  205. return $this->api($data);
  206. }
  207. $user = $this->getUser();
  208. $validator = \Validator::make($request->all(),
  209. [
  210. 'sex' => 'required',
  211. ],
  212. [
  213. 'sex.required' => '性别不能为空',
  214. ]
  215. );
  216. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  217. $sex = $request->sex;
  218. $user->sex = $sex;
  219. $ok = $user->save();
  220. if ($ok) return $this->api('');
  221. return $this->error(ErrorCode::SAVE_USER_FAILED);
  222. }
  223. /**
  224. * @api {post} /api/my/signture 个性签名(signture)
  225. * @apiDescription 个性签名(signture)
  226. * @apiGroup My
  227. * @apiParam {string} signture 个性签名
  228. * @apiPermission Passport
  229. * @apiVersion 0.1.0
  230. * @apiSuccessExample {json} Success-Response:
  231. * HTTP/1.1 200 OK
  232. * {
  233. * " status": true,
  234. * "status_code": 0,
  235. * "message": "",
  236. * "data": ""
  237. *}
  238. * @apiErrorExample {json} Error-Response:
  239. * HTTP/1.1 400 Bad Request
  240. * 保存
  241. * {
  242. * "status": false,
  243. * "status_code": 600,
  244. * "message": "保存用户数据失败",
  245. * "data": null
  246. * }
  247. * 提交
  248. * {
  249. * "status": false,
  250. * "status_code": 1000,
  251. * "message": "个性签名不能为空",
  252. * "data": null
  253. *}
  254. */
  255. public function signture(Request $request)
  256. {
  257. $user = $this->getUser();
  258. $validator = \Validator::make($request->all(),
  259. [
  260. 'signture' => 'required',
  261. ],
  262. [
  263. 'signture.required' => '个性签名不能为空',
  264. ]
  265. );
  266. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  267. $signture = $request->signture;
  268. $user->signture = $signture;
  269. $ok = $user->save();
  270. if ($ok) return $this->api('');
  271. return $this->error(ErrorCode::SAVE_USER_FAILED);
  272. }
  273. /**
  274. * @api {post} /api/my/tel 修改手机号(tel)
  275. * @apiDescription 修改手机号(tel)
  276. * @apiGroup My
  277. * @apiParam {int} tel 修改手机号
  278. * @apiPermission Passport
  279. * @apiVersion 0.1.0
  280. * @apiSuccessExample {json} Success-Response:
  281. * HTTP/1.1 200 OK
  282. * {
  283. * " status": true,
  284. * "status_code": 0,
  285. * "message": "",
  286. * "data": ""
  287. *}
  288. * @apiErrorExample {json} Error-Response:
  289. * HTTP/1.1 400 Bad Request
  290. * {
  291. * "status": false,
  292. * "status_code": 600,
  293. * "message": "保存用户数据失败",
  294. * "data": null
  295. * }
  296. */
  297. public function tel(Request $request)
  298. {
  299. $user = $this->getUser();
  300. $validator = \Validator::make($request->all(),
  301. [
  302. 'tel' => 'required|regex:/^1[34578][0-9]{9}$/',
  303. ],
  304. [
  305. 'tel.required' => '手机号不能为空',
  306. 'tel.regex' => '手机号格式不正确',
  307. ]
  308. );
  309. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  310. $tel = $request->tel;
  311. $user->tel = $tel;
  312. $ok = $user->save();
  313. if ($ok) return $this->api('');
  314. return $this->error(ErrorCode::SAVE_USER_FAILED);
  315. }
  316. /**
  317. * @api {post} /api/my/job 工作类型(job get or post)
  318. * @apiDescription 工作类型(job)
  319. * @apiGroup My
  320. * @apiParam {string} job 工作类型
  321. * @apiPermission Passport
  322. * @apiVersion 0.1.0
  323. * @apiSuccessExample {json} Success-Response:
  324. * HTTP/1.1 200 OK
  325. * {
  326. * " status": true,
  327. * "status_code": 0,
  328. * "message": "",
  329. * "data": ""
  330. *}
  331. * @apiErrorExample {json} Error-Response:
  332. * HTTP/1.1 400 Bad Request
  333. * {
  334. * "status": false,
  335. * "status_code": 600,
  336. * "message": "保存用户数据失败",
  337. * "data": null
  338. * }
  339. */
  340. public function job(Request $request)
  341. {
  342. if ($request->method() == 'GET') {
  343. $data = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  344. where('dictionary_code','job')->get();
  345. return $this->api($data);
  346. }
  347. $user = $this->getUser();
  348. $validator = \Validator::make($request->all(),
  349. [
  350. 'job' => 'required',
  351. ],
  352. [
  353. 'job.required' => '工作类型不能为空',
  354. ]
  355. );
  356. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  357. $job = $request->job;
  358. $user->job = $job;
  359. $ok = $user->save();
  360. if ($ok) return $this->api('');
  361. return $this->error(ErrorCode::SAVE_USER_FAILED);
  362. }
  363. /**
  364. * @api {post} /api/my/job 情感状态(emotion get or post)
  365. * @apiDescription 情感状态(job)
  366. * @apiGroup My
  367. * @apiParam {int} emotion 情感状态
  368. * @apiPermission Passport
  369. * @apiVersion 0.1.0
  370. * @apiSuccessExample {json} Success-Response:
  371. * HTTP/1.1 200 OK
  372. * {
  373. * " status": true,
  374. * "status_code": 0,
  375. * "message": "",
  376. * "data": ""
  377. *}
  378. * @apiErrorExample {json} Error-Response:
  379. * HTTP/1.1 400 Bad Request
  380. * {
  381. * "status": false,
  382. * "status_code": 600,
  383. * "message": "保存用户数据失败",
  384. * "data": null
  385. * }
  386. */
  387. public function emotion(Request $request)
  388. {
  389. if ($request->method() == 'GET') {
  390. $data = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  391. where('dictionary_code','emotion')->get();
  392. return $this->api($data);
  393. }
  394. $user = $this->getUser();
  395. $validator = \Validator::make($request->all(),
  396. [
  397. 'emotion' => 'required',
  398. ],
  399. [
  400. 'emotion.required' => '情感状态不能为空',
  401. ]
  402. );
  403. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  404. $emotion = $request->emotion;
  405. $user->emotion = $emotion;
  406. $ok = $user->save();
  407. if ($ok) return $this->api('');
  408. return $this->error(ErrorCode::SAVE_USER_FAILED);
  409. }
  410. /**
  411. * @api {post} /api/my/tall 身高
  412. * @apiDescription 身高
  413. * @apiGroup My
  414. * @apiParam {int} tall 身高
  415. * @apiPermission Passport
  416. * @apiVersion 0.1.0
  417. * @apiSuccessExample {json} Success-Response:
  418. * HTTP/1.1 200 OK
  419. * {
  420. * " status": true,
  421. * "status_code": 0,
  422. * "message": "",
  423. * "data": ""
  424. *}
  425. * @apiErrorExample {json} Error-Response:
  426. * HTTP/1.1 400 Bad Request
  427. * {
  428. * "status": false,
  429. * "status_code": 600,
  430. * "message": "保存用户数据失败",
  431. * "data": null
  432. * }
  433. */
  434. public function tall(Request $request)
  435. {
  436. $user = $this->getUser();
  437. $validator = \Validator::make($request->all(),
  438. [
  439. 'tall' => 'required|integer',
  440. ],
  441. [
  442. 'tall.required' => '身高不能为空',
  443. 'tall.integer' => '身高只能填写数字',
  444. ]
  445. );
  446. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  447. $tall = $request->tall;
  448. $user->tall = $tall;
  449. $ok = $user->save();
  450. if ($ok) return $this->api('');
  451. return $this->error(ErrorCode::SAVE_USER_FAILED);
  452. }
  453. /**
  454. * @api {get} /api/my/recharge 充值(recharge)
  455. * @apiDescription 充值(recharge)
  456. * @apiGroup My
  457. * @apiPermission Passport
  458. * @apiVersion 0.1.0
  459. * @apiSuccessExample {json} Success-Response:
  460. * HTTP/1.1 200 OK
  461. * @apiErrorExample {json} Error-Response:
  462. * HTTP/1.1 400 Bad Request
  463. */
  464. public function recharge()
  465. {
  466. $user = $this->getUser();
  467. return $this->api(compact('user'));
  468. }
  469. /**
  470. * @api {get} /api/my/system_info 系统消息(systemInfo)
  471. * @apiDescription 系统消息(systemInfo)
  472. * @apiGroup My
  473. * @apiPermission Passport
  474. * @apiVersion 0.1.0
  475. * @apiSuccessExample {json} Success-Response:
  476. * HTTP/1.1 200 OK
  477. *{
  478. * "status": true,
  479. * "status_code": 0,
  480. * "message": "",
  481. * "data": {
  482. * "data": [
  483. * {
  484. * "nickname": "",充值人
  485. * "pivot": {
  486. * "coin": 0 捐赠梦想币数量
  487. * }
  488. * }
  489. *}
  490. * @apiErrorExample {json} Error-Response:
  491. * HTTP/1.1 400 Bad Request
  492. * {
  493. * "status": true,
  494. * "status_code": 0,
  495. * "message": "",
  496. * "data": {
  497. * "data": []
  498. * }
  499. *}
  500. */
  501. public function systemInfo()
  502. {
  503. $user = $this->getUser();
  504. $data = $user->SystemInfo;
  505. return $this->api(compact('data'));
  506. }
  507. /**
  508. * @api {get} /api/my/reply_my 回复我的(replyMy)
  509. * @apiDescription 回复我的(replyMy)
  510. * @apiGroup My
  511. * @apiPermission Passport
  512. * @apiVersion 0.1.0
  513. * @apiSuccessExample {json} Success-Response:
  514. * HTTP/1.1 200 OK
  515. *
  516. * {
  517. * "status": true,
  518. * "status_code": 0,
  519. * "message": "",
  520. * "data": {
  521. * "comments_infos": [
  522. * {
  523. * "id": 1,
  524. * "dream_id": 2,
  525. * "user_id": 2,
  526. * "level": 2,
  527. * "content": "啊哈", 评论内容
  528. * "created_at": null, 评论时间
  529. * "updated_at": null,
  530. * "deleted_at": null,
  531. * "dream_name": "去旅游去旅游2", 梦想介绍
  532. * "dream_pic": "aaaaa", 梦想图片
  533. * "progress": 0, 进度
  534. * "reviewer": "22222", 评论者
  535. * "reviewer_pic": "22222pic", 评论者头像
  536. * }
  537. * ]
  538. * }
  539. * }
  540. * @apiErrorExample {json} Error-Response:
  541. * HTTP/1.1 400 Bad Request
  542. */
  543. public function replyMy()
  544. {
  545. $user = $this->getUser();
  546. // 梦想
  547. $dreams = $user->UserDream;
  548. if (count($dreams) == 0)
  549. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  550. foreach ($dreams as $dream){
  551. $comments_infos = $dream->DreamInfo;
  552. if (count($comments_infos) > 0) {
  553. foreach ($comments_infos as $k => $value) {
  554. $value->dream_name = $dream->dream;
  555. $value->dream_about = $dream->about;
  556. $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  557. $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  558. $value->reviewer = $value->CommentUser->nickname;
  559. $value->reviewer_pic = $value->CommentUser->pic;
  560. }
  561. }
  562. }
  563. return $this->api(compact('comments_infos'));
  564. }
  565. /**
  566. * @api {post} /api/my/my_reply 我的回复(myReply)
  567. * @apiDescription 我的回复(recharge)
  568. * @apiGroup My
  569. * @apiParam {text} content 回复内容
  570. * @apiParam {int} comment_id 评论ID
  571. * @apiPermission Passport
  572. * @apiVersion 0.1.0
  573. * @apiSuccessExample {json} Success-Response:
  574. * {
  575. * "status": true,
  576. * "status_code": 0,
  577. * "message": "",
  578. * "data": ""
  579. *}
  580. * HTTP/1.1 200 OK
  581. * @apiErrorExample {json} Error-Response:
  582. * {
  583. * "status": false,
  584. * "status_code": 1000,
  585. * "message": "输入不正确",
  586. * "data": null
  587. *}
  588. *{
  589. * "status": false,
  590. * "status_code": 600,
  591. * "message": "保存用户数据失败",
  592. * "data": null
  593. *}
  594. * HTTP/1.1 400 Bad Request
  595. */
  596. public function myReply(Request $request)
  597. {
  598. $user = $this->getUser();
  599. $data = $request->except('_token');
  600. $data['user_id'] = $user->id;
  601. if (!$request->content)
  602. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS);
  603. $ok = ReplyCommentsInfo::create($data);
  604. if ($ok) {
  605. return $this->api('');
  606. }else{
  607. return $this->error(ErrorCode::SAVE_USER_FAILED);
  608. }
  609. }
  610. /**
  611. * @api {get} /api/my/dream 我的梦想(dream)
  612. * @apiDescription 我的梦想(recharge)
  613. * @apiGroup My
  614. * @apiPermission Passport
  615. * @apiVersion 0.1.0
  616. * @apiSuccessExample {json} Success-Response:
  617. * {
  618. * "status": true,
  619. * "status_code": 0,
  620. * "message": "",
  621. * "data": {
  622. * "dreams": [
  623. * {
  624. * "id": 2,
  625. * "dream": "去旅游去旅游2",
  626. * "about": "欧冠胡234",
  627. * "dream_pic": "aaaaa",
  628. * "progress": 0, 进度
  629. * ]
  630. * }
  631. * }
  632. * HTTP/1.1 200 OK
  633. * @apiErrorExample {json} Error-Response:
  634. * HTTP/1.1 400 Bad Request
  635. */
  636. public function dream()
  637. {
  638. $user = $this->getUser();
  639. // 梦想
  640. $dreams = $user->UserDream;
  641. if (count($dreams) == 0)
  642. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  643. foreach ($dreams as $dream){
  644. $dream->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  645. $dream->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  646. }
  647. return $this->api(compact('dreams'));
  648. }
  649. /**
  650. * @api {get} /api/my/collection 我的收藏(collection)
  651. * @apiDescription 我的收藏(recharge)
  652. * @apiGroup My
  653. * @apiPermission Passport
  654. * @apiVersion 0.1.0
  655. * @apiSuccessExample {json} Success-Response:
  656. * HTTP/1.1 200 OK
  657. * @apiErrorExample {json} Error-Response:
  658. * HTTP/1.1 400 Bad Request
  659. */
  660. public function collection()
  661. {
  662. $user = $this->getUser();
  663. return $this->api(compact('user'));
  664. }
  665. /**
  666. * @api {get} /api/my/setting 设置(setting)
  667. * @apiDescription 设置(setting)
  668. * @apiGroup My
  669. * @apiPermission Passport
  670. * @apiVersion 0.1.0
  671. * @apiSuccessExample {json} Success-Response:
  672. * HTTP/1.1 200 OK
  673. * @apiErrorExample {json} Error-Response:
  674. * HTTP/1.1 400 Bad Request
  675. */
  676. public function setting()
  677. {
  678. $user = $this->getUser();
  679. return $this->api(compact('user'));
  680. }
  681. /**
  682. * @api {post} /api/my/add_dream 发布梦想(addDream)
  683. * @apiDescription 发布梦想(addDream)
  684. * @apiParam {string} pic 梦想图片 数组
  685. * @apiParam {string} videos 梦想视频
  686. * @apiParam {string} dream 梦想标题
  687. * @apiParam {string} about 梦想介绍
  688. * @apiParam {int} money 梦想币
  689. * @apiParam {int} time 实现时间默认21*3600
  690. * @apiGroup My
  691. * @apiPermission Passport
  692. * @apiVersion 0.1.0
  693. * @apiSuccessExample {json} Success-Response:
  694. * {
  695. * "status": true,
  696. * "status_code": 0,
  697. * "message": "",
  698. * "data": ""
  699. *}
  700. * HTTP/1.1 200 OK
  701. * @apiErrorExample {json} Error-Response:
  702. * {
  703. * "status": false,
  704. * "status_code": 600,
  705. * "message": "保存用户数据失败",
  706. * "data": null
  707. * }
  708. * HTTP/1.1 400 Bad Request
  709. */
  710. public function addDream(Request $request)
  711. {
  712. $user = $this->getUser();
  713. $validator = \Validator::make($request->all(),
  714. [
  715. 'dream' => 'required',
  716. 'about' => 'required',
  717. 'money' => 'required|integer',
  718. 'time' => 'required|integer',
  719. ],
  720. [
  721. 'dream.required' => '梦想标题必填',
  722. 'about.required' => '梦想介绍必填',
  723. 'money.required' => '梦想币必填',
  724. 'time.required' => '实现时间必填',
  725. 'money.integer' => '梦想币必须是正整数',
  726. 'time.integer' => '实现时间必须是正整数',
  727. ]
  728. );
  729. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  730. $data2 = $user->myCareNum;
  731. $care_num = count($data2);
  732. $key = BaseSettingsModel::where('category','paihang')->first();
  733. $a = $key ->key;
  734. $b = $key ->value;
  735. $t = 21*3600 / 60;
  736. $data = $request->except('_token','pic');
  737. $data['score'] = (log($care_num) + ($a/$t) + $b)*100000000 ;
  738. $data['created_at'] = date('Y-m-d H:i:s');
  739. $data['updated_at'] = date('Y-m-d H:i:s');
  740. $dream_id = DreamInfoModel::insertGetId($data);
  741. if ($dream_id) {
  742. $data1['dream_id'] = $dream_id;
  743. $data1['user_id'] = $user->id;
  744. $data1['created_at'] = date('Y-m-d H:i:s');
  745. $data1['updated_at'] = date('Y-m-d H:i:s');
  746. $arr = $request->pic;
  747. $videos = $request->videos;
  748. if (empty($arr) && empty($videos)) return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
  749. $ok = UserDream::create($data1);
  750. $arr1 = [];
  751. if ($ok) {
  752. if (is_array($arr)) {
  753. foreach ($arr as $k => $v){
  754. $arr1[] = [
  755. 'dream_id'=>$dream_id,
  756. 'pic' => $v,
  757. 'created_at' =>date('Y-m-d H:i:s'),
  758. 'updated_at' =>date('Y-m-d H:i:s'),
  759. ];
  760. }
  761. DreamImages::insert($arr1);
  762. }
  763. return $this->api('');
  764. }else{
  765. DreamInfoModel::destroy($dream_id);
  766. return $this->error(ErrorCode::SAVE_USER_FAILED);
  767. }
  768. }else{
  769. return $this->error(ErrorCode::SAVE_USER_FAILED);
  770. }
  771. }
  772. /**
  773. * @api {get} /api/my/dream_about 梦想介绍(dreamAbout)
  774. * @apiDescription 梦想介绍(dreamAbout)
  775. * @apiGroup My
  776. * @apiPermission Passport
  777. * @apiVersion 0.1.0
  778. * @apiSuccessExample {json} Success-Response:
  779. * HTTP/1.1 200 OK
  780. * @apiErrorExample {json} Error-Response:
  781. * HTTP/1.1 400 Bad Request
  782. */
  783. public function dreamAbout()
  784. {
  785. $user = $this->getUser();
  786. return $this->api(compact('user'));
  787. }
  788. }