MyController.php 33 KB

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