MyController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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. // dump(234324);
  250. $item->update(['is_read'=>0]);
  251. $info = InteractionInfo::find($item->interaction_id);
  252. $dream_id =empty($info) ? 0 : $info->dream_id;
  253. $item->dreamid = $dream_id;
  254. }
  255. return $this->api($data);
  256. }
  257. /**
  258. * @api {get} /api/my/letter 私信
  259. * @apiDescription 私信
  260. * @apiGroup My
  261. * @apiPermission Passport
  262. * @apiVersion 0.1.0
  263. * @apiSuccessExample {json} Success-Response:
  264. * HTTP/1.1 200 OK
  265. *{
  266. * "status": true,
  267. * "status_code": 0,
  268. * "message": "",
  269. * "data": [
  270. * {
  271. * ....
  272. * }
  273. * ]
  274. * @apiErrorExample {json} Error-Response:
  275. * HTTP/1.1 400 Bad Request
  276. */
  277. public function letter()
  278. {
  279. $user = $this->getUser();
  280. $data = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  281. foreach ($data as $item){ //访问接口 标记已读
  282. $item->update(['is_read'=>1]);
  283. }
  284. return $this->api($data);
  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. public function insertSearchTable($id,$keyword)
  836. {
  837. $info = SearchInfoModel::where('user_id',$id)->
  838. where('search',trim($keyword))->first();
  839. if (count($info) == 0) {
  840. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  841. }else{
  842. $info->times += 1;
  843. $info->save();
  844. }
  845. }
  846. //我的银行账户
  847. /**
  848. * @api {get} /api/my/bank/list 我的银行账户
  849. * @apiDescription 我的银行账户
  850. * @apiGroup My
  851. * @apiPermission Passport
  852. * @apiVersion 0.1.0
  853. * @apiSuccessExample {json} Success-Response:
  854. * HTTP/1.1 200 OK
  855. *{
  856. * "status": true,
  857. * "status_code": 0,
  858. * "message": "",
  859. * "data":[] or
  860. * "data": [
  861. * {
  862. * "id": 1,
  863. * "user_id": 1,
  864. * "bank_name": "1",
  865. * "bank_number": "1", /账号
  866. * "bank_phone": "1",
  867. * "bank_user": "" 用户名/
  868. * "type": 微信, 微信(支付宝)二维码
  869. * "url": wwww.ddf, 二维码地址
  870. * "is_img": 1,
  871. * }
  872. *]
  873. * @apiErrorExample {json} Error-Response:
  874. * HTTP/1.1 400 Bad Request
  875. */
  876. public function bankList()
  877. {
  878. $user = $this->getUser();
  879. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  880. return $this->api($data);
  881. }
  882. /**
  883. * @api {get} /api/my/bank/account 账户余额
  884. * @apiDescription 账户余额
  885. * @apiGroup My
  886. * @apiPermission Passport
  887. * @apiVersion 0.1.0
  888. * @apiSuccessExample {json} Success-Response:
  889. * HTTP/1.1 200 OK
  890. *{
  891. * "status": true,
  892. * "status_code": 0,
  893. * "message": "",
  894. * "data":[] or
  895. * "data": {
  896. * "coin": 508, 余额
  897. * }
  898. *]
  899. * @apiErrorExample {json} Error-Response:
  900. * HTTP/1.1 400 Bad Request
  901. */
  902. public function account()
  903. {
  904. $user = $this->getUser();
  905. return $this->api($user);
  906. }
  907. // 添加银行卡
  908. /**
  909. * @api {post} /api/my/bank/create 添加银行卡
  910. * @apiDescription 添加银行卡
  911. * @apiGroup My
  912. * @apiParam {string} data[bank_name] 银行名称
  913. * @apiParam {string} data[bank_number] 银行卡号
  914. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  915. * @apiParam {string} data[bank_user] 银行卡用户姓名
  916. * @apiPermission Passport
  917. * @apiVersion 0.1.0
  918. * @apiSuccessExample {json} Success-Response:
  919. * HTTP/1.1 200 OK
  920. *{
  921. * "status": true,
  922. * "status_code": 0,
  923. * "message": "",
  924. * "data": ""
  925. *}
  926. * @apiErrorExample {json} Error-Response:
  927. *{
  928. * "status": false,
  929. * "status_code": 700,
  930. * "message": "操作失败",
  931. * "data": null
  932. *}
  933. */
  934. public function bankCreate(Request $request)
  935. {
  936. $data = $request->data;
  937. $user = $this->getUser();
  938. $validator = \Validator::make($request->all(),
  939. [
  940. 'data.bank_name' => 'required',
  941. 'data.bank_number' => 'required',
  942. 'data.bank_phone' => 'required',
  943. 'data.bank_user' => 'required',
  944. ],
  945. [
  946. 'data.bank_name.required' => '请选择账号类型',
  947. 'data.bank_number.required' => '请输入账号',
  948. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  949. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  950. ]
  951. );
  952. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  953. $data['user_id'] = $user->id;
  954. $ok =UserBank::create($data);
  955. if ($ok) {
  956. return $this->api('');
  957. }else{
  958. return $this->error(ErrorCode::OPERATION_FAILED);
  959. }
  960. } /**
  961. * @api {post} /api/my/bank/qrcode 添加二维码
  962. * @apiDescription 添加二维码
  963. * @apiGroup My
  964. * @apiParam {string} data[type] 类型
  965. * @apiParam {string} data[qrcode] 二维码图片
  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 bankImgCreate(Request $request)
  985. {
  986. $data = $request->data;
  987. $user = $this->getUser();
  988. $validator = \Validator::make($request->all(),
  989. [
  990. 'data.type' => 'required',
  991. 'data.qrcode' => 'required',
  992. ],
  993. [
  994. 'data.type.required' => '请选择账号类型',
  995. 'data.qrcode.required' => '请上传二维码图片',
  996. ]
  997. );
  998. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  999. $data['user_id'] = $user->id;
  1000. /* $data['bank_user'] = '';
  1001. $data['bank_phone'] = '';
  1002. $data['bank_number'] = '';
  1003. $data['bank_name'] = '';*/
  1004. $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
  1005. ->where('type',$data['type'])->first(); //定义为二维码
  1006. if (empty($info)) {
  1007. $ok =UserBank::create($data);
  1008. }else{
  1009. $ok = $info->update($data);
  1010. }
  1011. if ($ok) {
  1012. return $this->api('');
  1013. }else{
  1014. return $this->error(ErrorCode::OPERATION_FAILED);
  1015. }
  1016. }
  1017. /**
  1018. * @api {get} /api/my/bank/delete 删除银行卡
  1019. * @apiDescription 删除银行卡
  1020. * @apiGroup My
  1021. * @apiParam {int} id 银行卡id
  1022. * @apiPermission Passport
  1023. * @apiVersion 0.1.0
  1024. * @apiSuccessExample {json} Success-Response:
  1025. * HTTP/1.1 200 OK
  1026. *{
  1027. * "status": true,
  1028. * "status_code": 0,
  1029. * "message": "",
  1030. * "data": ""
  1031. *}
  1032. * @apiErrorExample {json} Error-Response:
  1033. *{
  1034. * "status": false,
  1035. * "status_code": 700,
  1036. * "message": "操作失败",
  1037. * "data": null
  1038. *}
  1039. */
  1040. public function bankDelete(Request $request)
  1041. {
  1042. $id = $request->id;
  1043. $validator = \Validator::make($request->all(),
  1044. [
  1045. 'id' => 'required',
  1046. ],
  1047. [
  1048. 'id.required' => '银行账号不存在',
  1049. ]
  1050. );
  1051. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1052. $ok =UserBank::destroy($id);
  1053. if ($ok) {
  1054. return $this->api('');
  1055. }else{
  1056. return $this->error(ErrorCode::OPERATION_FAILED);
  1057. }
  1058. }
  1059. }