UserExtractController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 crmeb\services\WithdrawService;
  15. use think\facade\Config;
  16. /**
  17. * 提现类
  18. * Class UserExtractController
  19. * @package app\controller\api\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')->successful($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', 'bank'],
  52. ['money', 0],
  53. // ['name', ''],
  54. // ['bankname', ''],
  55. // ['cardnum', ''],
  56. // ['weixin', ''],
  57. // ['qrcode_url', ''],
  58. ]);
  59. $extractType = Config::get('pay.extractType', []);
  60. if (!in_array($extractInfo['extract_type'], $extractType))
  61. return app('json')->fail('提现方式不存在');
  62. if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('提现金额输入有误');
  63. if (!$extractInfo['cardnum'] == '')
  64. if (!preg_match('/^([1-9]{1})(\d{15}|\d{16}|\d{18})$/', $extractInfo['cardnum']))
  65. return app('json')->fail('银行卡号输入有误');
  66. if ($extractInfo['extract_type'] == 'alipay') {
  67. if (!$extractInfo['alipay_code']) return app('json')->fail('请输入支付宝账号');
  68. } else if ($extractInfo['extract_type'] == 'bank') {
  69. // if (!$extractInfo['cardnum']) return app('json')->fail('请输入银行卡账号');
  70. // if (!$extractInfo['bankname']) return app('json')->fail('请输入开户行信息');
  71. // $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
  72. // if ($bank_info['is_contract']) {
  73. // return app('json')->fail('签约已完成');
  74. // }
  75. } else if ($extractInfo['extract_type'] == 'weixin' && sys_config('brokerage_type') == 0) {
  76. if (!$extractInfo['weixin']) return app('json')->fail('请输入微信账号');
  77. }
  78. $uid = (int)$request->uid();
  79. if ($this->services->cash($uid, $extractInfo))
  80. return app('json')->successful('申请提现成功!');
  81. else
  82. return app('json')->fail('提现失败');
  83. }
  84. }