比较提交
2 次代码提交
fd14b701c3
...
73efa1a7eb
| 作者 | SHA1 | 提交日期 | |
|---|---|---|---|
|
|
73efa1a7eb | ||
|
|
fa8d57693b |
@@ -46,6 +46,13 @@
|
||||
<el-form-item label="结算周期"><el-input v-model="form.onboard_settle_cycle" placeholder="D1"></el-input></el-form-item>
|
||||
<el-form-item label="结算批次号"><el-input v-model="form.onboard_settle_batch_no"></el-input></el-form-item>
|
||||
<el-form-item label="进件通知URL"><el-input v-model="form.onboard_notify_url" readonly></el-input></el-form-item>
|
||||
<el-form-item label="自动提交进件">
|
||||
<el-switch v-model="form.onboard_auto_submit" active-value="1" inactive-value="0"></el-switch>
|
||||
<span class="text-muted" style="font-size:12px;margin-left:8px;">需配置 crontab: shopro_huifu:onboard-auto-submit</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="失败重提间隔(小时)">
|
||||
<el-input v-model="form.onboard_auto_retry_hours" placeholder="24" style="width:120px"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">只读</el-divider>
|
||||
<el-form-item label="支付通知URL"><el-input v-model="form.notify_url" readonly></el-input></el-form-item>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="panel panel-default panel-intro">
|
||||
<div class="panel-heading">
|
||||
汇付个人进件
|
||||
<span class="text-muted" style="font-size:12px;margin-left:12px;">先审核进件资料,业务审核通过后再提交汇付</span>
|
||||
<span class="text-muted" style="font-size:12px;margin-left:12px;">业务审核通过后由定时任务自动提交汇付;失败满 24 小时自动重提(可手动「提交汇付/重提」)</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div style="margin-bottom:12px;">
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_huifu\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 小程序发货管理 + 汇付延时分账:冻结/解冻链路只读诊断(需在已配置 .env 的服务器执行)
|
||||
*/
|
||||
class DiagnoseFreezeFlow extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('shopro_huifu:diagnose-freeze-flow')
|
||||
->addOption('days', null, Option::VALUE_OPTIONAL, '统计近 N 天订单,默认 30', 30)
|
||||
->addOption('limit', null, Option::VALUE_OPTIONAL, '明细条数上限,默认 15', 15)
|
||||
->setDescription('Diagnose order_auto_confirm, wechat shipping sync, split_timing vs FREEZE/23000004');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$days = max(1, intval($input->getOption('days')));
|
||||
$limit = max(5, intval($input->getOption('limit')));
|
||||
$since = time() - ($days * 86400);
|
||||
|
||||
$output->writeln('=== 汇付/微信发货冻结链路诊断(只读)===');
|
||||
$output->writeln('统计近 ' . $days . ' 天 · 明细最多 ' . $limit . ' 条');
|
||||
$output->writeln('');
|
||||
|
||||
$this->sectionOrderAutoConfirm($output);
|
||||
$this->sectionSplitTiming($output);
|
||||
$this->sectionWechatTrade($output);
|
||||
if ($this->tableExists('shopro_wechat_trade_sync')) {
|
||||
$this->sectionWechatSyncStats($output, $since);
|
||||
$this->sectionWechatSyncFailures($output, $since, $limit);
|
||||
$this->sectionShippedNoWechatSync($output, $since, $limit);
|
||||
$this->sectionConfirmGap($output, $since, $limit);
|
||||
} else {
|
||||
$output->writeln('[SKIP] 表 shopro_wechat_trade_sync 不存在 → 请安装/启用 shopro_wechat_trade');
|
||||
$output->writeln(' php think shopro_wechat_trade:install');
|
||||
}
|
||||
|
||||
if ($this->tableExists('shopro_split_order')) {
|
||||
$this->sectionSplitFailures($output, $since, $limit);
|
||||
$this->sectionTimingMismatch($output);
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
$output->writeln('=== 解读提示 ===');
|
||||
$output->writeln('· 小程序实物快递:须真实发货 + upload_shipping_info 成功,再 confirm(用户/自动收货)');
|
||||
$output->writeln('· split_timing=payed + 延时分账 + 微信 FREEZE → 易出现 23000004,建议改为 confirm 或 finish');
|
||||
$output->writeln('· 失败同步:php think shopro_wechat_trade:retry-failed');
|
||||
$output->writeln('· 单笔汇付查单:后台分账订单详情或 split_commission_verify.php');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function sectionOrderAutoConfirm(Output $output)
|
||||
{
|
||||
$output->writeln('--- 1. 商城自动确认收货 (shopro_config.name=order) ---');
|
||||
if (!$this->tableExists('shopro_config')) {
|
||||
$output->writeln('[FAIL] 无 shopro_config 表');
|
||||
return;
|
||||
}
|
||||
$row = Db::name('shopro_config')->where('name', 'order')->find();
|
||||
if (!$row) {
|
||||
$output->writeln('[WARN] 未找到 order 配置,发货后默认 10 天自动确认(见 Send.php)');
|
||||
return;
|
||||
}
|
||||
$cfg = json_decode($row['value'] ?? '', true);
|
||||
if (!is_array($cfg)) {
|
||||
$output->writeln('[WARN] order 配置非 JSON');
|
||||
return;
|
||||
}
|
||||
$days = isset($cfg['order_auto_confirm']) ? trim((string) $cfg['order_auto_confirm']) : '';
|
||||
$output->writeln('order_auto_confirm(天): ' . ($days !== '' ? $days : '(空,代码默认 10)'));
|
||||
if ($days === '0' || $days === 0) {
|
||||
$output->writeln('[WARN] 设为 0 不会立即确认,仍走默认 10 天');
|
||||
}
|
||||
$output->writeln('order_auto_close(天): ' . ($cfg['order_auto_close'] ?? '-'));
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionSplitTiming(Output $output)
|
||||
{
|
||||
$output->writeln('--- 2. 汇付延时分账时机 ---');
|
||||
if (!$this->tableExists('shopro_split_config')) {
|
||||
$output->writeln('[SKIP] 无 shopro_split_config');
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
$names = [
|
||||
'split_enable', 'split_mode', 'split_timing', 'delay_acct_enable', 'platform_huifu_id',
|
||||
];
|
||||
$rows = Db::name('shopro_split_config')->where('name', 'in', $names)->select();
|
||||
$map = [];
|
||||
foreach ($rows as $r) {
|
||||
$map[$r['name']] = $r['value'];
|
||||
}
|
||||
foreach ($names as $n) {
|
||||
$output->writeln($n . ': ' . ($map[$n] ?? '(未配置)'));
|
||||
}
|
||||
$timing = $map['split_timing'] ?? 'payed';
|
||||
$delay = ($map['delay_acct_enable'] ?? '0') === '1';
|
||||
$enable = ($map['split_enable'] ?? '0') === '1';
|
||||
if ($enable && $delay && in_array($timing, ['payed', 'pay'], true)) {
|
||||
$output->writeln('[WARN] split_timing=' . $timing . ' + delay_acct_enable=1 + 小程序 → 支付后立即分账易遇 FREEZE/23000004');
|
||||
$output->writeln(' 建议:后台分账配置改为 confirm 或 finish');
|
||||
}
|
||||
if ($this->tableExists('shopro_huifu_config')) {
|
||||
$hf = Db::name('shopro_huifu_config')->where('name', 'miniprogram_channel')->value('value');
|
||||
$st = Db::name('shopro_huifu_config')->where('name', 'status')->value('value');
|
||||
$output->writeln('huifu miniprogram_channel: ' . ($hf ?: '-'));
|
||||
$output->writeln('huifu plugin status: ' . ($st ?: '-'));
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionWechatTrade(Output $output)
|
||||
{
|
||||
$output->writeln('--- 3. 微信交易合规插件 ---');
|
||||
$info = function_exists('get_addon_info') ? get_addon_info('shopro_wechat_trade') : [];
|
||||
$state = intval($info['state'] ?? 0);
|
||||
$output->writeln('插件 state: ' . ($state === 1 ? '1 (启用)' : $state . ' (未启用)'));
|
||||
if ($this->tableExists('shopro_wechat_trade_config')) {
|
||||
$en = Db::name('shopro_wechat_trade_config')->where('name', 'wechat_trade_enable')->value('value');
|
||||
$output->writeln('wechat_trade_enable: ' . ($en ?? '-'));
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionWechatSyncStats(Output $output, $since)
|
||||
{
|
||||
$output->writeln('--- 4. 微信发货/确认同步统计(createtime >= ' . date('Y-m-d', $since) . ')---');
|
||||
$rows = Db::query(
|
||||
'SELECT sync_type, status, COUNT(*) AS cnt FROM ' . $this->table('shopro_wechat_trade_sync')
|
||||
. ' WHERE createtime >= ? GROUP BY sync_type, status ORDER BY sync_type, status',
|
||||
[$since]
|
||||
);
|
||||
if (!$rows) {
|
||||
$output->writeln('(无记录)');
|
||||
} else {
|
||||
foreach ($rows as $r) {
|
||||
$output->writeln(sprintf(' %s / %s: %d', $r['sync_type'], $r['status'], $r['cnt']));
|
||||
}
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionWechatSyncFailures(Output $output, $since, $limit)
|
||||
{
|
||||
$output->writeln('--- 5. 最近失败的微信同步(最多 ' . $limit . ' 条)---');
|
||||
$rows = Db::name('shopro_wechat_trade_sync')
|
||||
->where('createtime', '>=', $since)
|
||||
->where('status', '<>', 'success')
|
||||
->order('id', 'desc')
|
||||
->limit($limit)
|
||||
->select();
|
||||
if (!$rows) {
|
||||
$output->writeln('(无失败/pending 记录)');
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
foreach ($rows as $r) {
|
||||
$output->writeln(sprintf(
|
||||
'#%d order_id=%s sn=%s type=%s status=%s err=%s %s',
|
||||
$r['id'],
|
||||
$r['order_id'],
|
||||
$r['order_sn'],
|
||||
$r['sync_type'],
|
||||
$r['status'],
|
||||
$r['errcode'] ?? '',
|
||||
mb_substr((string) ($r['errmsg'] ?? ''), 0, 80)
|
||||
));
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionShippedNoWechatSync(Output $output, $since, $limit)
|
||||
{
|
||||
$output->writeln('--- 6. 已发货但未成功 upload_shipping(小程序汇付/微信,最多 ' . $limit . ' 单)---');
|
||||
$prefix = config('database.prefix');
|
||||
$sql = "SELECT o.id, o.order_sn, o.status, o.pay_type, MAX(oi.dispatch_status) AS max_dispatch
|
||||
FROM {$prefix}shopro_order o
|
||||
INNER JOIN {$prefix}shopro_order_item oi ON oi.order_id = o.id
|
||||
LEFT JOIN {$prefix}shopro_wechat_trade_sync ws ON ws.order_id = o.id AND ws.sync_type = 'shipping' AND ws.status = 'success'
|
||||
WHERE o.platform = 'wxMiniProgram'
|
||||
AND o.pay_type IN ('wechat','huifu_wechat')
|
||||
AND o.status > 0
|
||||
AND o.createtime >= ?
|
||||
AND oi.dispatch_status >= 1
|
||||
AND ws.id IS NULL
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC
|
||||
LIMIT " . intval($limit);
|
||||
try {
|
||||
$rows = Db::query($sql, [$since]);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('[ERR] ' . $e->getMessage());
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
if (!$rows) {
|
||||
$output->writeln('(未发现:已发货单均有 shipping success,或未命中条件)');
|
||||
} else {
|
||||
foreach ($rows as $r) {
|
||||
$output->writeln(sprintf(' order#%s %s pay=%s status=%s', $r['id'], $r['order_sn'], $r['pay_type'], $r['status']));
|
||||
}
|
||||
$output->writeln('[ACTION] php think shopro_wechat_trade:backfill 或后台补发货同步');
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionConfirmGap(Output $output, $since, $limit)
|
||||
{
|
||||
$output->writeln('--- 7. 已全部收货但未成功 notify_confirm(最多 ' . $limit . ' 单)---');
|
||||
$prefix = config('database.prefix');
|
||||
$got = 2; // DISPATCH_STATUS_GETED — 与 OrderItem 常量一致
|
||||
$sql = "SELECT o.id, o.order_sn, o.pay_type
|
||||
FROM {$prefix}shopro_order o
|
||||
INNER JOIN {$prefix}shopro_order_item oi ON oi.order_id = o.id
|
||||
LEFT JOIN {$prefix}shopro_wechat_trade_sync wc ON wc.order_id = o.id AND wc.sync_type = 'confirm' AND wc.status = 'success'
|
||||
WHERE o.platform = 'wxMiniProgram'
|
||||
AND o.pay_type IN ('wechat','huifu_wechat')
|
||||
AND o.status > 0
|
||||
AND o.createtime >= ?
|
||||
AND wc.id IS NULL
|
||||
GROUP BY o.id
|
||||
HAVING MIN(oi.dispatch_status) >= {$got}
|
||||
ORDER BY o.id DESC
|
||||
LIMIT " . intval($limit);
|
||||
try {
|
||||
$rows = Db::query($sql, [$since]);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('[ERR] ' . $e->getMessage());
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
if (!$rows) {
|
||||
$output->writeln('(无缺口,或尚无全部收货订单)');
|
||||
} else {
|
||||
foreach ($rows as $r) {
|
||||
$output->writeln(sprintf(' order#%s %s pay=%s', $r['id'], $r['order_sn'], $r['pay_type']));
|
||||
}
|
||||
$output->writeln('[ACTION] 确认 shopro_wechat_trade 已开;可在后台订单确认收货或 retry-failed');
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionSplitFailures(Output $output, $since, $limit)
|
||||
{
|
||||
$output->writeln('--- 8. 分账失败/待重试(含 23000004 / FREEZE 关键词,最多 ' . $limit . ' 条)---');
|
||||
$rows = Db::name('shopro_split_order')
|
||||
->where('createtime', '>=', $since)
|
||||
->where(function ($q) {
|
||||
$q->where('status', 4)
|
||||
->whereOr('wx_result', 'like', '%23000004%')
|
||||
->whereOr('wx_result', 'like', '%FREEZE%')
|
||||
->whereOr('wx_result', 'like', '%fund_freeze%');
|
||||
})
|
||||
->order('id', 'desc')
|
||||
->limit($limit)
|
||||
->select();
|
||||
if (!$rows) {
|
||||
$output->writeln('(近 ' . $limit . ' 条内无典型失败;可后台查看分账订单列表 status=4)');
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
foreach ($rows as $r) {
|
||||
$snippet = mb_substr(preg_replace('/\s+/', ' ', (string) ($r['wx_result'] ?? '')), 0, 120);
|
||||
$output->writeln(sprintf(
|
||||
'#%d order_sn=%s status=%s amount=%s %s',
|
||||
$r['id'],
|
||||
$r['order_sn'] ?? '',
|
||||
$r['status'] ?? '',
|
||||
$r['split_amount'] ?? '',
|
||||
$snippet
|
||||
));
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function sectionTimingMismatch(Output $output)
|
||||
{
|
||||
$output->writeln('--- 9. 分账时机 vs 分销结算(是否「支付就分、佣金却等确认」)---');
|
||||
if (!$this->tableExists('shopro_commission_config')) {
|
||||
$output->writeln('[SKIP] 无 commission 配置表');
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
$splitTiming = Db::name('shopro_split_config')->where('name', 'split_timing')->value('value') ?: 'payed';
|
||||
$commEvent = Db::name('shopro_commission_config')->where('name', 'commission_event')->value('value') ?: 'confirm';
|
||||
$output->writeln('split_timing: ' . $splitTiming);
|
||||
$output->writeln('commission_event: ' . $commEvent);
|
||||
if (in_array($splitTiming, ['payed', 'pay'], true) && in_array($commEvent, ['confirm', 'finish', 'completed'], true)) {
|
||||
$output->writeln('[INFO] 分账早于佣金结算事件,小程序 FREEZE 时更明显;建议 split_timing 与 commission_event 对齐为 confirm');
|
||||
}
|
||||
$output->writeln('');
|
||||
}
|
||||
|
||||
protected function tableExists($name)
|
||||
{
|
||||
try {
|
||||
Db::name($name)->limit(1)->select();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function table($name)
|
||||
{
|
||||
return config('database.prefix') . $name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_huifu\command;
|
||||
|
||||
use addons\shopro_huifu\library\onboard\HuifuOnboardAutoSubmit;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class OnboardAutoSubmit extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('shopro_huifu:onboard-auto-submit')
|
||||
->addOption('limit', 'l', Option::VALUE_OPTIONAL, '每轮最多处理条数', 30)
|
||||
->addOption('dry-run', null, Option::VALUE_NONE, '只扫描不调用汇付')
|
||||
->setDescription('Auto submit Huifu onboard: new drafts immediately, failed retry after cooldown');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$dryRun = (bool) $input->getOption('dry-run');
|
||||
$limit = intval($input->getOption('limit'));
|
||||
$output->writeln('=== 汇付进件自动提交 ===' . ($dryRun ? ' [dry-run]' : ''));
|
||||
|
||||
$stats = (new HuifuOnboardAutoSubmit())->run($limit, $dryRun);
|
||||
$output->writeln('扫描: ' . $stats['scanned']);
|
||||
$output->writeln('首次提交: ' . $stats['submit_now']);
|
||||
$output->writeln('失败重提: ' . $stats['retry']);
|
||||
$output->writeln('跳过: ' . $stats['skipped']);
|
||||
$output->writeln('执行失败: ' . $stats['failed']);
|
||||
foreach ($stats['details'] as $line) {
|
||||
$output->writeln(' · ' . $line);
|
||||
}
|
||||
|
||||
return $stats['failed'] > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
-- 小程序发货 + 汇付冻结链路 · 只读诊断(表前缀默认 fa_)
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
SELECT '=== order 自动确认收货 ===' AS section;
|
||||
SELECT value FROM fa_shopro_config WHERE name = 'order' LIMIT 1;
|
||||
|
||||
SELECT '=== 分账/延时分账 ===' AS section;
|
||||
SELECT name, value FROM fa_shopro_split_config
|
||||
WHERE name IN ('split_enable','split_mode','split_timing','delay_acct_enable','platform_huifu_id')
|
||||
ORDER BY name;
|
||||
|
||||
SELECT '=== 微信交易合规 ===' AS section;
|
||||
SELECT name, value FROM fa_shopro_wechat_trade_config WHERE name = 'wechat_trade_enable';
|
||||
|
||||
SELECT '=== 近30天 微信同步统计 ===' AS section;
|
||||
SELECT sync_type, status, COUNT(*) cnt
|
||||
FROM fa_shopro_wechat_trade_sync
|
||||
WHERE createtime >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))
|
||||
GROUP BY sync_type, status;
|
||||
|
||||
SELECT '=== 近30天 已发货无 shipping success(前15单)===' AS section;
|
||||
SELECT o.id, o.order_sn, o.pay_type
|
||||
FROM fa_shopro_order o
|
||||
INNER JOIN fa_shopro_order_item oi ON oi.order_id = o.id
|
||||
LEFT JOIN fa_shopro_wechat_trade_sync ws
|
||||
ON ws.order_id = o.id AND ws.sync_type = 'shipping' AND ws.status = 'success'
|
||||
WHERE o.platform = 'wxMiniProgram'
|
||||
AND o.pay_type IN ('wechat','huifu_wechat')
|
||||
AND o.status > 0
|
||||
AND o.createtime >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))
|
||||
AND oi.dispatch_status >= 1
|
||||
AND ws.id IS NULL
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC
|
||||
LIMIT 15;
|
||||
|
||||
SELECT '=== 近30天 分账失败/23000004(前15条)===' AS section;
|
||||
SELECT id, order_sn, status, split_amount, LEFT(wx_result, 200) AS wx_result_snip
|
||||
FROM fa_shopro_split_order
|
||||
WHERE createtime >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))
|
||||
AND (status = 4 OR wx_result LIKE '%23000004%' OR wx_result LIKE '%FREEZE%')
|
||||
ORDER BY id DESC
|
||||
LIMIT 15;
|
||||
@@ -105,5 +105,7 @@ INSERT IGNORE INTO `__PREFIX__shopro_huifu_config` (`name`, `value`, `group`, `d
|
||||
('onboard_cash_type', 'D1', 'onboard', '取现类型'),
|
||||
('onboard_cash_fix_amt', '0.03', 'onboard', '取现固定手续费'),
|
||||
('onboard_cash_fee_rate', '0', 'onboard', '取现费率'),
|
||||
('onboard_skill_source', 'hfps/1.3.5;hfms/1.0.2', 'onboard', '进件SDK skill_source');
|
||||
('onboard_skill_source', 'hfps/1.3.5;hfms/1.0.2', 'onboard', '进件SDK skill_source'),
|
||||
('onboard_auto_submit', '1', 'onboard', '定时自动提交汇付进件(0关1开)'),
|
||||
('onboard_auto_retry_hours', '24', 'onboard', '进件失败后自动重提间隔(小时)');
|
||||
|
||||
|
||||
@@ -302,6 +302,15 @@ class HuifuOnboardAdminView
|
||||
return $parts ? implode('、', $parts) : '无进件角色';
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销/区域公司业务审核是否已通过(status=normal)
|
||||
*/
|
||||
public static function isBusinessApproved(array $data)
|
||||
{
|
||||
$biz = self::businessStatus($data);
|
||||
return ($biz['status'] ?? '') === 'normal';
|
||||
}
|
||||
|
||||
protected static function businessStatus(array $data)
|
||||
{
|
||||
$roleType = $data['role_type'] ?? '';
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro_huifu\library\onboard;
|
||||
|
||||
use addons\shopro_huifu\library\HuifuConfig;
|
||||
use addons\shopro_huifu\model\Onboard;
|
||||
use think\Log;
|
||||
|
||||
/**
|
||||
* 汇付进件后台自动提交:业务已通过且从未提交汇付的立即提交;失败/驳回满冷却期后重提。
|
||||
*/
|
||||
class HuifuOnboardAutoSubmit
|
||||
{
|
||||
public function run($limit = 30, $dryRun = false)
|
||||
{
|
||||
$stats = [
|
||||
'scanned' => 0,
|
||||
'submit_now' => 0,
|
||||
'retry' => 0,
|
||||
'skipped' => 0,
|
||||
'failed' => 0,
|
||||
'details' => [],
|
||||
];
|
||||
|
||||
if (!HuifuOnboardGate::isOnboardRequired()) {
|
||||
$stats['details'][] = 'skip: 汇付进件未启用';
|
||||
return $stats;
|
||||
}
|
||||
|
||||
if (!$this->isAutoSubmitEnabled()) {
|
||||
$stats['details'][] = 'skip: onboard_auto_submit=0';
|
||||
return $stats;
|
||||
}
|
||||
|
||||
$limit = max(1, min(100, (int) $limit));
|
||||
$retryAfter = $this->getRetryAfterSeconds();
|
||||
$service = new HuifuOnboardService();
|
||||
$now = time();
|
||||
|
||||
$rows = Onboard::where('onboard_status', 'in', [
|
||||
Onboard::STATUS_DRAFT,
|
||||
Onboard::STATUS_FAILED,
|
||||
Onboard::STATUS_REJECTED,
|
||||
])->order('id asc')->limit($limit * 3)->select();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($stats['submit_now'] + $stats['retry'] >= $limit) {
|
||||
break;
|
||||
}
|
||||
$stats['scanned']++;
|
||||
$data = $row->toArray();
|
||||
$action = $this->resolveAction($data, $now, $retryAfter);
|
||||
if ($action === null) {
|
||||
$stats['skipped']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload = json_decode($row['payload'] ?? '', true);
|
||||
if (!$payload || !is_array($payload)) {
|
||||
$stats['skipped']++;
|
||||
$stats['details'][] = 'id=' . $row['id'] . ' skip: 无进件资料 payload';
|
||||
continue;
|
||||
}
|
||||
|
||||
$line = 'id=' . $row['id'] . ' uid=' . $row['user_id'] . ' ' . $row['role_type']
|
||||
. ' action=' . $action;
|
||||
if ($dryRun) {
|
||||
$stats[$action === 'submit_now' ? 'submit_now' : 'retry']++;
|
||||
$stats['details'][] = $line . ' (dry-run)';
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
if ($action === 'submit_now') {
|
||||
$service->submitFromDraft($row['user_id'], $row['role_type'], $row['role_ref_id']);
|
||||
$stats['submit_now']++;
|
||||
} else {
|
||||
$service->resubmit($row['user_id'], $row['role_type'], $row['role_ref_id'], $payload);
|
||||
$stats['retry']++;
|
||||
}
|
||||
$stats['details'][] = $line . ' ok';
|
||||
} catch (\Throwable $e) {
|
||||
$stats['failed']++;
|
||||
$msg = HuifuOnboardError::translate($e->getMessage());
|
||||
Log::error('[shopro_huifu] onboard auto-submit fail ' . $line . ' ' . $e->getMessage());
|
||||
$stats['details'][] = $line . ' fail: ' . $msg;
|
||||
}
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null submit_now|retry
|
||||
*/
|
||||
protected function resolveAction(array $data, $now, $retryAfter)
|
||||
{
|
||||
if (!HuifuOnboardAdminView::isBusinessApproved($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$status = (string) ($data['onboard_status'] ?? '');
|
||||
$updatedAt = intval($data['updatetime'] ?? 0);
|
||||
|
||||
if ($status === Onboard::STATUS_DRAFT) {
|
||||
if ($this->hasSubmittedToHuifu($data)) {
|
||||
return null;
|
||||
}
|
||||
return 'submit_now';
|
||||
}
|
||||
|
||||
if (in_array($status, [Onboard::STATUS_FAILED, Onboard::STATUS_REJECTED], true)) {
|
||||
if ($updatedAt <= 0 || ($now - $updatedAt) < $retryAfter) {
|
||||
return null;
|
||||
}
|
||||
return 'retry';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function hasSubmittedToHuifu(array $data)
|
||||
{
|
||||
if (!empty($data['basic_req_seq_id']) || !empty($data['busi_req_seq_id'])) {
|
||||
return true;
|
||||
}
|
||||
if (!empty($data['huifu_id'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function isAutoSubmitEnabled()
|
||||
{
|
||||
return HuifuConfig::getInstance()->get('onboard_auto_submit', '1') !== '0';
|
||||
}
|
||||
|
||||
protected function getRetryAfterSeconds()
|
||||
{
|
||||
$hours = (float) HuifuConfig::getInstance()->get('onboard_auto_retry_hours', '24');
|
||||
if ($hours <= 0) {
|
||||
$hours = 24;
|
||||
}
|
||||
return (int) round($hours * 3600);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,9 @@ define(['jquery', 'bootstrap', 'backend', 'form'], function ($, undefined, Backe
|
||||
onboard_settle_cycle: 'D1',
|
||||
onboard_settle_batch_no: '300',
|
||||
onboard_settle_fee_rate: '0.05',
|
||||
onboard_notify_url: ''
|
||||
onboard_notify_url: '',
|
||||
onboard_auto_submit: '1',
|
||||
onboard_auto_retry_hours: '24'
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
-- 汇付进件自动提交配置(已有站点执行一次)
|
||||
INSERT IGNORE INTO `__PREFIX__shopro_huifu_config` (`name`, `value`, `group`, `description`) VALUES
|
||||
('onboard_auto_submit', '1', 'onboard', '定时自动提交汇付进件(0关1开)'),
|
||||
('onboard_auto_retry_hours', '24', 'onboard', '进件失败后自动重提间隔(小时)');
|
||||
@@ -52,6 +52,13 @@
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="进件通知URL"><el-input v-model="form.onboard_notify_url" readonly></el-input></el-form-item>
|
||||
<el-form-item label="自动提交进件">
|
||||
<el-switch v-model="form.onboard_auto_submit" active-value="1" inactive-value="0"></el-switch>
|
||||
<span class="text-muted" style="font-size:12px;margin-left:8px;">需配置 crontab: shopro_huifu:onboard-auto-submit</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="失败重提间隔(小时)">
|
||||
<el-input v-model="form.onboard_auto_retry_hours" placeholder="24" style="width:120px"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">只读</el-divider>
|
||||
<el-form-item label="支付通知URL"><el-input v-model="form.notify_url" readonly></el-input></el-form-item>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="panel panel-default panel-intro">
|
||||
<div class="panel-heading">
|
||||
汇付个人进件
|
||||
<span class="text-muted" style="font-size:12px;margin-left:12px;">先审核进件资料,业务审核通过后再提交汇付</span>
|
||||
<span class="text-muted" style="font-size:12px;margin-left:12px;">业务审核通过后由定时任务自动提交汇付;失败满 24 小时自动重提(可手动「提交汇付/重提」)</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div style="margin-bottom:12px;">
|
||||
|
||||
@@ -25,7 +25,9 @@ return [
|
||||
'addons\shopro_huifu\command\TestPayConnection',
|
||||
'addons\shopro_huifu\command\ProbeWechatOnboarding',
|
||||
'addons\shopro_huifu\command\QuerySplitConfig',
|
||||
'addons\shopro_huifu\command\DiagnoseFreezeFlow',
|
||||
'addons\shopro_huifu\command\OnboardPoll',
|
||||
'addons\shopro_huifu\command\OnboardAutoSubmit',
|
||||
'addons\shopro_huifu\command\ImportBankBranch',
|
||||
'addons\shopro_wechat_trade\command\InitOrderPath',
|
||||
'addons\shopro_wechat_trade\command\ProbeOrderPath',
|
||||
|
||||
@@ -24,7 +24,9 @@ define(['jquery', 'bootstrap', 'backend', 'form'], function ($, undefined, Backe
|
||||
onboard_required: '1',
|
||||
onboard_settle_cycle: 'D1',
|
||||
onboard_settle_batch_no: '300',
|
||||
onboard_notify_url: ''
|
||||
onboard_notify_url: '',
|
||||
onboard_auto_submit: '1',
|
||||
onboard_auto_retry_hours: '24'
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
|
||||
在新工单中引用
屏蔽一个用户