MyController.php 25 KB

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