UserExtractController.php 3.6 KB

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