MyController.php 23 KB

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