MyController.php 33 KB

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