MyController.php 31 KB

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