UserExtractController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\user;
  12. use app\Request;
  13. use app\services\user\UserExtractServices;
  14. use think\facade\Config;
  15. /**
  16. * 提现类
  17. * Class UserExtractController
  18. * @package app\controller\api\user
  19. */
  20. class UserExtractController
  21. {
  22. protected $services = NUll;
  23. /**
  24. * UserExtractController constructor.
  25. * @param UserExtractServices $services
  26. */
  27. public function __construct(UserExtractServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 提现银行
  33. * @param Request $request
  34. * @return mixed
  35. */
  36. public function bank(Request $request)
  37. {
  38. $uid = (int)$request->uid();
  39. return app('json')->successful($this->services->bank($uid));
  40. }
  41. /**
  42. * 提现申请
  43. * @param Request $request
  44. * @return mixed
  45. */
  46. public function cash(Request $request)
  47. {
  48. $extractInfo = $request->postMore([
  49. ['alipay_code', ''],
  50. ['extract_type', ''],
  51. ['money', 0],
  52. ['name', ''],
  53. ['bankname', ''],
  54. ['cardnum', ''],
  55. ['weixin', ''],
  56. ['qrcode_url', ''],
  57. ]);
  58. $extractType = Config::get('pay.extractType', []);
  59. if (!in_array($extractInfo['extract_type'], $extractType))
  60. return app('json')->fail('提现方式不存在');
  61. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  62. if (!$extractInfo['cardnum'] == '')
  63. if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
  64. return app('json')->fail('银行卡号输入有误');
  65. if ($extractInfo['extract_type'] == 'alipay') {
  66. if (!$extractInfo['alipay_code']) return app('json')->fail('请输入支付宝账号');
  67. } else if ($extractInfo['extract_type'] == 'bank') {
  68. if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号');
  69. if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息');
  70. } else if ($extractInfo['extract_type'] == 'weixin' && sys_config('brokerage_type') == 0) {
  71. if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号');
  72. }
  73. $uid = (int)$request->uid();
  74. if ($this->services->cash($uid, $extractInfo))
  75. return app('json')->successful('申请提现成功!');
  76. else
  77. return app('json')->fail('提现失败');
  78. }
  79. }