MyController.php 34 KB

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