MyController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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 {post} /api/my/cash 提现
  274. * @apiDescription 提现
  275. * @apiGroup My
  276. * @apiParam {int} data[bank_id] 银行卡号id
  277. * @apiParam {int} data[cash] 银行卡号id
  278. * @apiPermission Passport
  279. * @apiVersion 0.1.0
  280. * @apiSuccessExample {json} Success-Response:
  281. * HTTP/1.1 200 OK
  282. *{
  283. * "status": false,
  284. * "status_code": 1413,
  285. * "message": "系统审核中",
  286. * "data": null
  287. *}
  288. * @apiErrorExample {json} Error-Response:
  289. *{
  290. * "status": false,
  291. * "status_code": 700,
  292. * "message": "操作失败",
  293. * "data": null
  294. *}
  295. */
  296. public function cash(Request $request)
  297. {
  298. $data = $request->data;
  299. $user = $this->getUser();
  300. $validator = \Validator::make($request->all(),
  301. [
  302. 'data.bank_id' => 'required',
  303. 'data.cash' => 'required',
  304. ],
  305. [
  306. 'data.id.required' => '请选择提现账号',
  307. 'data.cash.required' => '请输入金额',
  308. ]
  309. );
  310. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  311. // $info = [] ;
  312. // $info['from_type'] = '余额';
  313. // $info['from_id'] = $user->id;
  314. // $info['from_name'] = $user->name;
  315. // $info['op'] = '提现';
  316. // $info['from_amount'] = $data['coin'];
  317. // $info['to_type'] = '现金';
  318. // $info['to_id'] = $user->id;
  319. // $info['to_name'] = $data['account']; //账号
  320. // $info['note'] = $data['type'].$data['name'];
  321. // $ok = AccountLog::create($info);
  322. $data['user_id'] = $user->id;
  323. $data['status'] = 0;
  324. $ok = UserCashOut::create($data);
  325. if ($ok) {
  326. return $this->error(ErrorCode::verify);
  327. }else{
  328. return $this->error(ErrorCode::OPERATION_FAILED);
  329. }
  330. }
  331. // 联系客服
  332. /**
  333. * @api {post} /api/my/suggest 联系客服
  334. * @apiDescription 联系客服
  335. * @apiGroup My
  336. * @apiParam {string} data[content] 内容
  337. * @apiParam {string} data[email] 邮箱
  338. * @apiPermission Passport
  339. * @apiVersion 0.1.0
  340. * @apiSuccessExample {json} Success-Response:
  341. * HTTP/1.1 200 OK
  342. *{
  343. * "status": false,
  344. * "status_code": 200,
  345. * "message": "操作成功",
  346. * "data": null
  347. *}
  348. * @apiErrorExample {json} Error-Response:
  349. *{
  350. * "status": false,
  351. * "status_code": 700,
  352. * "message": "操作失败",
  353. * "data": null
  354. *}
  355. */
  356. public function suggest(Request $request)
  357. {
  358. $data = $request->data;
  359. $user = $this->getUser();
  360. $validator = \Validator::make($request->all(),
  361. [
  362. 'data.content' => 'required',
  363. 'data.email' => 'required|email',
  364. ],
  365. [
  366. 'data.content.required' => '请输入你遇到的问题',
  367. 'data.email.required' => '请输入正确的邮箱地址',
  368. 'data.email.email' => '请输入正确的邮箱地址',
  369. ]
  370. );
  371. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  372. $data['user_id'] = $user->id;
  373. $ok =Suggest::create($data);
  374. if ($ok) {
  375. return $this->error(ErrorCode::OPERATION_SUCCESS);
  376. }else{
  377. return $this->error(ErrorCode::OPERATION_FAILED);
  378. }
  379. }
  380. // 回复我的
  381. // public function replyMy()
  382. // {
  383. //
  384. // $user = $this->getUser();
  385. //// 梦想
  386. // $dreams = $user->UserDream;
  387. //
  388. // $data = $user->allInteraction;
  389. // foreach ($data as $item) {
  390. // $item->get_money = $item->dream->get_money;
  391. // $item->money = $item->dream->money;
  392. // }
  393. // dd($data) ;
  394. // if (count($dreams) == 0)
  395. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  396. // $comments_infos = [];
  397. // foreach ($dreams as $dream){
  398. // $comments_info = $dream->DreamInfo;
  399. // if (count($comments_info) > 0) {
  400. // foreach ($comments_info as $k => $value) {
  401. // $value->dream_name = $dream->dream;
  402. // $value->dream_about = $dream->about;
  403. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  404. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  405. // $value->reviewer = $value->CommentUser->nickname;
  406. // $value->reviewer_pic = $value->CommentUser->pic;
  407. // }
  408. // $comments_infos[] = $comments_info;
  409. // }
  410. // }
  411. //
  412. // return $this->api(compact('comments_infos'));
  413. // }
  414. /**
  415. * @api {get} /api/my/dream 我的梦想
  416. * @apiDescription 我的梦想
  417. * @apiGroup My
  418. * @apiPermission Passport
  419. * @apiVersion 0.1.0
  420. * @apiSuccessExample {json} Success-Response:
  421. * HTTP/1.1 200 OK
  422. *{
  423. * "status": true,
  424. * "status_code": 0,
  425. * "message": "",
  426. * "data": [
  427. * {
  428. * "id": 5,
  429. * "user_id": 1,
  430. * "name": "梦想标题1",
  431. * "about": "梦想介绍",
  432. * "coin": 2500,
  433. * "time": 21,
  434. * "get_coin": 0,
  435. * "status": 0,
  436. * "video": null,
  437. * "sign": "",
  438. * "created_at": "2017-06-25 12:45:22",
  439. * "updated_at": "2017-06-25 12:45:22",
  440. * "pic": "https://timgsa.baidu.com/timg?image7b14f12f.jpg",
  441. * },
  442. * ]
  443. *}
  444. * @apiErrorExample {json} Error-Response:
  445. * HTTP/1.1 400 Bad Request
  446. */
  447. public function dream()
  448. {
  449. $user = $this->getUser();
  450. $dreams = $user->dreams;
  451. if (count($dreams) == 0)
  452. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  453. foreach ($dreams as $dream){
  454. $dream->pic = count($dream->img) > 0 ? $dream->img->pic : '';
  455. }
  456. return $this->api($dreams);
  457. }
  458. /**
  459. * @api {get} /api/my/collection 我的收藏
  460. * @apiDescription 我的收藏
  461. * @apiGroup My
  462. * @apiPermission Passport
  463. * @apiParam {string} [keyword] 关键字可选
  464. * @apiVersion 0.1.0
  465. * @apiSuccessExample {json} Success-Response:
  466. * HTTP/1.1 200 OK
  467. *{
  468. * "status": true,
  469. * "status_code": 0,
  470. * "message": "",
  471. * "data": {
  472. * "data": [
  473. * { 梦想详情
  474. * "id": 12,
  475. * "user_id": 2,
  476. * "name": "用户2梦想标题166",
  477. * "about": "用户2梦想介绍666",
  478. * "coin": 2500,
  479. * "time": 21,
  480. * "get_coin": 0,
  481. * "status": 0,
  482. * "video": null,
  483. * "sign": "",
  484. * },
  485. * "img": {
  486. * "title": "",
  487. * "pic": "https://f12f.jpg" 梦想封面图片
  488. * }
  489. * ],
  490. * "users": {
  491. * "2": "https://xxx.jpeg" ID号和头像
  492. * }
  493. * }
  494. *}
  495. * keyword存在
  496. {
  497. "status": true,
  498. "status_code": 0,
  499. "message": "",
  500. "data": [
  501. {
  502. "id": 2,
  503. "user_id": 1,
  504. "dream_id": 12,
  505. "dream_user_id": 2,
  506. "interaction_number": 0,
  507. "created_at": "2017-06-25 13:11:45",
  508. "updated_at": "2017-06-25 13:11:45",
  509. "dreams": [ 梦想
  510. {
  511. "id": 12,
  512. "user_id": 2,
  513. "name": "用户2梦想标题166",
  514. "about": "用户2梦想介绍666",
  515. "coin": 2500,
  516. "end_time": 72000,
  517. "get_coin": 792,
  518. "mark": 5484,
  519. "status": 0,
  520. "video": "e",
  521. "score": 158730,
  522. "sign": "梦想达人",
  523. "created_at": "2017-06-25 13:10:56",
  524. "updated_at": "2017-06-28 16:53:39"
  525. "img": { 图片
  526. "title": "",
  527. "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  528. }
  529. }
  530. ]
  531. }
  532. ]
  533. }
  534. * @apiErrorExample {json} Error-Response:
  535. * HTTP/1.1 400 Bad Request
  536. */
  537. public function collection(Request $request)
  538. {
  539. $user = $this->getUser();
  540. if ($request->keyword) {
  541. $keyword ='%'.$request->keyword.'%';
  542. $data = UserCareDream::where('user_id',$user->id)->
  543. whereHas('dreams',function ($query) use($keyword){
  544. $query->where('end_time','>=',time())->where('name','like',$keyword);
  545. })->with('dreams')->get();
  546. foreach ($data as $item) {
  547. foreach ($item->dreams as $dream) {
  548. $dream->img;
  549. }
  550. }
  551. $this->insertSearchTable($user->id,$request->keyword);
  552. return $this->api($data);
  553. }else{
  554. $dreams = $user->collection;
  555. $users = [];
  556. foreach ($dreams as $item) {
  557. if ($item->pivot->interaction_number > 0) {
  558. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  559. $avatar = $user_info ? $user_info->avatar : '';
  560. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  561. $users[$item->pivot->dream_user_id] = $avatar;
  562. }
  563. }
  564. $item->img;
  565. }
  566. return $this->api(compact('dreams','users'));
  567. }
  568. }
  569. /**
  570. * @api {get} /api/my/setting 设置
  571. * @apiDescription 设置
  572. * @apiGroup My
  573. * @apiPermission Passport
  574. * @apiVersion 0.1.0
  575. * @apiSuccessExample {json} Success-Response:
  576. * HTTP/1.1 200 OK
  577. *{
  578. * "status": true,
  579. * "status_code": 0,
  580. * "message": "",
  581. * "data": {
  582. * "key": "2511789", 电话
  583. * "value": "关于喵喵介绍" 关于喵喵
  584. * }
  585. *}
  586. * @apiErrorExample {json} Error-Response:
  587. * HTTP/1.1 400 Bad Request
  588. */
  589. public function setting()
  590. {
  591. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  592. return $this->api($data);
  593. }
  594. /**
  595. * @api {get} /api/my/care 我关注的用户
  596. * @apiDescription 我关注的用户
  597. * @apiGroup My
  598. * @apiPermission Passport
  599. * @apiVersion 0.1.0
  600. * @apiSuccessExample {json} Success-Response:
  601. * HTTP/1.1 200 OK
  602. *{
  603. * "status": true,
  604. * "status_code": 0,
  605. * "message": "",
  606. * "data":[] or
  607. * "data": [
  608. * {
  609. * "id": 2,
  610. * "phone": "13880642881",
  611. * "nickname": "name2",
  612. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  613. * "birthday": "2000-06-21",
  614. * "sign": 0,
  615. * "money": 0,
  616. * "coin": 800,
  617. * "sex": 1,
  618. * "signture": "我的个性签名2",
  619. * "height": 200,
  620. * "work": "兼职",
  621. * "emotion": 2,
  622. * "address": "370105",
  623. * "city": "成都",
  624. * "detail_address": "",
  625. * "status": 1,
  626. * "wechat": "",
  627. * "weibo": "",
  628. * "remember_token": "",
  629. * "created_at": "2017-06-25 10:42:06",
  630. * "updated_at": "2017-06-30 09:15:04",
  631. * "deleted_at": null,
  632. * }
  633. * ]
  634. *}
  635. * @apiErrorExample {json} Error-Response:
  636. * HTTP/1.1 400 Bad Request
  637. */
  638. public function care()
  639. {
  640. $user = $this->getUser();
  641. $users =$user->UserCareUser;
  642. return $this->api($users);
  643. }
  644. public function insertSearchTable($id,$keyword)
  645. {
  646. $info = SearchInfoModel::where('user_id',$id)->
  647. where('search',trim($keyword))->first();
  648. if (count($info) == 0) {
  649. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  650. }else{
  651. $info->times += 1;
  652. $info->save();
  653. }
  654. }
  655. //我的银行账户
  656. /**
  657. * @api {get} /api/my/bank/list 我的银行账户
  658. * @apiDescription 我的银行账户
  659. * @apiGroup My
  660. * @apiPermission Passport
  661. * @apiVersion 0.1.0
  662. * @apiSuccessExample {json} Success-Response:
  663. * HTTP/1.1 200 OK
  664. *{
  665. * "status": true,
  666. * "status_code": 0,
  667. * "message": "",
  668. * "data":[] or
  669. * "data": [
  670. * {
  671. * "id": 1,
  672. * "user_id": 1,
  673. * "bank_name": "1",
  674. * "bank_number": "1",
  675. * "bank_phone": "1",
  676. * "bank_user": "1"
  677. * }
  678. *]
  679. * @apiErrorExample {json} Error-Response:
  680. * HTTP/1.1 400 Bad Request
  681. */
  682. public function bankList()
  683. {
  684. $user = $this->getUser();
  685. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  686. return $this->api($data);
  687. }
  688. // 添加银行卡
  689. /**
  690. * @api {post} /api/my/bank/create 添加银行卡
  691. * @apiDescription 添加银行卡
  692. * @apiGroup My
  693. * @apiParam {string} data[bank_name] 银行名称
  694. * @apiParam {string} data[bank_number] 银行卡号
  695. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  696. * @apiParam {string} data[bank_user] 银行卡用户姓名
  697. * @apiPermission Passport
  698. * @apiVersion 0.1.0
  699. * @apiSuccessExample {json} Success-Response:
  700. * HTTP/1.1 200 OK
  701. *{
  702. * "status": false,
  703. * "status_code": 200,
  704. * "message": "操作成功",
  705. * "data": null
  706. *}
  707. * @apiErrorExample {json} Error-Response:
  708. *{
  709. * "status": false,
  710. * "status_code": 700,
  711. * "message": "操作失败",
  712. * "data": null
  713. *}
  714. */
  715. public function bankCreate(Request $request)
  716. {
  717. $data = $request->data;
  718. $user = $this->getUser();
  719. $validator = \Validator::make($request->all(),
  720. [
  721. 'data.bank_name' => 'required',
  722. 'data.bank_number' => 'required',
  723. 'data.bank_phone' => 'required',
  724. 'data.bank_user' => 'required',
  725. ],
  726. [
  727. 'data.bank_name.required' => '请选择账号类型',
  728. 'data.bank_number.required' => '请输入账号',
  729. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  730. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  731. ]
  732. );
  733. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  734. $data['user_id'] = $user->id;
  735. $ok =UserBank::create($data);
  736. if ($ok) {
  737. return $this->error(ErrorCode::OPERATION_SUCCESS);
  738. }else{
  739. return $this->error(ErrorCode::OPERATION_FAILED);
  740. }
  741. }
  742. /**
  743. * @api {post} /api/my/bank/delete 删除银行卡
  744. * @apiDescription 删除银行卡
  745. * @apiGroup My
  746. * @apiParam {int} id 银行卡id
  747. * @apiPermission Passport
  748. * @apiVersion 0.1.0
  749. * @apiSuccessExample {json} Success-Response:
  750. * HTTP/1.1 200 OK
  751. *{
  752. * "status": false,
  753. * "status_code": 200,
  754. * "message": "操作成功",
  755. * "data": null
  756. *}
  757. * @apiErrorExample {json} Error-Response:
  758. *{
  759. * "status": false,
  760. * "status_code": 700,
  761. * "message": "操作失败",
  762. * "data": null
  763. *}
  764. */
  765. public function bankDelete(Request $request)
  766. {
  767. $id = $request->id;
  768. $validator = \Validator::make($request->all(),
  769. [
  770. 'id' => 'required',
  771. ],
  772. [
  773. 'id.required' => '银行账号不存在',
  774. ]
  775. );
  776. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  777. $ok =UserBank::destroy($id);
  778. if ($ok) {
  779. return $this->error(ErrorCode::OPERATION_SUCCESS);
  780. }else{
  781. return $this->error(ErrorCode::OPERATION_FAILED);
  782. }
  783. }
  784. }