MyController.php 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AccountLog;
  4. use App\Models\BaseDictionaryOptionModel;
  5. use App\Models\BaseSettingsModel;
  6. use App\Models\CommentInfoModel;
  7. use App\Models\DreamInfoModel;
  8. use App\Models\SearchInfoModel;
  9. use App\Models\Suggest;
  10. use App\Models\SystemInfoModel;
  11. use App\Models\UserBank;
  12. use App\Models\UserCareDream;
  13. use App\Models\UserCashOut;
  14. use App\Models\UserInfoModel;
  15. use Illuminate\Http\Request;
  16. use App\Services\Base\ErrorCode;
  17. class MyController extends Controller
  18. {
  19. /**
  20. * @api {get} /api/my/show 个人首页
  21. * @apiDescription 个人首页
  22. * @apiGroup My
  23. * @apiPermission Passport
  24. * @apiSuccessExample {json} Success-Response:
  25. * HTTP/1.1 200 O* "status": true,
  26. *{
  27. * "status": true,
  28. * "status_code": 0,
  29. * "message": "",
  30. * "data": {
  31. * "id": 1,
  32. * "phone": "13880642880",
  33. * "nickname": "name1",
  34. * "avatar": "https://tims%2Fitem%225_kzrcM.thumb.224_0.jpeg",
  35. * "birthday": "2000-06-21",
  36. * "sign": 0,
  37. * "money": 0,
  38. * "coin": 1300,
  39. * "sex": 1,
  40. * "signture": "",
  41. * "height": 170,
  42. * "work": "",
  43. * "emotion": 1,
  44. * "address": "",
  45. * "city": "",
  46. * "detail_address": "",
  47. * "status": 1,
  48. * "wechat": "",
  49. * "weibo": "",
  50. * "remember_token": "",
  51. * "created_at": "2017-06-25 10:27:08",
  52. * "updated_at": "2017-06-25 15:20:11",
  53. * "deleted_at": null,
  54. * "care_dreams_number": 2,
  55. * "fans_number": 0,
  56. * "collection_number": 0,
  57. * "interaction_number": 0,
  58. * }
  59. *}
  60. * @apiErrorExample {json} Error-Response:
  61. * HTTP/1.1 400 Bad Request
  62. *{
  63. * "status": true,
  64. * "status_code": 0,
  65. * "message": "",
  66. * "data": {
  67. * "user": null
  68. * }
  69. *}
  70. */
  71. public function show()
  72. {
  73. $user = $this->getUser();
  74. /*
  75. * 我的关注人数,我的粉丝,收藏
  76. * 点赞?徽章?
  77. * */
  78. $care_num = $user->careDreams;
  79. $user->care_dreams_number = count($care_num);
  80. $fens = UserCareDream::where('dream_user_id',$user->id)->get();
  81. $user->fans_number = count($fens);
  82. $collection = $user->myCollection;
  83. $user->collection_number = count($collection);
  84. $interaction_infos = $user->allInteraction;
  85. $user->interaction_number = count($interaction_infos);
  86. return $this->api($user);
  87. }
  88. /**
  89. * @api {get} /api/my/edit 修改个人信息
  90. * @apiDescription 修改个人信息
  91. * @apiGroup My
  92. * @apiPermission Passport
  93. * @apiVersion 0.1.0
  94. * @apiSuccessExample {json} Success-Response:
  95. * HTTP/1.1 200 OK
  96. *{
  97. * "status": true,
  98. * "status_code": 0,
  99. * "message": "",
  100. "data": {
  101. "emotion": [
  102. {
  103. "value": "1",
  104. "name": "未婚"
  105. },
  106. {
  107. "value": "2",
  108. "name": "已婚"
  109. },
  110. {
  111. "value": "3",
  112. "name": "离异"
  113. }
  114. ],
  115. "sex": [
  116. {
  117. "value": "0",
  118. "name": "男"
  119. },
  120. {
  121. "value": "1",
  122. "name": "女"
  123. }
  124. ]
  125. }
  126. * }
  127. * @apiErrorExample {json} Error-Response:
  128. * HTTP/1.1 400 Bad Request
  129. * {
  130. * "status": false,
  131. * "status_code": 1500,
  132. * "message": "会员不存在",
  133. * "data": null
  134. * }
  135. */
  136. public function edit()
  137. {
  138. $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  139. where('dictionary_code','sex')->get();
  140. $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  141. where('dictionary_code','emotion')->get();
  142. return $this->api(compact('emotion','sex'));
  143. }
  144. /**
  145. * @api {post} /api/my/update 保存个人信息
  146. * @apiDescription 保存个人信息
  147. * @apiParam {string} pic 头像
  148. * @apiParam {int} sex 性别
  149. * @apiParam {string} signture 个性签名
  150. * @apiParam {int} emotion 情感状态
  151. * @apiParam {string} work 职业
  152. * @apiParam {int} height 身高
  153. * @apiGroup My
  154. * @apiPermission Passport
  155. * @apiVersion 0.1.0
  156. * @apiSuccessExample {json} Success-Response:
  157. * HTTP/1.1 200 OK
  158. *{
  159. * "status": true,
  160. * "status_code": 0,
  161. * "message": "",
  162. * "data": ""
  163. *}
  164. * @apiErrorExample {json} Error-Response:
  165. * HTTP/1.1 400 Bad Request
  166. *{
  167. * "status": false,
  168. * "status_code": 600,
  169. * "message": "保存用户数据失败",
  170. * "data": null
  171. * }
  172. */
  173. public function update(Request $request)
  174. {
  175. $user = $this->getUser();
  176. $data = $request->except('_token');
  177. $ok = $user->update($data);
  178. if ($ok == true) {
  179. return $this->api('');
  180. }else{
  181. return $this->error(ErrorCode::SAVE_USER_FAILED);
  182. }
  183. }
  184. /**
  185. * @api {post} /api/my/recharge 充值
  186. * @apiDescription 充值
  187. * @apiGroup My
  188. * @apiParam {int} coin 充值金额
  189. * @apiPermission Passport
  190. * @apiVersion 0.1.0
  191. * @apiSuccessExample {json} Success-Response:
  192. * HTTP/1.1 200 OK
  193. * @apiErrorExample {json} Error-Response:
  194. * HTTP/1.1 400 Bad Request
  195. */
  196. public function recharge(Request $request)
  197. {
  198. $validator = \Validator::make($request->all(),
  199. [
  200. 'coin' => 'required|integer',
  201. ],
  202. [
  203. 'coin.required' => '请填写金额',
  204. 'coin.integer' => '请输入整数',
  205. ]
  206. );
  207. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  208. $user = $this->getUser();
  209. $user->coin += $request->coin;
  210. $user->save();
  211. return $this->api('');
  212. }
  213. /**
  214. * @api {get} /api/my/reply 回复我的
  215. * @apiDescription 回复我的
  216. * @apiGroup My
  217. * @apiPermission Passport
  218. * @apiVersion 0.1.0
  219. * @apiSuccessExample {json} Success-Response:
  220. * HTTP/1.1 200 OK
  221. *{
  222. * "status": true,
  223. * "status_code": 0,
  224. * "message": "",
  225. * "data": [
  226. * {
  227. * ....
  228. * }
  229. * ]
  230. * @apiErrorExample {json} Error-Response:
  231. * HTTP/1.1 400 Bad Request
  232. */
  233. public function reply()
  234. {
  235. $user = $this->getUser();
  236. $data = CommentInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
  237. foreach ($data as $item){ //访问接口 标记已读
  238. $item->update(['is_read'=>1]);
  239. }
  240. return $this->api($data);
  241. } /**
  242. * @api {get} /api/my/letter 私信
  243. * @apiDescription 私信
  244. * @apiGroup My
  245. * @apiPermission Passport
  246. * @apiVersion 0.1.0
  247. * @apiSuccessExample {json} Success-Response:
  248. * HTTP/1.1 200 OK
  249. *{
  250. * "status": true,
  251. * "status_code": 0,
  252. * "message": "",
  253. * "data": [
  254. * {
  255. * ....
  256. * }
  257. * ]
  258. * @apiErrorExample {json} Error-Response:
  259. * HTTP/1.1 400 Bad Request
  260. */
  261. public function letter()
  262. {
  263. $user = $this->getUser();
  264. $data = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  265. foreach ($data as $item){ //访问接口 标记已读
  266. $item->update(['is_read'=>1]);
  267. }
  268. return $this->api($data);
  269. } /**
  270. * @api {get} /api/my/system_info 系统消息
  271. * @apiDescription 系统消息
  272. * @apiGroup My
  273. * @apiPermission Passport
  274. * @apiVersion 0.1.0
  275. * @apiSuccessExample {json} Success-Response:
  276. * HTTP/1.1 200 OK
  277. *{
  278. * "status": true,
  279. * "status_code": 0,
  280. * "message": "",
  281. * "data": [
  282. * {
  283. * ....
  284. * }
  285. * ]
  286. * @apiErrorExample {json} Error-Response:
  287. * HTTP/1.1 400 Bad Request
  288. */
  289. public function systemInfo()
  290. {
  291. $user = $this->getUser();
  292. $data = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  293. foreach ($data as $item){ //访问接口 标记已读
  294. $item->update(['is_read'=>1]);
  295. }
  296. return $this->api($data);
  297. }
  298. /**
  299. * @api {get} /api/my/info 消息中心
  300. * @apiDescription 消息中心
  301. * @apiGroup My
  302. * @apiPermission Passport
  303. * @apiVersion 0.1.0
  304. * @apiSuccessExample {json} Success-Response:
  305. * HTTP/1.1 200 OK
  306. *{
  307. * "status": true,
  308. * "status_code": 0,
  309. * "message": "",
  310. * "data": {
  311. * "systemInfo": {
  312. * "number": 3,
  313. * "is_read": 3
  314. * },
  315. * "letter": {
  316. * "number": 0,
  317. * "is_read": 0
  318. * },
  319. * "reply": {
  320. * "number": 3,
  321. * "is_read": 3
  322. * }
  323. * }
  324. *}
  325. * @apiErrorExample {json} Error-Response:
  326. * HTTP/1.1 400 Bad Request
  327. */
  328. public function info()
  329. {
  330. $user = $this->getUser();
  331. $systemInfo1 = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  332. $systemInfo2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  333. ->whereNull('to_user_id')->orderBy('id','desc')->get();
  334. $letter1 = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  335. $letter2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  336. ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  337. $comments1 = CommentInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
  338. $comments2 = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
  339. $arr = [];
  340. $arr['systemInfo']['number'] = count($systemInfo1) ;
  341. $arr['systemInfo']['is_read'] = count($systemInfo2) ;
  342. $arr['letter']['number'] = count($letter1) ;
  343. $arr['letter']['is_read'] = count($letter2) ;
  344. $arr['reply']['number'] = count($comments1) ;
  345. $arr['reply']['is_read'] = count($comments2) ;
  346. return $this->api($arr);
  347. }
  348. /**
  349. * @api {get} /api/my/read 设为已读
  350. * @apiDescription 设为已读
  351. * @apiGroup My
  352. * @apiPermission Passport
  353. * @apiVersion 0.1.0
  354. * @apiSuccessExample {json} Success-Response:
  355. * HTTP/1.1 200 OK
  356. *{
  357. * "status": true,
  358. * "status_code": 0,
  359. * "message": "",
  360. * "data": ""
  361. *}
  362. * @apiErrorExample {json} Error-Response:
  363. * HTTP/1.1 400 Bad Request
  364. * {
  365. * "status": false,
  366. * "status_code": 700,
  367. * "message": "操作失败",
  368. * "data": null
  369. *}
  370. */
  371. public function read()
  372. {
  373. $user = $this->getUser();
  374. dd($user);
  375. $id = $user->id;
  376. $system_infos = SystemInfoModel::where(function ($query) use($id){
  377. $query->where('user_id',$id)->where('is_read','0');
  378. })->orWhere(function ($query) use($id){
  379. $query->where('to_user_id',$id)->where('is_read','0');
  380. })->orderBy('id','desc')->get();
  381. $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
  382. foreach ($system_infos as $system_info){
  383. $system_info->update(['is_read'=>1]);
  384. }
  385. foreach ($comments as $comment){
  386. $comment->update(['is_read'=>1]);
  387. }
  388. if (count($system_infos) > 0 || count($comments) > 0) {
  389. return $this->api('');
  390. }else{
  391. return $this->error(ErrorCode::OPERATION_FAILED);
  392. }
  393. }
  394. /**
  395. * @api {get} /api/my/pay/article 支付说明
  396. * @apiDescription 支付说明
  397. * @apiGroup My
  398. * @apiPermission Passport
  399. * @apiVersion 0.1.0
  400. * @apiSuccessExample {json} Success-Response:
  401. * HTTP/1.1 200 OK
  402. *{
  403. * "status": true,
  404. * "status_code": 0,
  405. * "message": "",
  406. *"data": {
  407. * "key": "23453423453", 标题
  408. * "value": "<p><span style=\"color: rgb(255, 0, 0);\">42352345234534是大法官地方<
  409. * img src=\"/ueditor/php/upload/image/20170815/1502779635.jpg\" title=\"1502779635.jpg\" alt=\"a1.jpg\"/>234534</span><
  410. * br/></p>", 内容
  411. *}
  412. * ]
  413. *}
  414. * @apiErrorExample {json} Error-Response:
  415. * HTTP/1.1 400 Bad Request
  416. */
  417. public function payArticle()
  418. {
  419. $data = BaseSettingsModel::where('category','pay_article')->first();
  420. return $this->api($data);
  421. }
  422. /**
  423. * @api {post} /api/my/cash 提现
  424. * @apiDescription 提现
  425. * @apiGroup My
  426. * @apiParam {int} data[bank_id] 银行卡号id
  427. * @apiParam {int} data[cash] 提现金额
  428. * @apiPermission Passport
  429. * @apiVersion 0.1.0
  430. * @apiSuccessExample {json} Success-Response:
  431. * HTTP/1.1 200 OK
  432. *{
  433. * "status": false,
  434. * "status_code": 1413,
  435. * "message": "系统审核中",
  436. * "data": null
  437. *}
  438. * @apiErrorExample {json} Error-Response:
  439. *{
  440. * "status": false,
  441. * "status_code": 700,
  442. * "message": "操作失败",
  443. * "data": null
  444. *}
  445. */
  446. public function cash(Request $request)
  447. {
  448. $data = $request->data;
  449. $user = $this->getUser();
  450. $validator = \Validator::make($request->all(),
  451. [
  452. 'data.bank_id' => 'required|integer',
  453. 'data.cash' => 'required',
  454. ],
  455. [
  456. 'data.bank_id.required' => '请选择提现账号',
  457. 'data.bank_id.integer' => '提现账号不存在',
  458. 'data.cash.required' => '请输入金额',
  459. ]
  460. );
  461. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  462. // $info = [] ;
  463. // $info['from_type'] = '余额';
  464. // $info['from_id'] = $user->id;
  465. // $info['from_name'] = $user->name;
  466. // $info['op'] = '提现';
  467. // $info['from_amount'] = $data['coin'];
  468. // $info['to_type'] = '现金';
  469. // $info['to_id'] = $user->id;
  470. // $info['to_name'] = $data['account']; //账号
  471. // $info['note'] = $data['type'].$data['name'];
  472. // $ok = AccountLog::create($info);
  473. $data['user_id'] = $user->id;
  474. $data['status'] = 0;
  475. $ok = UserCashOut::create($data);
  476. if ($ok) {
  477. return $this->api(ErrorCode::verify);
  478. }else{
  479. return $this->error(ErrorCode::OPERATION_FAILED);
  480. }
  481. }
  482. // 联系客服
  483. /**
  484. * @api {post} /api/my/suggest 联系客服
  485. * @apiDescription 联系客服
  486. * @apiGroup My
  487. * @apiParam {string} data[content] 内容
  488. * @apiParam {string} data[email] 邮箱
  489. * @apiPermission Passport
  490. * @apiVersion 0.1.0
  491. * @apiSuccessExample {json} Success-Response:
  492. * HTTP/1.1 200 OK
  493. *{
  494. * "status": true,
  495. * "status_code": 0,
  496. * "message": "",
  497. * "data": ""
  498. *}
  499. * @apiErrorExample {json} Error-Response:
  500. *{
  501. * "status": false,
  502. * "status_code": 700,
  503. * "message": "操作失败",
  504. * "data": null
  505. *}
  506. */
  507. public function suggest(Request $request)
  508. {
  509. $data = $request->data;
  510. $user = $this->getUser();
  511. $validator = \Validator::make($request->all(),
  512. [
  513. 'data.content' => 'required',
  514. 'data.email' => 'required|email',
  515. ],
  516. [
  517. 'data.content.required' => '请输入你遇到的问题',
  518. 'data.email.required' => '请输入正确的邮箱地址',
  519. 'data.email.email' => '请输入正确的邮箱地址',
  520. ]
  521. );
  522. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  523. $data['user_id'] = $user->id;
  524. $ok =Suggest::create($data);
  525. if ($ok) {
  526. return $this->api('');
  527. }else{
  528. return $this->error(ErrorCode::OPERATION_FAILED);
  529. }
  530. }
  531. // 回复我的
  532. // public function replyMy()
  533. // {
  534. //
  535. // $user = $this->getUser();
  536. //// 梦想
  537. // $dreams = $user->UserDream;
  538. //
  539. // $data = $user->allInteraction;
  540. // foreach ($data as $item) {
  541. // $item->get_money = $item->dream->get_money;
  542. // $item->money = $item->dream->money;
  543. // }
  544. // dd($data) ;
  545. // if (count($dreams) == 0)
  546. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  547. // $comments_infos = [];
  548. // foreach ($dreams as $dream){
  549. // $comments_info = $dream->DreamInfo;
  550. // if (count($comments_info) > 0) {
  551. // foreach ($comments_info as $k => $value) {
  552. // $value->dream_name = $dream->dream;
  553. // $value->dream_about = $dream->about;
  554. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  555. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  556. // $value->reviewer = $value->CommentUser->nickname;
  557. // $value->reviewer_pic = $value->CommentUser->pic;
  558. // }
  559. // $comments_infos[] = $comments_info;
  560. // }
  561. // }
  562. //
  563. // return $this->api(compact('comments_infos'));
  564. // }
  565. /**
  566. * @api {get} /api/my/dream 我的梦想
  567. * @apiDescription 我的梦想
  568. * @apiGroup My
  569. * @apiPermission Passport
  570. * @apiVersion 0.1.0
  571. * @apiSuccessExample {json} Success-Response:
  572. * HTTP/1.1 200 OK
  573. *{
  574. * "status": true,
  575. * "status_code": 0,
  576. * "message": "",
  577. * "data": [
  578. * {
  579. * "id": 5,
  580. * "user_id": 1,
  581. * "name": "梦想标题1",
  582. * "about": "梦想介绍",
  583. * "coin": 2500,
  584. * "time": 21,
  585. * "get_coin": 0,
  586. * "status": 0,
  587. * "video": null,
  588. * "sign": "",
  589. * "created_at": "2017-06-25 12:45:22",
  590. * "updated_at": "2017-06-25 12:45:22",
  591. * "pic": "https://timgsa.baidu.com/timg?image7b14f12f.jpg",
  592. * },
  593. * ]
  594. *}
  595. * @apiErrorExample {json} Error-Response:
  596. * HTTP/1.1 400 Bad Request
  597. */
  598. public function dream()
  599. {
  600. $user = $this->getUser();
  601. $dreams = $user->dreams;
  602. if (count($dreams) == 0)
  603. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  604. foreach ($dreams as $dream){
  605. $dream->pic = count($dream->img) > 0 ? $dream->img->pic : '';
  606. }
  607. return $this->api($dreams);
  608. }
  609. /**
  610. * @api {get} /api/my/collection 我的收藏
  611. * @apiDescription 我的收藏
  612. * @apiGroup My
  613. * @apiPermission Passport
  614. * @apiParam {string} [keyword] 关键字可选
  615. * @apiVersion 0.1.0
  616. * @apiSuccessExample {json} Success-Response:
  617. * HTTP/1.1 200 OK
  618. *{
  619. * "status": true,
  620. * "status_code": 0,
  621. * "message": "",
  622. * "data": {
  623. * "data": [
  624. * { 梦想详情
  625. * "id": 12,
  626. * "user_id": 2,
  627. * "name": "用户2梦想标题166",
  628. * "about": "用户2梦想介绍666",
  629. * "coin": 2500,
  630. * "time": 21,
  631. * "get_coin": 0,
  632. * "status": 0,
  633. * "video": null,
  634. * "sign": "",
  635. * },
  636. * "img": {
  637. * "title": "",
  638. * "pic": "https://f12f.jpg" 梦想封面图片
  639. * }
  640. * ],
  641. * "users": {
  642. * "2": "https://xxx.jpeg" ID号和头像
  643. * }
  644. * }
  645. *}
  646. * keyword存在
  647. *{
  648. * "status": true,
  649. * "status_code": 0,
  650. * "message": "",
  651. * "data": [
  652. * {
  653. * "id": 2,
  654. * "user_id": 1,
  655. * "dream_id": 12,
  656. * "dream_user_id": 2,
  657. * "interaction_number": 0,
  658. * "created_at": "2017-06-25 13:11:45",
  659. * "updated_at": "2017-06-25 13:11:45",
  660. * "dreams": [ 梦想
  661. * {
  662. * "id": 12,
  663. * "user_id": 2,
  664. * "name": "用户2梦想标题166",
  665. * "about": "用户2梦想介绍666",
  666. * "coin": 2500,
  667. * "end_time": 72000,
  668. * "get_coin": 792,
  669. * "mark": 5484,
  670. * "status": 0,
  671. * "video": "e",
  672. * "score": 158730,
  673. * "sign": "梦想达人",
  674. * "created_at": "2017-06-25 13:10:56",
  675. * "updated_at": "2017-06-28 16:53:39"
  676. * "img": { 图片
  677. * "title": "",
  678. * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  679. * },
  680. * "user": {
  681. *
  682. * }
  683. * }
  684. * ]
  685. * }
  686. * ]
  687. *}
  688. * @apiErrorExample {json} Error-Response:
  689. * HTTP/1.1 400 Bad Request
  690. */
  691. public function collection(Request $request)
  692. {
  693. $user = $this->getUser();
  694. if ($request->keyword) {
  695. $keyword ='%'.$request->keyword.'%';
  696. $data = UserCareDream::where('user_id',$user->id)->
  697. whereHas('dreams',function ($query) use($keyword){
  698. $query->where('end_time','>=',time())->where('name','like',$keyword);
  699. })->with('dreams')->get();
  700. foreach ($data as $item) {
  701. foreach ($item->dreams as $dream) {
  702. $dream->img;
  703. }
  704. }
  705. $this->insertSearchTable($user->id,$request->keyword);
  706. return $this->api($data);
  707. }else{
  708. $dreams = $user->collection;
  709. // $users = [];
  710. foreach ($dreams as $item) {
  711. /* if ($item->pivot->interaction_number > 0) {
  712. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  713. $avatar = $user_info ? $user_info->avatar : '';
  714. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  715. $users[$item->pivot->dream_user_id] = $avatar;
  716. }
  717. }*/
  718. $item->img;
  719. $item->user;
  720. }
  721. return $this->api(compact('dreams'));
  722. }
  723. }
  724. /**
  725. * @api {get} /api/my/miao 关于喵喵
  726. * @apiDescription 关于喵喵
  727. * @apiGroup My
  728. * @apiPermission Passport
  729. * @apiVersion 0.1.0
  730. * @apiSuccessExample {json} Success-Response:
  731. * HTTP/1.1 200 OK
  732. *{
  733. * "status": true,
  734. * "status_code": 0,
  735. * "message": "",
  736. * "data": {
  737. * "key": "2511789", 电话
  738. * "value": "关于喵喵介绍" 关于喵喵
  739. * }
  740. *}
  741. * @apiErrorExample {json} Error-Response:
  742. * HTTP/1.1 400 Bad Request
  743. */
  744. public function aboutMiao()
  745. {
  746. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  747. return $this->api($data);
  748. }
  749. /**
  750. * @api {get} /api/my/care 我关注的用户
  751. * @apiDescription 我关注的用户
  752. * @apiGroup My
  753. * @apiPermission Passport
  754. * @apiVersion 0.1.0
  755. * @apiSuccessExample {json} Success-Response:
  756. * HTTP/1.1 200 OK
  757. *{
  758. * "status": true,
  759. * "status_code": 0,
  760. * "message": "",
  761. * "data":[] or
  762. * "data": [
  763. * {
  764. * "id": 2,
  765. * "phone": "13880642881",
  766. * "nickname": "name2",
  767. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  768. * "birthday": "2000-06-21",
  769. * "sign": 0,
  770. * "money": 0,
  771. * "coin": 800,
  772. * "sex": 1,
  773. * "signture": "我的个性签名2",
  774. * "height": 200,
  775. * "work": "兼职",
  776. * "emotion": 2,
  777. * "address": "370105",
  778. * "city": "成都",
  779. * "detail_address": "",
  780. * "status": 1,
  781. * "wechat": "",
  782. * "weibo": "",
  783. * "remember_token": "",
  784. * "created_at": "2017-06-25 10:42:06",
  785. * "updated_at": "2017-06-30 09:15:04",
  786. * "deleted_at": null,
  787. * }
  788. * ]
  789. *}
  790. * @apiErrorExample {json} Error-Response:
  791. * HTTP/1.1 400 Bad Request
  792. */
  793. public function care()
  794. {
  795. $user = $this->getUser();
  796. $users =$user->UserCareUser;
  797. return $this->api($users);
  798. }
  799. public function insertSearchTable($id,$keyword)
  800. {
  801. $info = SearchInfoModel::where('user_id',$id)->
  802. where('search',trim($keyword))->first();
  803. if (count($info) == 0) {
  804. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  805. }else{
  806. $info->times += 1;
  807. $info->save();
  808. }
  809. }
  810. //我的银行账户
  811. /**
  812. * @api {get} /api/my/bank/list 我的银行账户
  813. * @apiDescription 我的银行账户
  814. * @apiGroup My
  815. * @apiPermission Passport
  816. * @apiVersion 0.1.0
  817. * @apiSuccessExample {json} Success-Response:
  818. * HTTP/1.1 200 OK
  819. *{
  820. * "status": true,
  821. * "status_code": 0,
  822. * "message": "",
  823. * "data":[] or
  824. * "data": [
  825. * {
  826. * "id": 1,
  827. * "user_id": 1,
  828. * "bank_name": "1",
  829. * "bank_number": "1", /账号
  830. * "bank_phone": "1",
  831. * "bank_user": "" 用户名/
  832. * "type": 微信, 微信(支付宝)二维码
  833. * "url": wwww.ddf, 二维码地址
  834. * "is_img": 1,
  835. * }
  836. *]
  837. * @apiErrorExample {json} Error-Response:
  838. * HTTP/1.1 400 Bad Request
  839. */
  840. public function bankList()
  841. {
  842. $user = $this->getUser();
  843. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  844. return $this->api($data);
  845. }
  846. /**
  847. * @api {get} /api/my/bank/account 账户余额
  848. * @apiDescription 账户余额
  849. * @apiGroup My
  850. * @apiPermission Passport
  851. * @apiVersion 0.1.0
  852. * @apiSuccessExample {json} Success-Response:
  853. * HTTP/1.1 200 OK
  854. *{
  855. * "status": true,
  856. * "status_code": 0,
  857. * "message": "",
  858. * "data":[] or
  859. * "data": {
  860. * "coin": 508, 余额
  861. * }
  862. *]
  863. * @apiErrorExample {json} Error-Response:
  864. * HTTP/1.1 400 Bad Request
  865. */
  866. public function account()
  867. {
  868. $user = $this->getUser();
  869. return $this->api($user);
  870. }
  871. // 添加银行卡
  872. /**
  873. * @api {post} /api/my/bank/create 添加银行卡
  874. * @apiDescription 添加银行卡
  875. * @apiGroup My
  876. * @apiParam {string} data[bank_name] 银行名称
  877. * @apiParam {string} data[bank_number] 银行卡号
  878. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  879. * @apiParam {string} data[bank_user] 银行卡用户姓名
  880. * @apiPermission Passport
  881. * @apiVersion 0.1.0
  882. * @apiSuccessExample {json} Success-Response:
  883. * HTTP/1.1 200 OK
  884. *{
  885. * "status": true,
  886. * "status_code": 0,
  887. * "message": "",
  888. * "data": ""
  889. *}
  890. * @apiErrorExample {json} Error-Response:
  891. *{
  892. * "status": false,
  893. * "status_code": 700,
  894. * "message": "操作失败",
  895. * "data": null
  896. *}
  897. */
  898. public function bankCreate(Request $request)
  899. {
  900. $data = $request->data;
  901. $user = $this->getUser();
  902. $validator = \Validator::make($request->all(),
  903. [
  904. 'data.bank_name' => 'required',
  905. 'data.bank_number' => 'required',
  906. 'data.bank_phone' => 'required',
  907. 'data.bank_user' => 'required',
  908. ],
  909. [
  910. 'data.bank_name.required' => '请选择账号类型',
  911. 'data.bank_number.required' => '请输入账号',
  912. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  913. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  914. ]
  915. );
  916. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  917. $data['user_id'] = $user->id;
  918. $ok =UserBank::create($data);
  919. if ($ok) {
  920. return $this->api('');
  921. }else{
  922. return $this->error(ErrorCode::OPERATION_FAILED);
  923. }
  924. } /**
  925. * @api {post} /api/my/bank/img 添加二维码
  926. * @apiDescription 添加二维码
  927. * @apiGroup My
  928. * @apiParam {string} data[type] 类型
  929. * @apiParam {string} data[url] 二维码图片
  930. * @apiPermission Passport
  931. * @apiVersion 0.1.0
  932. * @apiSuccessExample {json} Success-Response:
  933. * HTTP/1.1 200 OK
  934. *{
  935. * "status": true,
  936. * "status_code": 0,
  937. * "message": "",
  938. * "data": ""
  939. *}
  940. * @apiErrorExample {json} Error-Response:
  941. *{
  942. * "status": false,
  943. * "status_code": 700,
  944. * "message": "操作失败",
  945. * "data": null
  946. *}
  947. */
  948. public function bankImgCreate(Request $request)
  949. {
  950. $data = $request->data;
  951. $user = $this->getUser();
  952. $validator = \Validator::make($request->all(),
  953. [
  954. 'data.type' => 'required',
  955. 'data.url' => 'required',
  956. ],
  957. [
  958. 'data.type.required' => '请选择账号类型',
  959. 'data.url.required' => '请上传图片',
  960. ]
  961. );
  962. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  963. $data['user_id'] = $user->id;
  964. $data['bank_user'] = '';
  965. $data['bank_phone'] = '';
  966. $data['bank_number'] = '';
  967. $data['bank_name'] = '';
  968. $data['is_img'] = 1;
  969. $info = UserBank::where('is_img',1)->where('user_id',$user->id)
  970. ->where('type',$data['type'])->first(); //定义为二维码
  971. if (empty($info)) {
  972. $ok =UserBank::create($data);
  973. }else{
  974. $ok = $info->update($data);
  975. }
  976. if ($ok) {
  977. return $this->api('');
  978. }else{
  979. return $this->error(ErrorCode::OPERATION_FAILED);
  980. }
  981. }
  982. /**
  983. * @api {get} /api/my/bank/delete 删除银行卡
  984. * @apiDescription 删除银行卡
  985. * @apiGroup My
  986. * @apiParam {int} id 银行卡id
  987. * @apiPermission Passport
  988. * @apiVersion 0.1.0
  989. * @apiSuccessExample {json} Success-Response:
  990. * HTTP/1.1 200 OK
  991. *{
  992. * "status": true,
  993. * "status_code": 0,
  994. * "message": "",
  995. * "data": ""
  996. *}
  997. * @apiErrorExample {json} Error-Response:
  998. *{
  999. * "status": false,
  1000. * "status_code": 700,
  1001. * "message": "操作失败",
  1002. * "data": null
  1003. *}
  1004. */
  1005. public function bankDelete(Request $request)
  1006. {
  1007. $id = $request->id;
  1008. $validator = \Validator::make($request->all(),
  1009. [
  1010. 'id' => 'required',
  1011. ],
  1012. [
  1013. 'id.required' => '银行账号不存在',
  1014. ]
  1015. );
  1016. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1017. $ok =UserBank::destroy($id);
  1018. if ($ok) {
  1019. return $this->api('');
  1020. }else{
  1021. return $this->error(ErrorCode::OPERATION_FAILED);
  1022. }
  1023. }
  1024. }