MyController.php 38 KB

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