feature/qiuxiang-jst-ssdd-seller-remark (#725)
> 开工时标题使用 `WIP: <任务名称>` 并先填写“任务占用与边界”。Codex 完成独立合并前自审后补齐其余内容并移除 `WIP:`。 ## 任务占用与边界 - 任务名称: - 实际开发者: - 任务来源/团队分工: - 目标结果: - 预计修改路径: - 将写入的公共契约(路由、Controller 方法、Repository、表/视图、`source_key`、`scope`、权限名、菜单键或共享组件): - 仅复用、明确不修改的公共契约: - 数据源、表/视图和字段: - 上游 `source_key` / `scope`: - 权限名、菜单键或共享组件: - 明确不修改的范围: ## 开工碰撞检查 - [ ] Codex 已执行 `scripts/codex-task-preflight.ps1` - [ ] 已检查最新 `main` 和所有远程任务分支 - [ ] 已搜索主线既有页面、接口、Repository 和数据查询 - [ ] 已把“将写入”和“仅复用、不修改”的公共契约分开;仅复用项不作为单独阻断条件 - [ ] 未发现实际写入重叠;或已在下方写明相关分支、具体重叠项和协调结论 相关分支、重叠项与协调结论: ## 实际改动 - 完成内容: - Codex 实际修改的文件: - 新增或变更的公共契约: - 与原计划的差异: ## 验证证据 - 正常流程: - 空数据/错误输入/无权限场景: - 受影响旧功能: - 自动测试及结果: - 实际页面、接口或只读业务查询结果: ## 风险检查 - [ ] 不涉及金额、权限、审批、数据库迁移、生产配置或数据修复 - [ ] 如涉及上述高风险内容,已在下方写明影响、回滚和所需授权 - [ ] 未提交 `.env`、密码、Token、私钥、真实财务数据、生产日志或构建产物 - [ ] 前端改动符合 `DESIGN.md`;无前端改动则写“不适用” 高风险影响、回滚和授权状态: ## 合并前复查 - [ ] 已重新拉取远程引用并用实际修改范围再次运行碰撞检查 - [ ] PR 不再是 `WIP:`,所有测试结果已经补齐 - [ ] Codex 已重新读取原始需求和验收标准,并逐文件审核 `origin/main...任务分支` 的完整 diff - [ ] Codex 自审确认无越界修改、重复实现、敏感内容、未处理冲突和未验证结果 - [ ] 合并顺序不会覆盖其他未合并任务 - [ ] 已授权当前任务的 Codex 执行 Squash merge、验证 `main` 并清理任务分支 - [ ] 如涉及生产迁移、数据修复、删除、覆盖配置或部署,已另行取得对应高风险授权 Reviewed-on: #725
This commit is contained in:
parent
a934229ccc
commit
e00d7cf871
@ -15,11 +15,16 @@ use RuntimeException;
|
||||
* 两个数据源:
|
||||
* - 共享镜像 ops_jst_orders(常规,覆盖镜像有数据的区间);
|
||||
* - 聚水潭「导出订单」Excel(镜像没有的历史区间,例如 2026-03,只能靠财务导出补)。
|
||||
*
|
||||
* 卖家备注包含「SSDD」时同时生成 SSDD 标签。卖家备注不是聚水潭系统标签,
|
||||
* 但种菜判断需要把这类订单纳入标签明细。
|
||||
*/
|
||||
class JstOrderLabelImporter
|
||||
{
|
||||
public const NO_LABEL = '(无标签)';
|
||||
|
||||
public const SELLER_REMARK_LABEL = 'SSDD';
|
||||
|
||||
private const READ_CHUNK = 2000;
|
||||
|
||||
private const INSERT_CHUNK = 2000;
|
||||
@ -27,6 +32,8 @@ class JstOrderLabelImporter
|
||||
/** 聚水潭导出文件里用到的表头。 */
|
||||
private const EXPORT_COLUMNS = ['线上订单号', '店铺名称', '下单时间', '标签'];
|
||||
|
||||
private const EXPORT_OPTIONAL_COLUMNS = ['卖家备注'];
|
||||
|
||||
public function __construct(
|
||||
private readonly DatabaseManager $databases,
|
||||
private readonly ?XlsxSheetReader $exportReader = null,
|
||||
@ -98,7 +105,10 @@ class JstOrderLabelImporter
|
||||
continue;
|
||||
}
|
||||
|
||||
$labels = $this->splitLabels((string) ($record->labels ?? ''));
|
||||
$labels = $this->labelsForRecord(
|
||||
(string) ($record->labels ?? ''),
|
||||
(string) ($record->remark ?? ''),
|
||||
);
|
||||
if ($labels === []) {
|
||||
$labels = [self::NO_LABEL];
|
||||
$noLabelOrders++;
|
||||
@ -221,9 +231,12 @@ class JstOrderLabelImporter
|
||||
// 明细行带标签;不按订单判断就会给本来有标签的订单多写一行「(无标签)」。
|
||||
$labeledOrders = [];
|
||||
$anyRow = false;
|
||||
foreach ($reader->rows($path, self::EXPORT_COLUMNS) as $line) {
|
||||
foreach ($reader->rows($path, self::EXPORT_COLUMNS, self::EXPORT_OPTIONAL_COLUMNS) as $line) {
|
||||
$anyRow = true;
|
||||
if ($this->splitLabels((string) ($line['标签'] ?? '')) === []) {
|
||||
if ($this->labelsForRecord(
|
||||
(string) ($line['标签'] ?? ''),
|
||||
(string) ($line['卖家备注'] ?? ''),
|
||||
) === []) {
|
||||
continue;
|
||||
}
|
||||
$orderNo = trim((string) ($line['线上订单号'] ?? ''));
|
||||
@ -241,7 +254,7 @@ class JstOrderLabelImporter
|
||||
}
|
||||
|
||||
// 第二遍:按「线上订单号 + 标签」去重后写入。
|
||||
foreach ($reader->rows($path, self::EXPORT_COLUMNS) as $line) {
|
||||
foreach ($reader->rows($path, self::EXPORT_COLUMNS, self::EXPORT_OPTIONAL_COLUMNS) as $line) {
|
||||
$orderNo = trim((string) ($line['线上订单号'] ?? ''));
|
||||
$orderedAt = $this->normalizeOrderedAt((string) ($line['下单时间'] ?? ''));
|
||||
if ($orderNo === '' || $orderedAt === null) {
|
||||
@ -255,7 +268,10 @@ class JstOrderLabelImporter
|
||||
continue;
|
||||
}
|
||||
|
||||
$labels = $this->splitLabels((string) ($line['标签'] ?? ''));
|
||||
$labels = $this->labelsForRecord(
|
||||
(string) ($line['标签'] ?? ''),
|
||||
(string) ($line['卖家备注'] ?? ''),
|
||||
);
|
||||
$withoutLabel = $labels === [];
|
||||
if ($withoutLabel) {
|
||||
if (isset($labeledOrders[$orderNo])) {
|
||||
@ -350,6 +366,18 @@ class JstOrderLabelImporter
|
||||
return array_values(array_unique($out));
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function labelsForRecord(string $labels, string $sellerRemark): array
|
||||
{
|
||||
$labels = $this->splitLabels($labels);
|
||||
if (stripos($sellerRemark, self::SELLER_REMARK_LABEL) !== false
|
||||
&& ! in_array(self::SELLER_REMARK_LABEL, $labels, true)) {
|
||||
$labels[] = self::SELLER_REMARK_LABEL;
|
||||
}
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
private function normalizeDate(string $value, string $label): string
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
@ -33,6 +33,7 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
$table->string('shop_name')->nullable();
|
||||
$table->dateTime('order_date')->nullable();
|
||||
$table->text('labels')->nullable();
|
||||
$table->text('remark')->nullable();
|
||||
});
|
||||
|
||||
DB::connection('business_mirror')->table('ops_jst_orders')->insert([
|
||||
@ -109,6 +110,43 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
$this->assertSame(3, $result['orders']);
|
||||
}
|
||||
|
||||
public function test_import_uses_ssdd_seller_remark_as_a_planting_label(): void
|
||||
{
|
||||
$this->allowPage();
|
||||
DB::connection('business_mirror')->table('ops_jst_orders')->insert([
|
||||
'Id' => 5,
|
||||
'o_id' => 105,
|
||||
'so_id' => '260915-SSDD-REMARK',
|
||||
'shop_name' => '拼多多-索菲亚书房官方旗舰店',
|
||||
'order_date' => '2026-09-15 11:00:00',
|
||||
'labels' => '',
|
||||
'remark' => 'SSDD。特殊单',
|
||||
]);
|
||||
DB::table('jst_order_label_planting_rules')->insert([
|
||||
'company_id' => $this->company->id,
|
||||
'label' => 'SSDD',
|
||||
'is_planting' => '是',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
app(\App\Business\JstOrderLabelPlantingRules::class)->forget($this->company->id);
|
||||
|
||||
app(JstOrderLabelImporter::class)->import('2026-09-01', '2026-09-15', $this->company->id, true);
|
||||
|
||||
$labels = JstOrderLabel::query()
|
||||
->where('company_id', $this->company->id)
|
||||
->where('order_no', '260915-SSDD-REMARK')
|
||||
->pluck('label')
|
||||
->all();
|
||||
|
||||
$this->assertSame([JstOrderLabelImporter::SELLER_REMARK_LABEL], $labels);
|
||||
$this->assertSame(
|
||||
'是',
|
||||
app(\App\Business\JstOrderLabelPlantingRules::class)
|
||||
->flag($this->company->id, JstOrderLabelImporter::SELLER_REMARK_LABEL),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_page_filters_and_export(): void
|
||||
{
|
||||
$this->allowPage();
|
||||
@ -241,6 +279,31 @@ class JstOrderLabelsPageTest extends FeatureTestCase
|
||||
$this->assertSame('得物-米客米家家居旗舰店', $noLabel->shop_name);
|
||||
}
|
||||
|
||||
public function test_import_from_file_uses_optional_ssdd_seller_remark(): void
|
||||
{
|
||||
$this->allowPage();
|
||||
|
||||
$path = $this->makeExportFile([
|
||||
['线上订单号', '店铺名称', '下单时间', '标签', '卖家备注'],
|
||||
['260915-FILE-SSDD', '拼多多-索菲亚书房官方旗舰店', '2026-09-15 12:00:00', '', 'SSDD。特殊单'],
|
||||
]);
|
||||
|
||||
try {
|
||||
app(JstOrderLabelImporter::class)->importFromFile($path, null, null, $this->company->id, false);
|
||||
} finally {
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
$this->assertSame(
|
||||
[JstOrderLabelImporter::SELLER_REMARK_LABEL],
|
||||
JstOrderLabel::query()
|
||||
->where('company_id', $this->company->id)
|
||||
->where('order_no', '260915-FILE-SSDD')
|
||||
->pluck('label')
|
||||
->all(),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_import_from_file_respects_window_and_replace(): void
|
||||
{
|
||||
$this->allowPage();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user