MyController.php 26 KB

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