UserExtractController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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 think\facade\Config;
  15. /**
  16. * 提现类
  17. * Class UserExtractController
  18. * @package app\api\controller\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')->success($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. ['user_name', ''],
  53. ['name', ''],
  54. ['bankname', ''],
  55. ['cardnum', ''],
  56. ['weixin', ''],
  57. ['qrcode_url', ''],
  58. ]);
  59. $extractInfo['channel_type'] = $request->getFromType();
  60. $extractType = Config::get('pay.extractType', []);
  61. if (!in_array($extractInfo['extract_type'], $extractType))
  62. return app('json')->fail(410114);
  63. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail(410115);
  64. if (!$extractInfo['cardnum'] == '')
  65. if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
  66. return app('json')->fail(410116);
  67. if ($extractInfo['extract_type'] == 'weixin') {
  68. if (trim($extractInfo['user_name']) == '') return app('json')->fail('请填写真实姓名');
  69. } elseif ($extractInfo['extract_type'] == 'alipay') {
  70. if (trim($extractInfo['alipay_code']) == '') return app('json')->fail(410117);
  71. if (trim($extractInfo['user_name']) == '') return app('json')->fail('请填写真实姓名');
  72. } elseif ($extractInfo['extract_type'] == 'bank') {
  73. if (!$extractInfo['cardnum']) return app('json')->fail(410118);
  74. if (!$extractInfo['bankname']) return app('json')->fail(410119);
  75. }
  76. $uid = (int)$request->uid();
  77. if ($this->services->cash($uid, $extractInfo))
  78. return app('json')->success(410120);
  79. else
  80. return app('json')->fail(410121);
  81. }
  82. }