MyController.php 27 KB

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