| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace addons\HiGo\api\modules\v1\controllers;
- use addons\HiGo\common\enums\HiGoEnum;
- use addons\HiGo\common\global_func\withdraw_way\WithdrawWay;
- use addons\HiGo\common\models\HigoWallet;
- use addons\HiGo\common\models\HigoWithdrawLog;
- use Yii;
- use api\controllers\OnAuthController;
- use common\enums\ApiStatusEnum;
- use common\enums\StatusEnum;
- use common\enums\WithdrawWayEnum;
- use common\globals\GlobalInvoke;
- use common\models\common\PlatformSetting;
- use common\models\common\UserBankCard;
- use common\models\common\UserThirdPartyAddress;
- use common\models\user\User;
- use yii\helpers\Json;
- /**
- *
- *
- * Class WithdrawController
- * @package addons\HiGo\api\modules\v1\controllers
- */
- class WithdrawController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * @Description: 获取提现设置
- * @Author: qi
- * @DateTime 2022-11-19 15:33:56
- * @return mixed
- */
- public function actionGetSetting()
- {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['from'], 'required', 'message' => '参数丢失'],
- [['from'], 'in', 'range' => [1, 2]],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $higo_wallet = HigoWallet::getOne([['user_id' => $this->user_id], ['status' => StatusEnum::ENABLED], ['mall_id' => $this->mall_id]], true, [], false, 'hi_bei');
- $withdraw = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'withdraw');
- $cash_status = $withdraw['cash_status'] ? json_decode($withdraw['cash_status'], true) : 0;
- $cash_status = is_array($cash_status) ? $cash_status['value'] : $cash_status;
- if (!$cash_status) {
- return $this->error('暂未开启提现功能');
- }
- $isCash = $cash_status;
- $cashType = $withdraw['cash_type'] ? json_decode($withdraw['cash_type'], true) : [];
- $cashType = is_array($cashType) ? $cashType['value'] : $cashType;
- $cashServiceFee = $withdraw['cash_service_fee'] ? json_decode($withdraw['cash_service_fee'], true) : 0;
- $cashServiceFee = is_array($cashServiceFee) ? $cashServiceFee['value'] : $cashServiceFee;
- $userMoney = $higo_wallet['hi_bei'] ?? 0;
- $balance_config = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.balance');
- $pay_password_status = 0;
- if ($balance_config) {
- $balance_config = Json::decode($balance_config);
- $pay_password_status = isset($balance_config["pay_password_status"]) ? $balance_config["pay_password_status"] : 0;
- }
- if (!$isCash) {
- return $this->error('系统未开启提现功能');
- }
- if (!$cashType) {
- return $this->error('系统未设置提现方式');
- }
- $cash__type_name = [];
- $get_system_setting = PlatformSetting::getConfByGroup('system', true);
- if (!empty($cashType)) {
- $cash_type = $cashType;
- $cash__type_name = [];
- $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
- $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]);
- $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way, WithdrawWay::getExtensionWithdrawWay());
- $cash_type_keys = array_keys($all_withdraw);
- if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
- $bank_card_list = UserBankCard::getUserCardList($this->user_id, $this->mall_id);
- }
- foreach ($cash_type as $i => $item) {
- if (isset($all_withdraw[$item])) {
- $taxFee = 0;
- $name = '';
- if (isset($all_withdraw[$item])) {
- if (is_array($all_withdraw[$item])) {
- $name = $all_withdraw[$item]['name'] ?? '';
- $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
- } else {
- $name = $all_withdraw[$item];
- }
- }
- $cash__type_name[$i]['type'] = $item;
- $cash__type_name[$i]['taxFee'] = $taxFee;
- $cash__type_name[$i]['name'] = $name;
- $cash__type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
- if ('bank' == $item || 'joinpay' == $item) {
- $cash__type_name[$i]['bank_card_list'] = $bank_card_list;
- }
- }
- }
- }
- $password = User::getOne([['id' => $this->user_id]], true, '', '', 'transaction_password');
- $third_party_address = UserThirdPartyAddress::getOne([['mall_id' => $this->mall_id], ['user_id' => $this->user_id], ['status' => StatusEnum::ENABLED]], true, [], false, 'third_party_address');
- $isTransactionPassword = false;
- $transaction_password = $password['transaction_password'];
- $transaction_password = trim($transaction_password);
- if (!empty($transaction_password)) {
- $isTransactionPassword = true;
- }
- //检测是否需要实名认证
- $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'cash']);
- if ($need_auth === true) {
- //需要先进行实名认证
- return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
- }
- $wallet_text = HiGoEnum::getHigoWalletText($this->mall_id);
- return $this->success('操作成功', [
- 'notice' => [
- 'content' => '',
- 'icon' => ''
- ],
- 'setting' => [
- 'cash_type_name' => $cash__type_name,
- 'cash_service_fee' => $cashServiceFee,
- 'min_money' => 0.00,
- 'day_max_money' => 0.00,
- 'withdrawal_rule' => '',
- 'pay_password_status' => intval($pay_password_status),
- 'hi_bei_name' => $wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI]
- ],
- 'user_info' => [
- 'income' => $userMoney,
- 'is_transaction_password' => $isTransactionPassword,
- 'third_party_address' => $third_party_address['third_party_address'] ?? ''
- ]
- ], ApiStatusEnum::CODE_SUCCESS, 0);
- }
- /**
- * @Description: 提现
- * @Author: qi
- * @DateTime 2022-11-19 15:50:22
- * @return mixed
- */
- public function actionWithdraw()
- {
- $params = \Yii::$app->request->post();
- $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'cash']);
- if ($need_auth === true) {
- //需要先进行实名认证
- return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
- }
- $form = new HigoWithdrawLog();
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $form->attributes = $params;
- $data = $form->saveRecord($params);
- if ($data['state']) {
- return $this->success('操作成功', $data['data']);
- } else {
- return $this->error($data['msg']);
- }
- }
- }
|