UserExtractController.php 3.5 KB

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