MyController.php 34 KB

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