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