feat(shopro_huifu): 添加分账扩展材料上传功能并优化图片处理 - 新增 UploadSplitExtendedMaterials 命令用于上传 F469/F330 等分账补充材料 - 优化 ProbeSplitConfigDeps 命令中扩展材料配置的检查逻辑 - 支持 PDF 文件上传,增加文件大小限制(PDF 5MB,图片 2MB) - 修复 MCC 编码可作为 online_busi_type 备选值的问题 ```
120 行
4.8 KiB
PHP
120 行
4.8 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_huifu\command;
|
||
|
||
use addons\shopro_huifu\library\Bridge;
|
||
use addons\shopro_huifu\library\HuifuConfig;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardPicture;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\input\Option;
|
||
use think\console\Output;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 上传 split/config 补充材料 extended_material_list(如 H5921L 要求的 F469/F330)
|
||
*/
|
||
class UploadSplitExtendedMaterials extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('shopro_huifu:upload-split-ext-materials')
|
||
->addOption('f469-url', null, Option::VALUE_OPTIONAL, 'F469 分账配置-服务佣金相关协议(pdf/jpg/png URL)')
|
||
->addOption('f330-url', null, Option::VALUE_OPTIONAL, 'F330 食品经营许可证(pdf/jpg/png URL)')
|
||
->addOption('file-type', null, Option::VALUE_OPTIONAL, '自定义:格式 F469=https://... 可多次传')
|
||
->addOption('online-busi-type', null, Option::VALUE_OPTIONAL, '一并写入 split_config_online_busi_type,如 H5921L')
|
||
->addOption('save-config', null, Option::VALUE_NONE, '写入 split_config_extended_material_json')
|
||
->setDescription('Upload F469/F330 etc. for split/config extended_material_list');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
if (!Bridge::isEnabled()) {
|
||
$output->writeln('[FAIL] 汇付插件未启用');
|
||
return 1;
|
||
}
|
||
|
||
$tasks = [];
|
||
$f469 = trim((string) $input->getOption('f469-url'));
|
||
$f330 = trim((string) $input->getOption('f330-url'));
|
||
if ($f469 !== '') {
|
||
$tasks['F469'] = $f469;
|
||
}
|
||
if ($f330 !== '') {
|
||
$tasks['F330'] = $f330;
|
||
}
|
||
$custom = trim((string) $input->getOption('file-type'));
|
||
if ($custom !== '' && strpos($custom, '=') !== false) {
|
||
list($ft, $url) = explode('=', $custom, 2);
|
||
$ft = trim($ft);
|
||
$url = trim($url);
|
||
if ($ft !== '' && $url !== '') {
|
||
$tasks[$ft] = $url;
|
||
}
|
||
}
|
||
|
||
if ($tasks === []) {
|
||
$output->writeln('[FAIL] 至少提供 --f469-url 与 --f330-url(酒类 H5921L 分账常见必填)');
|
||
$output->writeln('示例:');
|
||
$output->writeln(' php think shopro_huifu:upload-split-ext-materials \\');
|
||
$output->writeln(' --f469-url=https://域名/多方分账协议.pdf \\');
|
||
$output->writeln(' --f330-url=https://域名/食品经营许可证.pdf \\');
|
||
$output->writeln(' --online-busi-type=H5921L --save-config');
|
||
return 1;
|
||
}
|
||
|
||
$picture = new HuifuOnboardPicture();
|
||
$list = [];
|
||
foreach ($tasks as $fileType => $url) {
|
||
$output->writeln('上传 ' . $fileType . ' ...');
|
||
$fileId = $picture->uploadByUrl($fileType, $url);
|
||
$output->writeln(' file_id: ' . $fileId);
|
||
$list[] = [
|
||
'file_id' => $fileId,
|
||
'file_type' => $fileType,
|
||
];
|
||
}
|
||
|
||
$json = json_encode($list, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||
$output->writeln('');
|
||
$output->writeln('split_config_extended_material_json:');
|
||
$output->writeln($json);
|
||
|
||
if ($input->getOption('save-config')) {
|
||
$this->upsertConfig('split_config_extended_material_json', $json, 'split/config extended_material_list JSON');
|
||
HuifuConfig::reload();
|
||
$output->writeln('[OK] 已写入 split_config_extended_material_json');
|
||
}
|
||
|
||
$busiType = trim((string) $input->getOption('online-busi-type'));
|
||
if ($busiType !== '') {
|
||
if ($input->getOption('save-config')) {
|
||
$this->upsertConfig('split_config_online_busi_type', $busiType, '线上业务类型编码');
|
||
HuifuConfig::reload();
|
||
$output->writeln('[OK] 已写入 split_config_online_busi_type=' . $busiType);
|
||
} else {
|
||
$output->writeln('[提示] 未 --save-config,online_busi_type 未写入库');
|
||
}
|
||
}
|
||
|
||
$output->writeln('');
|
||
$output->writeln('下一步: php think shopro_huifu:sync-split-receivers');
|
||
return 0;
|
||
}
|
||
|
||
protected function upsertConfig($name, $value, $description)
|
||
{
|
||
$row = Db::name('shopro_huifu_config')->where('name', $name)->find();
|
||
if ($row) {
|
||
Db::name('shopro_huifu_config')->where('name', $name)->update(['value' => $value]);
|
||
} else {
|
||
Db::name('shopro_huifu_config')->insert([
|
||
'name' => $name,
|
||
'value' => $value,
|
||
'group' => 'split',
|
||
'description' => $description,
|
||
]);
|
||
}
|
||
}
|
||
}
|