Merge remote-tracking branch 'origin/main' into feature/limeng-quote-management

This commit is contained in:
limeng 2026-08-13 18:45:23 +08:00
commit 7bf44aa3d4
10 changed files with 103 additions and 10 deletions

2
.gitignore vendored
View File

@ -106,6 +106,8 @@ modules/*
*.pem
*.tar
/artifacts/
# 本地私有配置、账号密码和敏感信息文档;禁止使用 git add -f 强制提交。
/runtime/private/敏感信息.md
/runtime/
/.caiwu-build/
.workbuddy/

View File

@ -83,7 +83,8 @@
## 6. 数据与安全红线
- 不得提交 `.env`、密码、Token、SSH 私钥、数据库连接串、真实财务数据、客户数据或生产日志。
- 不得把上述内容粘贴到 AI 对话、工单、PR、聊天群或截图中。
- 项目负责人明确要求时,可以在当前一对一 AI 对话中直接发送其指定的密码或连接信息;只发送完成当前任务所需的范围,不得自动扩散到工单、PR、聊天群、公开摘要或无关日志。
- 本项目使用本地私有文档 `runtime/private/敏感信息.md` 记录需要长期保留的密码、Token、服务器和数据库连接等敏感信息。整个 `runtime/` 已被 `.gitignore` 排除;写入前和提交前必须用 `git check-ignore runtime/private/敏感信息.md` 以及暂存区检查确认它不会进入 Git,禁止使用 `git add -f` 强制添加。
- 不得在不确认环境和影响范围时执行数据库写入、迁移、删除、导入、部署或服务器命令。
- 任何包含金额、账户、登录凭据、权限或数据库连接的信息都按敏感数据处理。
- 发现误提交、泄露或错误操作,立即告知负责人;不要自行删除记录掩盖问题。
@ -142,7 +143,7 @@
### 8.5 发布安全与验收
- SSH 私钥、`runtime/.env`、镜像临时包、数据库密码不得进入 Git 或 Docker 构建上下文。
- 首次服务器初始化由脚本生成数据库密码和 `APP_KEY`,不在终端、聊天或文档中输出。
- 首次服务器初始化由脚本生成数据库密码和 `APP_KEY`,默认只写入服务器私有运行配置和本地 `runtime/private/敏感信息.md`。项目负责人明确要求时可以在当前一对一 AI 对话中提供指定值;不得进入 Git、PR、工单、群聊、公开文档或持久化日志。
- 数据库迁移默认关闭;检测到新增迁移时发布必须停止,获得负责人授权后才可显式开启。
- 新镜像必须先通过本机后端健康检查,再通过公网 HTTPS 页面验收;失败时自动恢复上一个镜像,并保留日志用于排查。
- 生产业务文件统一使用项目唯一的私有七牛桶,固定逻辑盘名为 `uploads`;Access Key 和 Secret Key 只允许存在发布机用户环境、被 Git 忽略的 `runtime/qiniu-business-storage.env` 或服务器 `runtime/qiniu-storage.env`。发布脚本负责首次安全写入服务器私有配置,激活脚本负责读写探测和旧本机上传文件的幂等复制,原件保留用于回滚。新人不得配置对象存储。

View File

@ -13,6 +13,7 @@ use Illuminate\Routing\Controller;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
use Modules\EcommerceFinance\Exceptions\UpstreamSnapshotPendingException;
use Modules\EcommerceFinance\Repositories\AlibabaBillRepository;
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
use Modules\EcommerceFinance\Repositories\InventoryRepository;
@ -248,6 +249,7 @@ class Pages extends Controller
'platform' => $tab,
'balances' => collect(),
'error' => null,
'pending' => false,
];
if (! in_array($tab, ['taobao-alipay', 'pinduoduo'], true)) {
@ -282,6 +284,9 @@ class Pages extends Controller
$pageSize,
),
);
} catch (UpstreamSnapshotPendingException $exception) {
$content['pending'] = true;
$result = ['rows' => [], 'total' => 0];
} catch (ServiceUnavailableHttpException $exception) {
$content['error'] = $exception->getMessage();
$result = ['rows' => [], 'total' => 0];

View File

@ -24,7 +24,7 @@ class TeamSystemDatabaseProfile
* 登录密码。资料必须保留在代码层,避免旧容器的 Laravel 配置缓存
* 缺少新配置项时把新人挡在连接页面。
*/
private const EMBEDDED_PROFILE = 'eyJ2IjoxLCJzYWx0IjoiNE5IZWlPS2ltVUxySUI1NkVYYmJudz09IiwiaXYiOiJ6K1JZT0UwNEFlajR5V0ROIiwidGFnIjoiTTJ2NHo2XC9nemh2K0owK1k2aEVCR2c9PSIsImRhdGEiOiJpcFB4TlZwZzZJbW9JN2lyUjlFSzMxV0hPOGF0aWZXMDhKdWFWZThxSFNWYlpGMlIrRW9oM1FwQnB6VjlybTBEXC9hV2VPbEtzSTI3ek5ZVHBcL1VKRzFBT21hK1wvM3g1ViswSlBQT01SN1FXbjhrWVplUWF0ZWNxYzhDZlZnb1ZsclJ2K1wvenlCT2ZnPT0ifQ==';
private const EMBEDDED_PROFILE = 'eyJ2IjoxLCJzYWx0IjoiSkdEMG5LckgxN3ZUcTRTcVY1N1NEdz09IiwiaXYiOiJoUEQyNmhrSUVPRkh6anpxIiwidGFnIjoib0dcLzVBR241a2ZLV1RxUWdLYVlcLzF3PT0iLCJkYXRhIjoiaFBxMjExdEFwMlZkdnRmVWtWU0h4dlZ2XC9RMmdTWU5jRFlxN1BJSFwvQXJHajVYU0ltbnhFKzRiTTdLaWZqYW1hYXlXNUhWVjR5ZkpYalBkbDV3ajRIWFk5cGFUNXdCZTVlR25qaTFVRGV6SmtHVEM5TUlEeTRqWExRWXBRTnRFVFZiMGFvbWJoIn0=';
public function __construct(private readonly ?string $encodedProfile = null)
{

View File

@ -0,0 +1,16 @@
<?php
namespace Modules\EcommerceFinance\Exceptions;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
class UpstreamSnapshotPendingException extends ServiceUnavailableHttpException
{
public function __construct(int $retryAfter = 15)
{
parent::__construct(
$retryAfter,
'数据同步请求已登记,后台正在准备首份共享数据。'
);
}
}

View File

@ -8,6 +8,7 @@ use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Cache\Lock;
use Illuminate\Contracts\Cache\LockTimeoutException;
use Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Exceptions\UpstreamSnapshotPendingException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Throwable;
@ -102,10 +103,7 @@ class UpstreamQueryCache
$this->register($scope, $parameters, true);
if (! (bool) config('upstreams.snapshots.allow_inline_refresh', false)) {
throw new ServiceUnavailableHttpException(
15,
'数据同步请求已登记,后台正在准备首份共享数据,请稍后刷新。'
);
throw new UpstreamSnapshotPendingException();
}
$resolved = $this->resolve($scope, $parameters, $resolver, false);

View File

@ -24,6 +24,8 @@
.marketing-balance-pagination .page-item.disabled .page-link { color: #595959; cursor: not-allowed; }
.marketing-balance-pagination div.lg\:flex > div:first-child { display: none !important; }
.marketing-balance-pagination div.lg\:flex { justify-content: center; }
.marketing-balance-status { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; border: 1px solid var(--vip-border, #D8D2C7); border-radius: 12px; background: var(--vip-content-accent-soft, #F7F0DE); padding: 12px 14px; color: #513E21; font-size: 0.875rem; line-height: 1.5; }
.marketing-balance-status .material-icons-outlined { flex: 0 0 auto; color: var(--vip-content-accent-dark, #856632); font-size: 14px; }
</style>
<div class="biz-card-head">
@ -71,6 +73,11 @@
@if (! empty($error))
<div class="biz-alert biz-alert-error" role="alert">{{ $error }}</div>
@elseif (! empty($pending))
<div class="marketing-balance-status" role="status" aria-live="polite" data-marketing-balance-pending>
<span class="material-icons-outlined" aria-hidden="true">sync</span>
<span>同步请求已进入后台队列,页面会自动检查首份共享数据,无需重复操作。</span>
</div>
@endif
@if ($supportsBalances)
@ -104,3 +111,32 @@
<div>该平台余额数据表尚未配置。</div>
</div>
@endif
@if (! empty($pending))
<script>
(function () {
var key = 'caiwu-marketing-balance-pending:' + window.location.pathname + window.location.search;
var attempts = Number(window.sessionStorage.getItem(key) || 0);
var maximumAttempts = 10;
if (attempts >= maximumAttempts) {
var status = document.querySelector('[data-marketing-balance-pending] span:last-child');
if (status) {
status.textContent = '后台仍在处理首份共享数据,请稍后手动刷新;无需重复提交查询。';
}
return;
}
window.sessionStorage.setItem(key, String(attempts + 1));
window.setTimeout(function () {
window.location.reload();
}, 30000);
}());
</script>
@elseif ($supportsBalances)
<script>
window.sessionStorage.removeItem('caiwu-marketing-balance-pending:' + window.location.pathname + window.location.search);
</script>
@endif

View File

@ -4,6 +4,7 @@ namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Mockery;
use Modules\EcommerceFinance\Exceptions\UpstreamSnapshotPendingException;
use Modules\EcommerceFinance\Repositories\JdWalletBillRepository;
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
use Modules\EcommerceFinance\Repositories\TmallTaobaoSpreadBillRepository;
@ -196,6 +197,38 @@ class MarketingAccountBillsTabsTest extends FeatureTestCase
->assertSessionHas('error', '首份共享快照正在准备,系统已登记刷新请求;请稍后刷新页面后再导出。');
}
public function testMarketingAccountBalanceColdStartShowsProcessingStateAndAutomaticCheck(): void
{
$this->allowMarketingAccountBalancePage();
$cache = Mockery::mock(UpstreamQueryCache::class);
$cache->shouldReceive('remember')
->once()
->withArgs(fn (string $scope): bool => $scope === 'taobao-alipay-bills.list')
->andThrow(new UpstreamSnapshotPendingException());
$cache->shouldReceive('remember')
->once()
->withArgs(fn (string $scope): bool => $scope === 'taobao-alipay-bills.options')
->andReturn([]);
$factory = Mockery::mock(UpstreamQueryCacheFactory::class);
$factory->shouldReceive('forSource')->once()->with('jiansun')->andReturn($cache);
$this->app->instance(UpstreamQueryCacheFactory::class, $factory);
$this->app->instance(TmallTaobaoSpreadBillRepository::class, Mockery::mock(TmallTaobaoSpreadBillRepository::class));
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-balance',
'tab' => 'taobao-alipay',
]))
->assertOk()
->assertSeeText('同步请求已进入后台队列,页面会自动检查首份共享数据,无需重复操作。')
->assertSee('data-marketing-balance-pending', false)
->assertSee('window.location.reload()', false)
->assertDontSee('<div class="biz-alert biz-alert-error" role="alert">', false);
}
public function testMarketingAccountBalanceExportUnexpectedFailureReturnsRedactedRedirect(): void
{
$this->allowMarketingAccountBalancePage();

View File

@ -5,6 +5,7 @@ namespace Tests\Unit\EcommerceFinance;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use InvalidArgumentException;
use Modules\EcommerceFinance\Exceptions\UpstreamSnapshotPendingException;
use Modules\EcommerceFinance\Services\UpstreamOdbcConnection;
use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
@ -103,9 +104,10 @@ class UpstreamQueryCacheTest extends TestCase
return ['total' => 1];
});
$this->fail('页面冷查询不应直接访问上游数据库。');
} catch (ServiceUnavailableHttpException $exception) {
} catch (UpstreamSnapshotPendingException $exception) {
$this->assertSame(0, $calls);
$this->assertStringContainsString('后台正在准备', $exception->getMessage());
$this->assertSame(15, $exception->getHeaders()['Retry-After']);
$this->assertNotEmpty(Cache::get('source_a:snapshots:active:v2'));
}
}

View File

@ -12,7 +12,7 @@ class TeamSystemDatabaseProfileTest extends TestCase
{
$encoded = TeamSystemDatabaseProfile::seal([
'host' => 'shared-db.test',
'port' => 3306,
'port' => 8444,
'database' => 'shared_system',
'username' => 'shared_writer',
], 'correct-password');
@ -20,7 +20,7 @@ class TeamSystemDatabaseProfileTest extends TestCase
$settings = (new TeamSystemDatabaseProfile($encoded))->settings('correct-password');
$this->assertSame('shared-db.test', $settings['host']);
$this->assertSame(3306, $settings['port']);
$this->assertSame(8444, $settings['port']);
$this->assertSame('shared_system', $settings['database']);
$this->assertSame('shared_writer', $settings['username']);
$this->assertSame('correct-password', $settings['password']);