257 行
9.3 KiB
PHP
257 行
9.3 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\controller;
|
|
|
|
|
|
class UserWalletApply extends Base
|
|
{
|
|
|
|
protected $noNeedLogin = ['rule'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
public function index()
|
|
{
|
|
$this->success('提现记录', \addons\shopro\model\UserWalletApply::getList());
|
|
}
|
|
|
|
// 申请提现
|
|
public function apply()
|
|
{
|
|
$type = $this->request->post('type');
|
|
$money = $this->request->post('money');
|
|
$apply = \think\Db::transaction(function () use ($type, $money) {
|
|
try {
|
|
return \addons\shopro\model\UserWalletApply::apply($type, $money);
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
});
|
|
if ($apply) {
|
|
$this->success('申请成功');
|
|
}
|
|
$this->error('申请失败');
|
|
}
|
|
|
|
public function rule()
|
|
{
|
|
// 提现规则
|
|
$config = \addons\shopro\model\UserWalletApply::getWithdrawConfig();
|
|
$min = round(floatval($config['min']), 2);
|
|
$max = round(floatval($config['max']), 2);
|
|
$service_fee = floatval($config['service_fee']) * 100;
|
|
$service_fee = round($service_fee, 1); // 1 位小数
|
|
$perday_amount = isset($config['perday_amount']) ? round(floatval($config['perday_amount']), 2) : 0;
|
|
$perday_num = isset($config['perday_num']) ? round(floatval($config['perday_num']), 2) : 0;
|
|
|
|
$rule = [
|
|
'min' => $min,
|
|
'max' => $max,
|
|
'service_fee' => $service_fee,
|
|
'perday_amount' => $perday_amount,
|
|
'perday_num' => $perday_num,
|
|
'methods' => $config['methods'] ?? [],
|
|
'wechat_alipay_auto' => ($config['wechat_alipay_auto'] ?? '0') == '1',
|
|
];
|
|
|
|
$this->success('提现规则', $rule);
|
|
}
|
|
|
|
/**
|
|
* 提现页分账进件绑定信息(分销商 / 区域公司)
|
|
*/
|
|
public function onboard()
|
|
{
|
|
$this->success('进件绑定', $this->resolveWalletOnboard($this->auth->id));
|
|
}
|
|
|
|
/**
|
|
* 汇付进件:支行联行号检索(桥接 shopro_huifu 插件)
|
|
*/
|
|
public function searchBranch()
|
|
{
|
|
if (!class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardBankBranch')) {
|
|
$this->error('汇付插件未安装');
|
|
}
|
|
$keyword = $this->request->get('keyword', $this->request->post('keyword', ''));
|
|
$cityCode = $this->request->get('city_code', $this->request->post('city_code', ''));
|
|
$limit = intval($this->request->get('limit', 20));
|
|
$list = \addons\shopro_huifu\library\onboard\HuifuOnboardBankBranch::search($keyword, $cityCode, $limit);
|
|
$this->success('ok', ['list' => $list]);
|
|
}
|
|
|
|
/**
|
|
* 提现页提交 / 重新提交分账进件资料
|
|
*/
|
|
public function onboardSubmit()
|
|
{
|
|
if (!class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')
|
|
|| !\addons\shopro_huifu\library\onboard\HuifuOnboardGate::isOnboardRequired()) {
|
|
$this->error('当前无需绑定进件资料');
|
|
}
|
|
|
|
$form = $this->request->post('huifu_onboard/a', []);
|
|
if (empty($form) || !is_array($form)) {
|
|
$this->error('请填写进件资料');
|
|
}
|
|
|
|
$userId = $this->auth->id;
|
|
$bindings = $this->collectOnboardBindings($userId);
|
|
if (!$bindings) {
|
|
$this->error('您暂无可绑定进件的角色');
|
|
}
|
|
|
|
$service = new \addons\shopro_huifu\library\onboard\HuifuOnboardService();
|
|
$did = false;
|
|
$resubmit = false;
|
|
|
|
try {
|
|
\think\Db::transaction(function () use ($bindings, $userId, $form, $service, &$did, &$resubmit) {
|
|
foreach ($bindings as $binding) {
|
|
$huifu = $binding['huifu_onboard'];
|
|
if (!empty($huifu['can_submit'])) {
|
|
$service->submit($userId, $binding['role_type'], $binding['role_ref_id'], $form);
|
|
$did = true;
|
|
$resubmit = true;
|
|
} elseif (!empty($huifu['can_save_draft'])) {
|
|
$service->saveDraft($userId, $binding['role_type'], $binding['role_ref_id'], $form);
|
|
$did = true;
|
|
}
|
|
}
|
|
});
|
|
} catch (\InvalidArgumentException $e) {
|
|
$this->error($e->getMessage());
|
|
} catch (\RuntimeException $e) {
|
|
$msg = class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardError')
|
|
? \addons\shopro_huifu\library\onboard\HuifuOnboardError::translate($e->getMessage())
|
|
: $e->getMessage();
|
|
$this->error($msg);
|
|
}
|
|
|
|
if (!$did) {
|
|
$this->error('当前状态不可提交进件资料');
|
|
}
|
|
|
|
$msg = $resubmit
|
|
? '汇付进件已重新提交,请耐心等待审核'
|
|
: '进件资料已提交,请等待后台审核;审核通过后将自动提交汇付';
|
|
$this->success($msg, $this->resolveWalletOnboard($userId));
|
|
}
|
|
|
|
protected function resolveWalletOnboard($userId)
|
|
{
|
|
if (!class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')) {
|
|
return ['show' => false, 'required' => false];
|
|
}
|
|
|
|
$required = \addons\shopro_huifu\library\onboard\HuifuOnboardGate::isOnboardRequired();
|
|
if (!$required) {
|
|
return ['show' => false, 'required' => false];
|
|
}
|
|
|
|
$bindings = $this->collectOnboardBindings($userId);
|
|
if (!$bindings) {
|
|
return ['show' => false, 'required' => $required, 'role_labels' => []];
|
|
}
|
|
|
|
$primary = null;
|
|
foreach ($bindings as $binding) {
|
|
$huifu = $binding['huifu_onboard'];
|
|
if (!empty($huifu['can_submit']) || !empty($huifu['can_save_draft'])) {
|
|
$primary = $binding;
|
|
break;
|
|
}
|
|
if (($huifu['status'] ?? '') !== 'approved' && !$primary) {
|
|
$primary = $binding;
|
|
}
|
|
}
|
|
if (!$primary) {
|
|
$primary = $bindings[0];
|
|
}
|
|
|
|
$huifu = $primary['huifu_onboard'];
|
|
$show = false;
|
|
$canSubmitBind = false;
|
|
foreach ($bindings as $binding) {
|
|
$item = $binding['huifu_onboard'];
|
|
$approved = ($item['status'] ?? '') === 'approved';
|
|
if (!$approved) {
|
|
$show = true;
|
|
}
|
|
if (!empty($item['can_submit']) || !empty($item['can_save_draft'])) {
|
|
$show = true;
|
|
$canSubmitBind = true;
|
|
}
|
|
}
|
|
|
|
$config = [
|
|
'account_types' => [
|
|
['value' => 'indv', 'label' => '个人'],
|
|
['value' => 'ent', 'label' => '个体户/企业'],
|
|
],
|
|
'bank_account_types' => [
|
|
['value' => '0', 'label' => '对私'],
|
|
['value' => '1', 'label' => '对公'],
|
|
],
|
|
];
|
|
|
|
return [
|
|
'show' => $show,
|
|
'required' => true,
|
|
'role_labels' => array_column($bindings, 'role_label'),
|
|
'role_type' => $primary['role_type'],
|
|
'huifu_onboard' => $huifu,
|
|
'can_submit_bind' => $canSubmitBind,
|
|
'onboard_config' => $config,
|
|
];
|
|
}
|
|
|
|
protected function collectOnboardBindings($userId)
|
|
{
|
|
if (!class_exists('\\addons\\shopro_huifu\\library\\onboard\\HuifuOnboardGate')) {
|
|
return [];
|
|
}
|
|
|
|
$bindings = [];
|
|
$promoterStatuses = ['normal', 'pending', 'needinfo', 'freeze', 'reject'];
|
|
|
|
$commissionAgent = \addons\shopro\model\commission\Agent::where('user_id', $userId)->find();
|
|
if ($commissionAgent && in_array($commissionAgent['status'], $promoterStatuses, true)) {
|
|
$onboardRow = \addons\shopro_huifu\model\Onboard::findByRole($userId, 'promoter', $userId);
|
|
$bindings[] = [
|
|
'role_type' => 'promoter',
|
|
'role_ref_id' => $userId,
|
|
'role_label' => '分销商',
|
|
'huifu_onboard' => \addons\shopro_huifu\library\onboard\HuifuOnboardGate::publicStatus(
|
|
$onboardRow,
|
|
$userId,
|
|
'promoter',
|
|
$userId,
|
|
$commissionAgent['status'] ?? ''
|
|
),
|
|
];
|
|
}
|
|
|
|
$regionalAgents = \addons\shopro\model\regional_agent\Agent::where('user_id', $userId)
|
|
->where('status', 'in', ['normal', 'pending'])
|
|
->order('id desc')
|
|
->select();
|
|
foreach ($regionalAgents as $regionalAgent) {
|
|
$onboardRow = \addons\shopro_huifu\model\Onboard::findByRole($userId, 'regional_agent', $regionalAgent['id']);
|
|
$bindings[] = [
|
|
'role_type' => 'regional_agent',
|
|
'role_ref_id' => $regionalAgent['id'],
|
|
'role_label' => '区域公司',
|
|
'huifu_onboard' => \addons\shopro_huifu\library\onboard\HuifuOnboardGate::publicStatus(
|
|
$onboardRow,
|
|
$userId,
|
|
'regional_agent',
|
|
$regionalAgent['id'],
|
|
$regionalAgent['status'] ?? ''
|
|
),
|
|
];
|
|
}
|
|
|
|
return $bindings;
|
|
}
|
|
}
|