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