MyController.php 24 KB

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