WithdrawController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace addons\HiGo\api\modules\v1\controllers;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use addons\HiGo\common\global_func\withdraw_way\WithdrawWay;
  5. use addons\HiGo\common\models\HigoWallet;
  6. use addons\HiGo\common\models\HigoWithdrawLog;
  7. use Yii;
  8. use api\controllers\OnAuthController;
  9. use common\enums\ApiStatusEnum;
  10. use common\enums\StatusEnum;
  11. use common\enums\WithdrawWayEnum;
  12. use common\globals\GlobalInvoke;
  13. use common\models\common\PlatformSetting;
  14. use common\models\common\UserBankCard;
  15. use common\models\common\UserThirdPartyAddress;
  16. use common\models\user\User;
  17. use yii\helpers\Json;
  18. /**
  19. *
  20. *
  21. * Class WithdrawController
  22. * @package addons\HiGo\api\modules\v1\controllers
  23. */
  24. class WithdrawController extends OnAuthController
  25. {
  26. public $modelClass = '';
  27. /**
  28. * 不用进行登录验证的方法
  29. *
  30. * 例如: ['index', 'update', 'create', 'view', 'delete']
  31. * 默认全部需要验证
  32. *
  33. * @var array
  34. */
  35. protected $authOptional = [];
  36. /**
  37. * @Description: 获取提现设置
  38. * @Author: qi
  39. * @DateTime 2022-11-19 15:33:56
  40. * @return mixed
  41. */
  42. public function actionGetSetting()
  43. {
  44. $params = \Yii::$app->request->post();
  45. $res = Yii::$app->services->validate->validate($params, [
  46. [['from'], 'required', 'message' => '参数丢失'],
  47. [['from'], 'in', 'range' => [1, 2]],
  48. ]);
  49. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  50. $higo_wallet = HigoWallet::getOne([['user_id' => $this->user_id], ['status' => StatusEnum::ENABLED], ['mall_id' => $this->mall_id]], true, [], false, 'hi_bei');
  51. $withdraw = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'withdraw');
  52. $cash_status = $withdraw['cash_status'] ? json_decode($withdraw['cash_status'], true) : 0;
  53. $cash_status = is_array($cash_status) ? $cash_status['value'] : $cash_status;
  54. if (!$cash_status) {
  55. return $this->error('暂未开启提现功能');
  56. }
  57. $isCash = $cash_status;
  58. $cashType = $withdraw['cash_type'] ? json_decode($withdraw['cash_type'], true) : [];
  59. $cashType = is_array($cashType) ? $cashType['value'] : $cashType;
  60. $cashServiceFee = $withdraw['cash_service_fee'] ? json_decode($withdraw['cash_service_fee'], true) : 0;
  61. $cashServiceFee = is_array($cashServiceFee) ? $cashServiceFee['value'] : $cashServiceFee;
  62. $userMoney = $higo_wallet['hi_bei'] ?? 0;
  63. $balance_config = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.balance');
  64. $pay_password_status = 0;
  65. if ($balance_config) {
  66. $balance_config = Json::decode($balance_config);
  67. $pay_password_status = isset($balance_config["pay_password_status"]) ? $balance_config["pay_password_status"] : 0;
  68. }
  69. if (!$isCash) {
  70. return $this->error('系统未开启提现功能');
  71. }
  72. if (!$cashType) {
  73. return $this->error('系统未设置提现方式');
  74. }
  75. $cash__type_name = [];
  76. $get_system_setting = PlatformSetting::getConfByGroup('system', true);
  77. if (!empty($cashType)) {
  78. $cash_type = $cashType;
  79. $cash__type_name = [];
  80. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  81. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]);
  82. $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way, WithdrawWay::getExtensionWithdrawWay());
  83. $cash_type_keys = array_keys($all_withdraw);
  84. if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
  85. $bank_card_list = UserBankCard::getUserCardList($this->user_id, $this->mall_id);
  86. }
  87. foreach ($cash_type as $i => $item) {
  88. if (isset($all_withdraw[$item])) {
  89. $taxFee = 0;
  90. $name = '';
  91. if (isset($all_withdraw[$item])) {
  92. if (is_array($all_withdraw[$item])) {
  93. $name = $all_withdraw[$item]['name'] ?? '';
  94. $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
  95. } else {
  96. $name = $all_withdraw[$item];
  97. }
  98. }
  99. $cash__type_name[$i]['type'] = $item;
  100. $cash__type_name[$i]['taxFee'] = $taxFee;
  101. $cash__type_name[$i]['name'] = $name;
  102. $cash__type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
  103. if ('bank' == $item || 'joinpay' == $item) {
  104. $cash__type_name[$i]['bank_card_list'] = $bank_card_list;
  105. }
  106. }
  107. }
  108. }
  109. $password = User::getOne([['id' => $this->user_id]], true, '', '', 'transaction_password');
  110. $third_party_address = UserThirdPartyAddress::getOne([['mall_id' => $this->mall_id], ['user_id' => $this->user_id], ['status' => StatusEnum::ENABLED]], true, [], false, 'third_party_address');
  111. $isTransactionPassword = false;
  112. $transaction_password = $password['transaction_password'];
  113. $transaction_password = trim($transaction_password);
  114. if (!empty($transaction_password)) {
  115. $isTransactionPassword = true;
  116. }
  117. //检测是否需要实名认证
  118. $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'cash']);
  119. if ($need_auth === true) {
  120. //需要先进行实名认证
  121. return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
  122. }
  123. $wallet_text = HiGoEnum::getHigoWalletText($this->mall_id);
  124. return $this->success('操作成功', [
  125. 'notice' => [
  126. 'content' => '',
  127. 'icon' => ''
  128. ],
  129. 'setting' => [
  130. 'cash_type_name' => $cash__type_name,
  131. 'cash_service_fee' => $cashServiceFee,
  132. 'min_money' => 0.00,
  133. 'day_max_money' => 0.00,
  134. 'withdrawal_rule' => '',
  135. 'pay_password_status' => intval($pay_password_status),
  136. 'hi_bei_name' => $wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI]
  137. ],
  138. 'user_info' => [
  139. 'income' => $userMoney,
  140. 'is_transaction_password' => $isTransactionPassword,
  141. 'third_party_address' => $third_party_address['third_party_address'] ?? ''
  142. ]
  143. ], ApiStatusEnum::CODE_SUCCESS, 0);
  144. }
  145. /**
  146. * @Description: 提现
  147. * @Author: qi
  148. * @DateTime 2022-11-19 15:50:22
  149. * @return mixed
  150. */
  151. public function actionWithdraw()
  152. {
  153. $params = \Yii::$app->request->post();
  154. $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'cash']);
  155. if ($need_auth === true) {
  156. //需要先进行实名认证
  157. return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
  158. }
  159. $form = new HigoWithdrawLog();
  160. $params['mall_id'] = $this->mall_id;
  161. $params['user_id'] = $this->user_id;
  162. $form->attributes = $params;
  163. $data = $form->saveRecord($params);
  164. if ($data['state']) {
  165. return $this->success('操作成功', $data['data']);
  166. } else {
  167. return $this->error($data['msg']);
  168. }
  169. }
  170. }