feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_huifu\library\onboard;
|
||||
|
||||
use addons\shopro_huifu\library\Bridge;
|
||||
use addons\shopro_huifu\library\HuifuConfig;
|
||||
use addons\shopro_huifu\model\Onboard;
|
||||
use think\Db;
|
||||
|
||||
class HuifuOnboardGate
|
||||
{
|
||||
/**
|
||||
* 与 shopro split Config::isHuifuMode 同口径,但不依赖核心是否已升级该方法
|
||||
*/
|
||||
public static function isHuifuSplitActive()
|
||||
{
|
||||
try {
|
||||
$split = Db::name('shopro_split_config')->column('value', 'name');
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
if (($split['split_enable'] ?? '0') !== '1') {
|
||||
return false;
|
||||
}
|
||||
$mode = $split['split_mode'] ?? 'wechat';
|
||||
if ($mode === 'huifu' || $mode === 'both') {
|
||||
return true;
|
||||
}
|
||||
$provider = $split['split_provider'] ?? 'auto';
|
||||
if ($provider === 'huifu') {
|
||||
return true;
|
||||
}
|
||||
if ($provider === 'auto') {
|
||||
return Bridge::isHuifuMiniProgramChannel('wxMiniProgram');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isOnboardRequired()
|
||||
{
|
||||
if (!Bridge::isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
if (HuifuConfig::getInstance()->get('onboard_required', '1') === '0') {
|
||||
return false;
|
||||
}
|
||||
return self::isHuifuSplitActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台业务审核通过后触发汇付进件(先审后汇付)
|
||||
*/
|
||||
public static function submitOnBusinessApproved($userId, $roleType, $roleRefId)
|
||||
{
|
||||
if (!self::isOnboardRequired()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$service = new HuifuOnboardService();
|
||||
return $service->submitFromDraft($userId, $roleType, $roleRefId);
|
||||
} catch (\Throwable $e) {
|
||||
\think\Log::error('[shopro_huifu] onboard after admin approve fail uid=' . $userId . ' ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户端是否可重新提交汇付(仅汇付驳回/失败后)
|
||||
*/
|
||||
public static function canSubmitOnboard($userId, $roleType, $roleRefId, $agentStatus = '')
|
||||
{
|
||||
if (!self::isOnboardRequired()) {
|
||||
return false;
|
||||
}
|
||||
$row = Onboard::findByRole($userId, $roleType, $roleRefId);
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
return in_array($row['onboard_status'], [
|
||||
Onboard::STATUS_REJECTED,
|
||||
Onboard::STATUS_FAILED,
|
||||
], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户端是否可保存/更新进件草稿(不调用汇付 API)
|
||||
*/
|
||||
public static function canSaveHuifuDraft($userId, $roleType, $roleRefId, $agentStatus = '')
|
||||
{
|
||||
if (!self::isOnboardRequired()) {
|
||||
return false;
|
||||
}
|
||||
$row = Onboard::findByRole($userId, $roleType, $roleRefId);
|
||||
if ($row && $row['onboard_status'] === Onboard::STATUS_APPROVED) {
|
||||
return false;
|
||||
}
|
||||
if ($row && in_array($row['onboard_status'], [
|
||||
Onboard::STATUS_SUBMITTING,
|
||||
Onboard::STATUS_BASIC_OK,
|
||||
Onboard::STATUS_BUSI_PENDING,
|
||||
], true)) {
|
||||
return false;
|
||||
}
|
||||
if ($row && $row['onboard_status'] === Onboard::STATUS_DRAFT
|
||||
&& in_array($agentStatus, ['pending', 'needinfo', 'reject'], true)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function publicStatus($row, $userId = 0, $roleType = 'promoter', $roleRefId = 0, $agentStatus = '')
|
||||
{
|
||||
$required = self::isOnboardRequired();
|
||||
$canSubmit = $required && $userId && self::canSubmitOnboard($userId, $roleType, $roleRefId, $agentStatus);
|
||||
$canSaveDraft = $required && $userId && self::canSaveHuifuDraft($userId, $roleType, $roleRefId, $agentStatus);
|
||||
$awaitAdmin = $required && $row && $row['onboard_status'] === Onboard::STATUS_DRAFT
|
||||
&& in_array($agentStatus, ['pending', 'needinfo', 'reject'], true);
|
||||
if (!$row) {
|
||||
return [
|
||||
'required' => $required,
|
||||
'can_submit' => $canSubmit,
|
||||
'can_save_draft' => $canSaveDraft,
|
||||
'await_admin' => false,
|
||||
'audit_first' => true,
|
||||
'status' => null,
|
||||
'huifu_id' => '',
|
||||
'reject_reason' => '',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'required' => $required,
|
||||
'can_submit' => $canSubmit,
|
||||
'can_save_draft' => $canSaveDraft,
|
||||
'await_admin' => $awaitAdmin,
|
||||
'audit_first' => true,
|
||||
'status' => $row['onboard_status'],
|
||||
'huifu_id' => $row['huifu_id'] ? substr($row['huifu_id'], 0, 4) . '****' . substr($row['huifu_id'], -4) : '',
|
||||
'reject_reason' => $row['reject_reason'] ?? '',
|
||||
'apply_no' => $row['apply_no'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户