MyController.php 38 KB

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