feat(批量铺货): 支持关键词类目推荐与最终兜底
This commit is contained in:
1 parent
b98c4edf68
commit
8fdc25483f
20 files changed
+531
-194
No files matched your search
@@ -47,7 +47,7 @@ Ydisks 支持管理渠道、推广账号、原始链接、推广短链与域名
|
||||
- 多个闲鱼账号的统一在线状态与消息管理
|
||||
- 数字商品、兑换码、链接或图片内容的自动交付
|
||||
- 付款后发货、评价赠品、超时求评价等自动化流程
|
||||
- 商品与订单同步、单商品发布及带逐行/批次类目兜底的表格批量铺货
|
||||
- 商品与订单同步、单商品发布及支持逐行/默认类目、自动识别和最终兜底的表格批量铺货
|
||||
- 接入 OpenAI 兼容接口实现可控的 AI 客服回复
|
||||
- 账号掉线、风控、续期和发货结果的多渠道通知
|
||||
|
||||
@@ -60,7 +60,7 @@ Ydisks 支持管理渠道、推广账号、原始链接、推广短链与域名
|
||||
| 即时消息 | 闲鱼 WebSocket 长连接、消息收发、关键词回复、默认回复及仅回复一次 |
|
||||
| 自动化中心 | 付款后自动发货、评价后赠品、超时未评价提醒、失败任务恢复与幂等检查点 |
|
||||
| 卡密库存 | 文本、批量卡密和图片三种交付类型,库存追加、批量导入、规格与延迟发送 |
|
||||
| 商品管理 | 商品同步、手工关联、单商品发布、CSV + ZIP 批量铺货、自动识别失败时的逐行/批次类目兜底、任务恢复与结果导出 |
|
||||
| 商品管理 | 商品同步、手工关联、单商品发布、CSV + ZIP 批量铺货、关键词获取默认类目、逐行类目优先、自动识别与“电子资料”最终兜底、任务恢复与结果导出 |
|
||||
| 订单管理 | 订单同步、插入、编辑、平台发货、补发卡密、仅确认发货及异常状态处理 |
|
||||
| AI 回复 | OpenAI 兼容 API、模型发现、自定义提示词、议价轮次和让价范围控制 |
|
||||
| 数据看板 | 活跃账号、订单、营收、库存、商品销量与金额统计 |
|
||||
@@ -69,6 +69,8 @@ Ydisks 支持管理渠道、推广账号、原始链接、推广短链与域名
|
||||
| 安全能力 | 管理端会话、敏感字段 AES-256-GCM 加密、日志脱敏和出站地址校验 |
|
||||
| 容器部署 | PostgreSQL 17、健康检查、持久化卷、GHCR amd64/arm64 多架构镜像 |
|
||||
|
||||
批量铺货的类目优先级为:表格当前行指定类目 > 上传页通过关键词获取的默认类目 > 闲鱼按标题、描述和图片自动识别 > “电子资料”最终兜底。模板类目字段可全部留空;如填写,类目 ID、名称和频道类目 ID 必须同时填写,淘宝类目 ID 按闲鱼响应提供的值填写。
|
||||
|
||||
## 系统架构
|
||||
|
||||
```mermaid
|
||||
|
||||
+1
-1
@@ -1004,7 +1004,7 @@
|
||||
<div class="feature-card">
|
||||
<div class="feature-icon-box">📊</div>
|
||||
<h3 class="feature-card-title">批量铺货与商品管理</h3>
|
||||
<p class="feature-card-desc">轻松同步闲鱼在售商品,支持 CSV + ZIP 素材包批量发布、逐行与批次类目兜底、单商品手动挂载及自动化发货规则。</p>
|
||||
<p class="feature-card-desc">轻松同步闲鱼在售商品,支持 CSV + ZIP 素材包批量发布、关键词获取默认类目、逐行类目优先、自动识别与电子资料最终兜底、单商品手动挂载及自动化发货规则。</p>
|
||||
</div>
|
||||
|
||||
<!-- Card 7 -->
|
||||
|
||||
+7
-7
@@ -19,8 +19,8 @@
|
||||
- 标题非空,价格大于 0;库存为正整数,留空默认 1。
|
||||
- 邮费模式为 `free`/`包邮` 或 `fixed`/`固定邮费`;固定邮费时必须填邮费。
|
||||
- 每件商品 1–9 张图片,多个用英文分号 `;` 分隔。可用公开 `https://` URL,或 ZIP 内相对路径。
|
||||
- 上传页必须填写“批次兜底类目 ID + 类目名称”。表格的“类目ID + 类目名称”可选,用于覆盖某一行的批次兜底配置;两列必须同时填写。
|
||||
- “频道类目ID”和“淘宝类目ID”通常留空,只有已取得同类闲鱼商品的准确值时才填写。
|
||||
- 上传页的默认类目可以留空。需要指定时,先选择账号,再输入关键词,由闲鱼推荐接口返回完整类目信息。表格的“类目ID + 类目名称 + 频道类目ID”可覆盖当前行;三列必须同时填写。
|
||||
- “淘宝类目ID”按闲鱼推荐响应填写;“电子资料”的值为空,应保持为空。
|
||||
- 本地图片 ZIP 最大 200 MiB,单图最大 10 MiB;表格最大 20 MiB。
|
||||
- CSV 使用 UTF-8,建议带 BOM;不要在表头增加空格。
|
||||
|
||||
@@ -40,23 +40,23 @@
|
||||
|
||||
1. 在“商品管理”点击“批量铺货”。
|
||||
2. 选择默认账号;表格某行未填账号 ID 时会使用它。
|
||||
3. 填写批次兜底类目 ID 和名称。优先从同类型、已经同步或发布成功的历史商品复用,页面会提示已知的历史类目。
|
||||
3. 默认类目可以留空;需要整批固定类目时,输入关键词并点击“获取类目”。
|
||||
4. 选择表格;表格引用本地图片时同时选择 ZIP。
|
||||
5. 点击预检,确认每一行显示的兜底类目正确,再处理账号未授权、卡密组不存在、图片路径不匹配、固定邮费缺失或价格为 0 等错误。
|
||||
5. 点击预检,确认每一行的类目策略正确,再处理账号未授权、卡密组不存在、图片路径不匹配、固定邮费缺失或价格为 0 等错误。
|
||||
6. 所有需发布行确认无误后启动任务;不要关闭正在运行的任务页面。
|
||||
7. 在任务详情查看成功、失败与进行中行。需要时取消任务;正在提交的单件商品可能继续完成。
|
||||
8. 对可重试失败项使用“重试失败”,并下载结果 CSV 留档。
|
||||
|
||||
### 类目选择顺序
|
||||
|
||||
系统仍会先让闲鱼根据标题、描述和图片自动识别类目。只有闲鱼明确返回“未能自动识别商品类目”时,系统才会使用后备配置:优先使用表格当前行的“类目ID + 类目名称”,否则使用上传页的批次兜底类目。接口超时、鉴权失败、风控等错误不会被兜底类目掩盖。
|
||||
类目优先级为:表格当前行指定类目 > 上传页通过关键词获取的默认类目 > 闲鱼根据商品标题、描述和图片自动识别 > “电子资料”最终兜底。只要用户指定了类目,就不会再由自动识别结果覆盖。接口超时、鉴权失败、风控等错误不会被最终兜底掩盖。
|
||||
|
||||
批量铺货发布的都是虚拟商品,不请求或提交实物发货地址;指定类目只解决商品类型识别,不会改变虚拟发货流程。
|
||||
|
||||
## 3. 常见问题
|
||||
|
||||
- **图片找不到**:ZIP 内路径必须与表格完全一致,使用 `/`,不能以 `/` 开头或包含 `..`。
|
||||
- **未能自动识别类目**:新建批次时必须设置兜底类目;如果仍出现该提示,通常是旧批次没有保存兜底配置,请重新上传创建任务。不要把接口超时或鉴权错误误当成类目问题。
|
||||
- **类目 ID 从哪里取**:优先复用账号里同类型的历史商品类目。选择页面给出的历史类目,或从已同步商品的类目信息中复制 ID 和准确名称;不要猜测 ID。
|
||||
- **未能自动识别类目**:系统会自动使用“电子资料”最终兜底;接口超时、鉴权或风控错误仍会正常提示。
|
||||
- **类目 ID 从哪里取**:在上传页输入关键词获取,无需手工查找或填写底层 ID。
|
||||
- **自动化不生效**:检查卡密组 ID、账号归属、启用列和库存;发布成功后仍应查看自动化规则是否已创建。
|
||||
- **任务中断**:先重新打开批次详情确认状态,避免重复新建整批任务;仅重试失败行。
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
- 对已在闲鱼上存在的商品,选择同步全部或按页同步,确认商品归属到正确账号。
|
||||
- 对单个新商品,使用发布入口填写标题、描述、价格、库存、邮费和图片。图片必须可用;提交前复核目标账号。
|
||||
- 批量铺货时必须指定批次兜底类目 ID 和名称。系统优先使用闲鱼自动识别结果,仅在无法识别时使用表格当前行的指定类目或批次兜底类目;类目信息应复用同类型历史商品,不要猜测 ID。
|
||||
- 批量铺货的默认类目可以留空,也可以通过关键词从闲鱼获取。优先级为逐行类目、页面默认类目、自动识别,最后才使用“电子资料”兜底。
|
||||
- 批量铺货商品按虚拟商品发布,不依赖实物发货地址;类目兜底不会改变付款后的虚拟交付逻辑。
|
||||
- 商品发布成功不等于已开启自动发货。仍需在“自动化规则”中按商品/规格绑定卡密组,或在批量铺货表格中一并声明自动化配置。
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
1. 账号在线并已启用。
|
||||
2. 商品已同步或发布成功,价格、库存和图片正确。
|
||||
3. 批量铺货的预检明细已显示正确的逐行兜底类目。
|
||||
3. 批量铺货的预检明细已显示正确的类目策略。
|
||||
4. 所需卡密组启用且余量充足。
|
||||
5. 自动化规则准确匹配商品;有规格时逐个规格确认。
|
||||
6. 先用测试订单验证,检查订单列表、自动化异常列表和通知记录。
|
||||
+14
-13
@@ -55,22 +55,23 @@ cookie_id,title,description,price,original_price,quantity,postage_mode,postage,i
|
||||
| 邮费 | 条件必填 | 数字。邮费模式为 `fixed` 时必填;`free` 时留空 | `8.00` |
|
||||
| 图片 | 是 | 1–9 张,多个用 `;` 分隔。每项是公网 URL 或图片包内相对路径 | `images/bundle-1.jpg;images/bundle-2.jpg` |
|
||||
|
||||
#### 指定类目字段(可选的逐行兜底)
|
||||
#### 指定类目字段(可选的逐行默认类目)
|
||||
|
||||
| 列 | 何时填写 | 格式 / 取值 |
|
||||
|---|---|---|
|
||||
| 类目ID | 当前行需要覆盖批次兜底类目时 | 闲鱼商品类目 ID;必须和“类目名称”同时填写 |
|
||||
| 类目ID | 当前行需要指定默认类目时 | 闲鱼商品类目 ID;必须和“类目名称、频道类目ID”同时填写 |
|
||||
| 类目名称 | 填写了“类目ID”时 | 与类目 ID 对应的准确名称 |
|
||||
| 频道类目ID | 通常留空 | 仅在已从同类闲鱼商品取得准确值时填写 |
|
||||
| 淘宝类目ID | 通常留空 | 仅在已从同类闲鱼商品取得准确值时填写 |
|
||||
| 频道类目ID | 填写了“类目ID”时 | 必须填写闲鱼推荐响应中的准确频道类目 ID |
|
||||
| 淘宝类目ID | 闲鱼响应有值时 | 按原样填写;“电子资料”没有该值,保持为空 |
|
||||
|
||||
上传页面还会要求运营人员填写一个必需的“批次兜底类目 ID + 类目名称”。系统对每行按以下顺序处理:
|
||||
上传页面的默认类目可以留空。需要整批固定类目时,选择发布账号后输入关键词,由闲鱼推荐接口返回并保存完整类目信息。系统对每行按以下顺序处理:
|
||||
|
||||
1. 先调用闲鱼接口,根据标题、描述和图片自动识别类目。
|
||||
2. 自动识别成功时,使用闲鱼返回的类目,指定类目不会强行覆盖。
|
||||
3. 只有闲鱼明确未识别出类目时,才使用表格当前行的指定类目;当前行未填时使用上传页的批次兜底类目。
|
||||
1. 当前行填写了完整类目字段时,优先使用当前行类目。
|
||||
2. 否则,上传页已通过关键词选择默认类目时,使用页面默认类目。
|
||||
3. 前两项均为空时,调用闲鱼接口,根据标题、描述和图片自动识别。
|
||||
4. 闲鱼明确没有识别结果时,最终使用“电子资料”(类目 ID `50023914`、频道类目 ID `202036301`)。
|
||||
|
||||
因此,即使表格完全不填写这四列,运营人员也必须在上传页设置批次兜底类目,保证每个待发布商品都有可用的后备类型。类目 ID 和名称应从同类型、已经同步或发布成功的闲鱼商品中取得,不要凭空编造。频道类目 ID 和淘宝类目 ID 没有可靠值时留空即可。
|
||||
因此,表格和上传页都不指定类目时,系统会先自动识别,并只在没有匹配结果时使用“电子资料”。接口超时、鉴权失败和风控错误不会被最终兜底掩盖。
|
||||
|
||||
#### 自动化字段(可选,不填或填"否"表示不启用)
|
||||
|
||||
@@ -169,7 +170,7 @@ sub/product.jpg
|
||||
| 邮费模式 | `free` 或 `fixed`(或 `包邮` / `固定邮费`) |
|
||||
| 邮费 | 邮费模式为 `fixed` 时必填且 ≥ 0 |
|
||||
| 图片 | 1–9 张;本地路径必须在 ZIP 内存在;URL 必须是合法 `http(s)://` |
|
||||
| 指定类目 | 当前行填写了任一类目字段时,“类目ID”和“类目名称”必须同时存在;批次兜底类目由上传者在页面必填 |
|
||||
| 指定类目 | 当前行填写了任一类目字段时,“类目ID、类目名称、频道类目ID”必须同时存在;页面默认类目可为空 |
|
||||
| 付款发货 | 启用时:内容列必填至少一条卡密组;卡密组 ID 必须属于上传者;每件份数 > 0;延迟秒 ≥ 0 |
|
||||
| 评价赠品 | 同上 |
|
||||
| 求评价 | 启用时:等待小时 > 0、文案非空、最多次数 > 0 |
|
||||
@@ -200,7 +201,7 @@ sub/product.jpg
|
||||
2222660684687,普通商品,仅发布不绑自动化,49.90,,10,fixed,8.00,https://cdn.example.com/p1.jpg,,,,,否,,否,,否,,,
|
||||
```
|
||||
|
||||
无需图片包(用的是 URL)。四个逐行类目列留空,上传时必须选择同类型商品对应的批次兜底类目。
|
||||
无需图片包(用的是 URL)。四个逐行类目列可留空;页面默认类目也留空时,系统会自动识别。
|
||||
|
||||
### 7.2 完整自动化 + 本地图片包
|
||||
|
||||
@@ -233,8 +234,8 @@ images.zip
|
||||
- [ ] 每行标题非空、价格 > 0、库存 > 0
|
||||
- [ ] 邮费模式只填 `free` / `fixed`(或 `包邮` / `固定邮费`);`fixed` 时邮费已填
|
||||
- [ ] 每行图片 1–9 张,多个用 `;` 分隔
|
||||
- [ ] 已确认上传者会填写准确的批次兜底类目 ID 和名称
|
||||
- [ ] 需要逐行覆盖类目时,“类目ID”和“类目名称”同时填写;没有可靠的频道/淘宝类目 ID 时保持为空
|
||||
- [ ] 需要整批固定类目时,已在上传页通过关键词获取默认类目;否则保持为空
|
||||
- [ ] 需要逐行指定类目时,“类目ID、类目名称、频道类目ID”同时填写;淘宝类目 ID 按接口响应填写
|
||||
- [ ] 用本地路径的图片,在 ZIP 内对应路径都能找到
|
||||
- [ ] 用 URL 的图片,链接是 `http(s)://` 且可公开访问
|
||||
- [ ] 启用了付款发货/评价赠品的行,内容列按 §3 格式填写,卡密组 ID 已知(或已标注需运营补填)
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
syncItemsFromAccount,
|
||||
createItem,
|
||||
publishItem,
|
||||
recommendPublishCategory,
|
||||
previewItemPublishBatch,
|
||||
startItemPublishBatch,
|
||||
getItemPublishBatch,
|
||||
@@ -19,7 +20,7 @@ import {
|
||||
deleteItem,
|
||||
getShippingRules
|
||||
} from '../services/api';
|
||||
import { ArrowRight, Box, CheckCircle2, CircleDashed, Edit, Filter, Link2, PackagePlus, Plus, RefreshCw, Save, ShoppingBag, Trash2, UploadCloud, User, X } from 'lucide-react';
|
||||
import { ArrowRight, Box, CheckCircle2, CircleDashed, Edit, Filter, Link2, PackagePlus, Plus, RefreshCw, Save, Search, ShoppingBag, Trash2, UploadCloud, User, X } from 'lucide-react';
|
||||
|
||||
interface ItemListProps {
|
||||
onConfigureDelivery: (item: Item) => void;
|
||||
@@ -97,6 +98,8 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
const [batchPhase, setBatchPhase] = useState<BatchPhase>('upload');
|
||||
const [batchFile, setBatchFile] = useState<File | null>(null);
|
||||
const [batchImagesZip, setBatchImagesZip] = useState<File | null>(null);
|
||||
const [batchCategoryKeyword, setBatchCategoryKeyword] = useState('');
|
||||
const [batchCategoryLoading, setBatchCategoryLoading] = useState(false);
|
||||
const [batchFallbackCategory, setBatchFallbackCategory] = useState({
|
||||
catId: '',
|
||||
catName: '',
|
||||
@@ -135,23 +138,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
});
|
||||
const [publishImagePreviews, setPublishImagePreviews] = useState<{ key: string; url: string }[]>([]);
|
||||
|
||||
const knownCategories = useMemo(() => {
|
||||
const unique = new Map<string, string>();
|
||||
items.forEach(item => {
|
||||
const catId = String(item.item_category || '').trim();
|
||||
if (!catId) return;
|
||||
let catName = '';
|
||||
try {
|
||||
const detail = JSON.parse(item.item_detail || '{}') as { category_name?: string };
|
||||
catName = String(detail.category_name || '').trim();
|
||||
} catch {
|
||||
// 历史商品详情可能不是 JSON,仍保留可复用的类目 ID。
|
||||
}
|
||||
if (!unique.has(catId) || catName) unique.set(catId, catName);
|
||||
});
|
||||
return Array.from(unique, ([catId, catName]) => ({ catId, catName }));
|
||||
}, [items]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showPublishModal || publishForm.images.length === 0) {
|
||||
setPublishImagePreviews([]);
|
||||
@@ -351,6 +337,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
setBatchDetail(null);
|
||||
setBatchFile(null);
|
||||
setBatchImagesZip(null);
|
||||
setBatchCategoryKeyword('');
|
||||
setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' });
|
||||
setShowBatchModal(true);
|
||||
setBatchLoading(true);
|
||||
@@ -370,6 +357,28 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRecommendBatchCategory = async () => {
|
||||
const keyword = batchCategoryKeyword.trim();
|
||||
if (!selectedAccount) return alert('请先选择默认发布账号');
|
||||
if (!keyword) return alert('请输入类目关键词');
|
||||
setBatchCategoryLoading(true);
|
||||
try {
|
||||
const result = await recommendPublishCategory(selectedAccount, keyword);
|
||||
const category = result.category;
|
||||
setBatchFallbackCategory({
|
||||
catId: category.cat_id,
|
||||
catName: category.cat_name,
|
||||
channelCatId: category.channel_cat_id,
|
||||
tbCatId: category.tb_cat_id || '',
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('获取推荐类目失败:', error);
|
||||
alert(error?.message || '没有匹配到类目,请换一个更具体的关键词');
|
||||
} finally {
|
||||
setBatchCategoryLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openRecentBatchResult = async () => {
|
||||
if (!recentBatch?.id) return;
|
||||
setBatchLoading(true);
|
||||
@@ -388,9 +397,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
const handlePreviewBatch = async () => {
|
||||
if (!batchFile) return alert('请先上传商品表格');
|
||||
if (!selectedAccount) return alert('请先选择默认发布账号');
|
||||
if (!batchFallbackCategory.catId.trim() || !batchFallbackCategory.catName.trim()) {
|
||||
return alert('请同时填写批次兜底类目 ID 和类目名称');
|
||||
}
|
||||
setBatchLoading(true);
|
||||
try {
|
||||
const result = await previewItemPublishBatch({
|
||||
@@ -953,58 +959,57 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
<p className="text-xs text-gray-500">表格中“账号ID”为空时,会使用这里选择的账号。</p>
|
||||
</div>
|
||||
|
||||
<div className="rounded-2xl border border-amber-200 bg-amber-50/70 p-4 space-y-3">
|
||||
<div className="rounded-xl border border-amber-200 bg-amber-50/70 p-4 space-y-3">
|
||||
<div>
|
||||
<div className="text-sm font-extrabold text-gray-900">批次兜底类目 <span className="text-red-600">*</span></div>
|
||||
<p className="mt-1 text-xs leading-5 text-amber-800">闲鱼仍会先自动识别;只有明确识别不出类目时才使用这里的配置。表格中的“类目ID + 类目名称”可覆盖当前行。</p>
|
||||
<div className="text-sm font-extrabold text-gray-900">默认类目 <span className="font-medium text-gray-500">(可为空)</span></div>
|
||||
<p className="mt-1 text-xs leading-5 text-amber-800">填写后优先使用该类目;留空时由闲鱼根据每件商品自动识别。仍无法识别时,系统最终使用“电子资料”兜底。</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1.5">
|
||||
<span className="text-xs font-bold text-gray-700">类目 ID</span>
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
<label className="relative flex-1">
|
||||
<span className="sr-only">类目关键词</span>
|
||||
<Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400" />
|
||||
<input
|
||||
className="w-full ios-input px-3 py-2.5 rounded-xl bg-white"
|
||||
list="known-publish-categories"
|
||||
placeholder="例如 50023717"
|
||||
value={batchFallbackCategory.catId}
|
||||
onChange={e => {
|
||||
const catId = e.target.value;
|
||||
const matched = knownCategories.find(category => category.catId === catId.trim());
|
||||
setBatchFallbackCategory(prev => ({
|
||||
...prev,
|
||||
catId,
|
||||
catName: matched?.catName || (catId ? prev.catName : ''),
|
||||
}));
|
||||
className="w-full ios-input rounded-xl bg-white py-2.5 pl-10 pr-3"
|
||||
placeholder="输入关键词,例如:课程资料、设计素材"
|
||||
value={batchCategoryKeyword}
|
||||
onChange={e => setBatchCategoryKeyword(e.target.value)}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
void handleRecommendBatchCategory();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<datalist id="known-publish-categories">
|
||||
{knownCategories.map(category => (
|
||||
<option key={category.catId} value={category.catId}>{category.catName || '历史商品类目'}</option>
|
||||
))}
|
||||
</datalist>
|
||||
</label>
|
||||
<label className="space-y-1.5">
|
||||
<span className="text-xs font-bold text-gray-700">类目名称</span>
|
||||
<input
|
||||
className="w-full ios-input px-3 py-2.5 rounded-xl bg-white"
|
||||
placeholder="例如 其他虚拟商品"
|
||||
value={batchFallbackCategory.catName}
|
||||
onChange={e => setBatchFallbackCategory(prev => ({ ...prev, catName: e.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
disabled={!selectedAccount || !batchCategoryKeyword.trim() || batchCategoryLoading}
|
||||
onClick={() => void handleRecommendBatchCategory()}
|
||||
className="ios-btn-primary flex min-h-[42px] items-center justify-center gap-2 rounded-xl px-4 text-sm font-bold disabled:opacity-50"
|
||||
>
|
||||
<Search className="h-4 w-4" />
|
||||
{batchCategoryLoading ? '匹配中...' : '获取类目'}
|
||||
</button>
|
||||
</div>
|
||||
<details className="group text-xs text-gray-600">
|
||||
<summary className="cursor-pointer select-none font-bold text-amber-900">高级类目字段(通常留空)</summary>
|
||||
<div className="mt-3 grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<label className="space-y-1.5">
|
||||
<span className="font-bold text-gray-700">频道类目 ID</span>
|
||||
<input className="w-full ios-input px-3 py-2.5 rounded-xl bg-white" value={batchFallbackCategory.channelCatId} onChange={e => setBatchFallbackCategory(prev => ({ ...prev, channelCatId: e.target.value }))} />
|
||||
</label>
|
||||
<label className="space-y-1.5">
|
||||
<span className="font-bold text-gray-700">淘宝类目 ID</span>
|
||||
<input className="w-full ios-input px-3 py-2.5 rounded-xl bg-white" value={batchFallbackCategory.tbCatId} onChange={e => setBatchFallbackCategory(prev => ({ ...prev, tbCatId: e.target.value }))} />
|
||||
</label>
|
||||
{batchFallbackCategory.catId ? (
|
||||
<div className="flex min-h-[46px] items-center justify-between gap-3 border-t border-amber-200 pt-3">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2 text-sm font-bold text-gray-900">
|
||||
<CheckCircle2 className="h-4 w-4 shrink-0 text-emerald-600" />
|
||||
<span className="truncate">{batchFallbackCategory.catName}</span>
|
||||
</div>
|
||||
<div className="mt-1 font-mono text-xs text-gray-500">类目 {batchFallbackCategory.catId} · 频道 {batchFallbackCategory.channelCatId}</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
title="清除默认类目"
|
||||
onClick={() => setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' })}
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-gray-500 hover:bg-white hover:text-gray-900"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
@@ -1078,10 +1083,10 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
['邮费模式', '可以留空', '留空表示包邮;包邮填 free,固定邮费填 fixed'],
|
||||
['邮费', '邮费模式填 fixed 时填写', '只填数字,例如 8.00'],
|
||||
['图片', '每个商品都要填', '填写 zip 内图片路径或图片网址;多张图片用英文分号隔开'],
|
||||
['类目ID', '需要覆盖批次兜底类目时填写', '必须和“类目名称”同时填写;只覆盖当前商品行'],
|
||||
['类目ID', '需要指定当前行默认类目时填写', '必须和“类目名称、频道类目ID”同时填写;优先于自动识别'],
|
||||
['类目名称', '填写了“类目ID”时必填', '填写该 ID 对应的准确类目名称'],
|
||||
['频道类目ID', '通常留空', '仅在已明确取得闲鱼频道类目 ID 时填写'],
|
||||
['淘宝类目ID', '通常留空', '仅在已明确取得淘宝类目 ID 时填写'],
|
||||
['频道类目ID', '覆盖类目时必填', '必须填写闲鱼返回的准确频道类目 ID'],
|
||||
['淘宝类目ID', '按闲鱼返回填写', '“电子资料”无淘宝类目 ID,保持为空'],
|
||||
['付款发货启用', '需要付款后自动发货时填写', '填“是”表示开启;不需要时填“否”或留空'],
|
||||
['付款发货内容', '“付款发货启用”填“是”时填写', '从“卡密库存”页面取得卡密组 ID,按上方示例填写'],
|
||||
['评价赠品启用', '需要评价赠品时填写', '填“是”表示开启;不需要时填“否”或留空'],
|
||||
@@ -1129,7 +1134,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
<th className="px-4 py-3">状态</th>
|
||||
<th className="px-4 py-3">标题</th>
|
||||
<th className="px-4 py-3">价格/库存</th>
|
||||
<th className="px-4 py-3">兜底类目</th>
|
||||
<th className="px-4 py-3">类目策略</th>
|
||||
<th className="px-4 py-3">图片</th>
|
||||
<th className="px-4 py-3">问题</th>
|
||||
</tr>
|
||||
@@ -1146,8 +1151,8 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
<td className="px-4 py-3 font-bold text-gray-900 max-w-[240px] truncate">{row.title || '-'}</td>
|
||||
<td className="px-4 py-3 text-gray-600">¥{row.price || '-'} / {row.quantity || 1}</td>
|
||||
<td className="px-4 py-3 text-xs text-gray-600 min-w-[150px]">
|
||||
<div className="font-bold text-gray-800">{row.category?.cat_name || '-'}</div>
|
||||
<div className="font-mono text-gray-400">{row.category?.cat_id || '-'}</div>
|
||||
<div className="font-bold text-gray-800">{row.category?.cat_name || '自动识别'}</div>
|
||||
<div className="font-mono text-gray-400">{row.category?.cat_id || '失败后使用电子资料'}</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-gray-600">{row.images?.length || 0} 张</td>
|
||||
<td className="px-4 py-3 text-red-600 text-xs max-w-[280px]">{row.errors?.join(';') || '-'}</td>
|
||||
@@ -1191,7 +1196,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
<th className="px-4 py-3">行号</th>
|
||||
<th className="px-4 py-3">状态</th>
|
||||
<th className="px-4 py-3">标题</th>
|
||||
<th className="px-4 py-3">兜底类目</th>
|
||||
<th className="px-4 py-3">类目策略</th>
|
||||
<th className="px-4 py-3">商品ID</th>
|
||||
<th className="px-4 py-3">错误原因</th>
|
||||
</tr>
|
||||
@@ -1207,8 +1212,8 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
</td>
|
||||
<td className="px-4 py-3 font-bold text-gray-900 max-w-[260px] truncate">{row.title}</td>
|
||||
<td className="px-4 py-3 text-xs text-gray-600 min-w-[150px]">
|
||||
<div className="font-bold text-gray-800">{row.category?.cat_name || '-'}</div>
|
||||
<div className="font-mono text-gray-400">{row.category?.cat_id || '-'}</div>
|
||||
<div className="font-bold text-gray-800">{row.category?.cat_name || '自动识别'}</div>
|
||||
<div className="font-mono text-gray-400">{row.category?.cat_id || '失败后使用电子资料'}</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-xs font-mono">
|
||||
{row.item_url ? <a href={row.item_url} target="_blank" rel="noreferrer" className="text-blue-600 hover:underline">{row.item_id}</a> : (row.item_id || '-')}
|
||||
@@ -1225,7 +1230,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
|
||||
|
||||
<div className="modal-footer">
|
||||
{batchPhase === 'upload' && (
|
||||
<button disabled={batchLoading || !batchFile || !selectedAccount || !batchFallbackCategory.catId.trim() || !batchFallbackCategory.catName.trim()} onClick={handlePreviewBatch} className="w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50">
|
||||
<button disabled={batchLoading || !batchFile || !selectedAccount} onClick={handlePreviewBatch} className="w-full ios-btn-primary px-6 py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 disabled:opacity-50">
|
||||
<RefreshCw className={`w-4 h-4 ${batchLoading ? 'animate-spin' : ''}`} />
|
||||
{batchLoading ? '正在预检...' : '开始预检'}
|
||||
</button>
|
||||
|
||||
@@ -476,6 +476,18 @@ export const publishItem = async (form: {
|
||||
return postForm('/items/publish', body);
|
||||
}
|
||||
|
||||
export const recommendPublishCategory = async (cookieId: string, keyword: string): Promise<{
|
||||
success: boolean;
|
||||
category: {
|
||||
cat_id: string;
|
||||
cat_name: string;
|
||||
channel_cat_id: string;
|
||||
tb_cat_id?: string;
|
||||
};
|
||||
}> => {
|
||||
return post('/items/publish-categories/recommend', { cookie_id: cookieId, keyword });
|
||||
};
|
||||
|
||||
export const previewItemPublishBatch = async (form: {
|
||||
file: File;
|
||||
imagesZip?: File | null;
|
||||
|
||||
@@ -49,7 +49,7 @@ type ItemPublishBatchRow struct {
|
||||
PostageMode string // 邮费模式:free/buyer/seller
|
||||
Postage string
|
||||
ImagesJSON string // 图片引用 JSON 数组(相对 UploadDir 的路径)
|
||||
CategoryJSON string // 自动识别失败时使用的指定类目 JSON
|
||||
CategoryJSON string // 用户指定的优先类目 JSON;为空时自动识别
|
||||
AutomationJSON string // 发布后自动创建的自动化规则配置 JSON
|
||||
Status string // pending/running/success/failed
|
||||
ItemID string // 发布成功后回填的闲鱼商品 ID
|
||||
|
||||
@@ -23,6 +23,7 @@ func (s *Server) mountItemsReal(r chi.Router) {
|
||||
r.Post("/items/get-all-from-account", s.syncItemsFromAccount)
|
||||
r.Post("/items/get-by-page", s.syncItemsPageFromAccount)
|
||||
r.Post("/items/publish", s.publishItem)
|
||||
r.Post("/items/publish-categories/recommend", s.recommendItemPublishCategory)
|
||||
r.Post("/items/publish-batches/preview", s.previewItemPublishBatch)
|
||||
r.Post("/items/publish-batches", s.startItemPublishBatch)
|
||||
r.Get("/items/publish-batches", s.listItemPublishBatches)
|
||||
|
||||
@@ -20,6 +20,45 @@ type stubPublishMTop struct {
|
||||
publish func(context.Context, string, mtop.PublishItemRequest) (*mtop.PublishItemResult, error)
|
||||
}
|
||||
|
||||
func TestRecommendItemPublishCategory(t *testing.T) {
|
||||
srv, _, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
client := mtop.NewClient()
|
||||
client.HTTPClient = &http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if req.URL.Query().Get("api") != "mtop.taobao.idle.kgraph.property.recommend" {
|
||||
t.Fatalf("api=%q", req.URL.Query().Get("api"))
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Header: make(http.Header),
|
||||
Body: io.NopCloser(strings.NewReader(
|
||||
`{"ret":["SUCCESS::调用成功"],"data":{"cardList":[{"cardData":{"propertyId":"-10000","propertyName":"分类","valuesList":[{"catId":"50023914","catName":"电子资料","channelCatId":"202036301","isClicked":"1"}]}}]}}`,
|
||||
)),
|
||||
Request: req,
|
||||
}, nil
|
||||
})}
|
||||
srv.MTop = client
|
||||
h := srv.Router()
|
||||
cookie := loginHelper(t, h)
|
||||
req := httptest.NewRequest(http.MethodPost, "/items/publish-categories/recommend", strings.NewReader(`{"cookie_id":"acc1","keyword":"课程资料"}`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.AddCookie(cookie)
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var response struct {
|
||||
Category mtop.PublishCategory `json:"category"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
if response.Category.CatID != "50023914" || response.Category.CatName != "电子资料" || response.Category.ChannelCatID != "202036301" {
|
||||
t.Fatalf("category=%+v", response.Category)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *stubPublishMTop) PublishItem(ctx context.Context, cookies string, req mtop.PublishItemRequest) (*mtop.PublishItemResult, error) {
|
||||
return s.publish(ctx, cookies, req)
|
||||
}
|
||||
|
||||
@@ -94,6 +94,72 @@ type publishReviewRequestCfg struct {
|
||||
DelaySeconds int `json:"delay_seconds"`
|
||||
}
|
||||
|
||||
type publishCategoryRecommender interface {
|
||||
RecommendPublishCategory(ctx context.Context, cookiesStr, keyword string) (mtop.PublishCategory, string, error)
|
||||
}
|
||||
|
||||
func (s *Server) recommendItemPublishCategory(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
CookieID string `json:"cookie_id"`
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
if err := decodeJSON(r, &req); err != nil {
|
||||
writeErr(w, http.StatusBadRequest, "请求格式错误")
|
||||
return
|
||||
}
|
||||
req.CookieID = strings.TrimSpace(req.CookieID)
|
||||
req.Keyword = strings.TrimSpace(req.Keyword)
|
||||
if req.CookieID == "" {
|
||||
writeErr(w, http.StatusBadRequest, "请先选择发布账号")
|
||||
return
|
||||
}
|
||||
if req.Keyword == "" {
|
||||
writeErr(w, http.StatusBadRequest, "请输入类目关键词")
|
||||
return
|
||||
}
|
||||
_, userID, ok := s.cookieForCurrentUser(w, r, req.CookieID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
recommender, ok := s.mtopClient().(publishCategoryRecommender)
|
||||
if !ok {
|
||||
writeErr(w, http.StatusNotImplemented, "当前 MTOP 客户端不支持类目推荐")
|
||||
return
|
||||
}
|
||||
|
||||
credentialUnlock := s.Store.LockAccountCredentials(req.CookieID)
|
||||
defer credentialUnlock()
|
||||
latest, err := s.Store.Cookies.GetDetails(r.Context(), req.CookieID)
|
||||
if err != nil || latest == nil || latest.UserID != userID || !hasStoredCookieCredential(latest) {
|
||||
writeErr(w, http.StatusConflict, "账号凭证已变化,请重试")
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
mtopCtx, cookieSession := withMTopCookieSnapshot(ctx, latest)
|
||||
category, updatedCookies, callErr := recommender.RecommendPublishCategory(mtopCtx, latest.Value, req.Keyword)
|
||||
_, _, handled, persistErr := s.persistMTopCookieSessionLocked(r.Context(), latest, cookieSession)
|
||||
if persistErr != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "保存账号登录状态失败")
|
||||
return
|
||||
}
|
||||
if !handled && updatedCookies != "" && updatedCookies != latest.Value {
|
||||
if err := s.Store.Cookies.UpdateValueOwned(r.Context(), req.CookieID, updatedCookies, userID); err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "保存账号登录状态失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
if callErr != nil {
|
||||
if errors.Is(callErr, mtop.ErrPublishCategoryUnrecognized) {
|
||||
writeErr(w, http.StatusNotFound, "没有匹配到可发布类目,请换一个关键词")
|
||||
return
|
||||
}
|
||||
writeErr(w, http.StatusBadGateway, callErr.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"success": true, "category": category})
|
||||
}
|
||||
|
||||
func (s *Server) previewItemPublishBatch(w http.ResponseWriter, r *http.Request) {
|
||||
sess := auth.SessionFromContext(r.Context())
|
||||
s.cleanupExpiredPublishUploads(r.Context())
|
||||
@@ -119,8 +185,9 @@ func (s *Server) previewItemPublishBatch(w http.ResponseWriter, r *http.Request)
|
||||
ChannelCatID: strings.TrimSpace(r.FormValue("fallback_channel_category_id")),
|
||||
TBCatID: strings.TrimSpace(r.FormValue("fallback_tb_category_id")),
|
||||
}
|
||||
if fallbackCategory.CatID == "" || fallbackCategory.CatName == "" {
|
||||
writeErr(w, http.StatusBadRequest, "请同时填写批次兜底类目 ID 和类目名称")
|
||||
hasDefaultCategory := fallbackCategory.CatID != "" || fallbackCategory.CatName != "" || fallbackCategory.ChannelCatID != "" || fallbackCategory.TBCatID != ""
|
||||
if hasDefaultCategory && (fallbackCategory.CatID == "" || fallbackCategory.CatName == "" || fallbackCategory.ChannelCatID == "") {
|
||||
writeErr(w, http.StatusBadRequest, "默认类目信息不完整,请重新通过关键词获取")
|
||||
return
|
||||
}
|
||||
source, sourceHeader, err := r.FormFile("file")
|
||||
@@ -536,7 +603,7 @@ func (s *Server) downloadItemPublishBatchResult(w http.ResponseWriter, r *http.R
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("\xEF\xBB\xBF")
|
||||
cw := csv.NewWriter(&buf)
|
||||
_ = cw.Write([]string{"行号", "状态", "账号ID", "标题", "价格", "库存", "兜底类目ID", "兜底类目名称", "商品ID", "商品URL", "错误原因"})
|
||||
_ = cw.Write([]string{"行号", "状态", "账号ID", "标题", "价格", "库存", "默认类目ID", "默认类目名称", "商品ID", "商品URL", "错误原因"})
|
||||
for _, row := range rows {
|
||||
var category mtop.PublishCategory
|
||||
_ = json.Unmarshal([]byte(row.CategoryJSON), &category)
|
||||
@@ -781,16 +848,19 @@ func (s *Server) publishBatchRow(ctx context.Context, userID int64, client mtop.
|
||||
res := &mtop.PublishItemResult{ItemID: row.ItemID, ItemURL: row.ItemURL, Title: row.Title, PriceText: row.Price, Quantity: row.Quantity}
|
||||
var responseCookieErr error
|
||||
if row.ItemID == "" {
|
||||
var preferredCategory *mtop.PublishCategory
|
||||
rawCategory := strings.TrimSpace(row.CategoryJSON)
|
||||
if rawCategory == "" || rawCategory == "{}" {
|
||||
return errors.New("批量任务缺少兜底类目,请重新上传并创建任务")
|
||||
}
|
||||
var fallbackCategory mtop.PublishCategory
|
||||
if err := json.Unmarshal([]byte(rawCategory), &fallbackCategory); err != nil {
|
||||
return errors.New("兜底类目配置损坏,请重新创建批量任务")
|
||||
}
|
||||
if strings.TrimSpace(fallbackCategory.CatID) == "" || strings.TrimSpace(fallbackCategory.CatName) == "" {
|
||||
return errors.New("兜底类目缺少类目 ID 或类目名称,请重新创建批量任务")
|
||||
if rawCategory != "" && rawCategory != "{}" {
|
||||
var configured mtop.PublishCategory
|
||||
if err := json.Unmarshal([]byte(rawCategory), &configured); err != nil {
|
||||
return errors.New("默认类目配置损坏,请重新创建批量任务")
|
||||
}
|
||||
if strings.TrimSpace(configured.CatID) != "" || strings.TrimSpace(configured.CatName) != "" || strings.TrimSpace(configured.ChannelCatID) != "" || strings.TrimSpace(configured.TBCatID) != "" {
|
||||
if strings.TrimSpace(configured.CatID) == "" || strings.TrimSpace(configured.CatName) == "" || strings.TrimSpace(configured.ChannelCatID) == "" {
|
||||
return errors.New("默认类目信息不完整,请重新创建批量任务")
|
||||
}
|
||||
preferredCategory = &configured
|
||||
}
|
||||
}
|
||||
images, err := loadBatchPublishImages(ctx, batch.UploadDir, row)
|
||||
if err != nil {
|
||||
@@ -830,7 +900,7 @@ func (s *Server) publishBatchRow(ctx context.Context, userID int64, client mtop.
|
||||
PostageMode: row.PostageMode,
|
||||
PostageCents: postageCents,
|
||||
Virtual: true,
|
||||
FallbackCategory: &fallbackCategory,
|
||||
PreferredCategory: preferredCategory,
|
||||
Images: images,
|
||||
})
|
||||
value, valueChanged, handled, persistErr := s.persistMTopCookieSessionLocked(ctx, latest, cookieSession)
|
||||
@@ -1064,8 +1134,8 @@ func (s *Server) parsePublishRows(ctx context.Context, userID int64, defaultCook
|
||||
hasRowCategory := rowCategory.CatID != "" || rowCategory.CatName != "" || rowCategory.ChannelCatID != "" || rowCategory.TBCatID != ""
|
||||
if hasRowCategory {
|
||||
row.Category = rowCategory
|
||||
if rowCategory.CatID == "" || rowCategory.CatName == "" {
|
||||
row.Errors = append(row.Errors, "指定行类目时必须同时填写类目ID和类目名称")
|
||||
if rowCategory.CatID == "" || rowCategory.CatName == "" || rowCategory.ChannelCatID == "" {
|
||||
row.Errors = append(row.Errors, "指定行类目时必须同时填写类目ID、类目名称和频道类目ID")
|
||||
}
|
||||
} else {
|
||||
row.Category = fallbackCategory
|
||||
|
||||
@@ -97,6 +97,7 @@ func previewPublishBatch(t *testing.T, h http.Handler, cookie *http.Cookie) stri
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
csvField, _ := mw.CreateFormFile("file", "products.csv")
|
||||
csvField.Write([]byte("账号ID,标题,价格,库存,图片\nacc1,商品A,12.50,5,img/a.png\n"))
|
||||
zipField, _ := mw.CreateFormFile("images_zip", "images.zip")
|
||||
@@ -126,6 +127,7 @@ func previewTwoRowPublishBatch(t *testing.T, h http.Handler, cookie *http.Cookie
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
csvField, _ := mw.CreateFormFile("file", "products.csv")
|
||||
csvField.Write([]byte("账号ID,标题,价格,库存,图片\nacc1,商品A,12.50,5,img/a.png\nacc1,商品B,13.50,5,img/a.png\n"))
|
||||
zipField, _ := mw.CreateFormFile("images_zip", "images.zip")
|
||||
|
||||
@@ -81,6 +81,7 @@ func TestPreviewItemPublishBatchCSV(t *testing.T) {
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
csvField, _ := mw.CreateFormFile("file", "products.csv")
|
||||
csvField.Write([]byte("账号ID,标题,价格,库存,图片\nacc1,商品A,12.50,5,img/a.png\n"))
|
||||
zipField, _ := mw.CreateFormFile("images_zip", "images.zip")
|
||||
@@ -107,7 +108,7 @@ func TestPreviewItemPublishBatchCSV(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreviewItemPublishBatchRequiresFallbackCategory(t *testing.T) {
|
||||
func TestPreviewItemPublishBatchAllowsEmptyDefaultCategory(t *testing.T) {
|
||||
srv, _, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
h := srv.Router()
|
||||
@@ -124,9 +125,16 @@ func TestPreviewItemPublishBatchRequiresFallbackCategory(t *testing.T) {
|
||||
req.AddCookie(cookie)
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusBadRequest || !strings.Contains(rec.Body.String(), "兜底类目") {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var res map[string]any
|
||||
_ = json.Unmarshal(rec.Body.Bytes(), &res)
|
||||
row := res["rows"].([]any)[0].(map[string]any)
|
||||
category := row["category"].(map[string]any)
|
||||
if category["cat_id"] != "" || category["cat_name"] != "" {
|
||||
t.Fatalf("category should be empty: %+v", category)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreviewItemPublishBatchRowCategoryOverridesFallback(t *testing.T) {
|
||||
@@ -140,8 +148,9 @@ func TestPreviewItemPublishBatchRowCategoryOverridesFallback(t *testing.T) {
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "批次类目")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
file, _ := mw.CreateFormFile("file", "products.csv")
|
||||
file.Write([]byte("标题,价格,图片,类目ID,类目名称\n商品A,12.50,https://example.com/a.png,7001,行指定类目\n"))
|
||||
file.Write([]byte("标题,价格,图片,类目ID,类目名称,频道类目ID\n商品A,12.50,https://example.com/a.png,7001,行指定类目,8001\n"))
|
||||
_ = mw.Close()
|
||||
req := httptest.NewRequest(http.MethodPost, "/items/publish-batches/preview", &buf)
|
||||
req.Header.Set("Content-Type", mw.FormDataContentType())
|
||||
@@ -172,6 +181,7 @@ func TestPreviewItemPublishBatchNoFile(t *testing.T) {
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
_ = mw.Close()
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/items/publish-batches/preview", &buf)
|
||||
@@ -246,6 +256,7 @@ func TestPreviewItemPublishBatchTooManyRows(t *testing.T) {
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
csvField, _ := mw.CreateFormFile("file", "products.csv")
|
||||
csvField.Write(csvBuf.Bytes())
|
||||
_ = mw.Close()
|
||||
@@ -278,6 +289,7 @@ func TestPreviewItemPublishBatchZipTraversal(t *testing.T) {
|
||||
_ = mw.WriteField("default_cookie_id", "acc1")
|
||||
_ = mw.WriteField("fallback_category_id", "5001")
|
||||
_ = mw.WriteField("fallback_category_name", "虚拟商品")
|
||||
_ = mw.WriteField("fallback_channel_category_id", "6001")
|
||||
csvField, _ := mw.CreateFormFile("file", "products.csv")
|
||||
csvField.Write([]byte("账号ID,标题,价格,库存,图片\nacc1,商品A,12.50,5,../escape.png\n"))
|
||||
zipField, _ := mw.CreateFormFile("images_zip", "images.zip")
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.visible{visibility:visible}.fixed{positiLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.visible{visibility:visible}.fixed{positiLine truncated
|
||||
@@ -1,19 +0,0 @@
|
||||
import{j as e,r as i,b as Le,c as ba,d as ya}from"./react-vendor-DZnRGM0-.js";import{L as fa,U as Ut,S as Wt,C as Ys,B as Vt,Z as Zs,a as ps,b as rt,c as Gt,d as ja,e as ns,A as ht,D as Na,f as gt,P as Jt,g as ks,E as Qt,T as va,h as wa,i as Re,Q as zs,j as is,k as He,l as us,m as bt,R as Oe,n as Kt,o as _a,p as Je,X as _e,K as ka,q as rs,r as as,s as ss,t as es,u as yt,v as nt,w as hs,x as Yt,y as Zt,z as _s,F as Xt,G as Ca,H as ft,I as jt,J as Sa,M as La,N as Aa,O as Ia,V as Us,W as As,Y as Ht,_ as $a,$ as Ra,a0 as Xs,a1 as Pa,a2 as Da,a3 as Hs,a4 as Nt,a5 as Fa,a6 as Fs,a7 as ea,a8 as Ta,a9 as Ea,aa as it,ab as sa,ac as Ma,ad as Oa}from"./icons-vendor-RenKjhri.js";import{R as Is,B as qa,X as vt,Y as wt,T as Ws,a as Ba,C as Vs,A as za,b as Ua,c as Wa,P as _t,d as kt,L as Va}from"./charts-vendor-B_BfwiL0.js";import"./vendor-w5t2K9ux.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const x of document.querySelectorAll('link[rel="modulepreload"]'))d(x);new MutationObserver(x=>{for(const N of x)if(N.type==="childList")for(const S of N.addedNodes)S.tagName==="LINK"&&S.rel==="modulepreload"&&d(S)}).observe(document,{childList:!0,subtree:!0});function n(x){const N={};return x.integrity&&(N.integrity=x.integrity),x.referrerPolicy&&(N.referrerPolicy=x.referrerPolicy),x.crossOrigin==="use-credentials"?N.credentials="include":x.crossOrigin==="anonymous"?N.credentials="omit":N.credentials="same-origin",N}function d(x){if(x.ep)return;x.ep=!0;const N=n(x);fetch(x.href,N)}})();const Ga=({className:s="w-full h-full text-white"})=>e.jsx("svg",{className:s,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),et=({sizeClass:s="w-12 h-12",logoClassName:t="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${s} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#0094f7"}),e.jsx("stop",{offset:"100%",stopColor:"#287efe"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(rt,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Ls,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:v,children:"取消"}),e.jsxs("button",{onClick:os,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:v,children:[v?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(ss,{className:"w-4 h-4"}),v?"保存中...":"保存"]})]})})]})}),document.body)]})},Nr=s=>({total:Number((s==null?void 0:s.total)||0),success_count:Number((s==null?void 0:s.success_count)||0),failed_count:Number((s==null?void 0:s.failed_count)||0),results:Array.isArray(s==null?void 0:s.results)?s.results.map(t=>({order_id:String((t==null?void 0:t.order_id)||"unknown"),success:(t==null?void 0:t.success)===!0,message:String((t==null?void 0:t.message)||"")})):[]}),vr=s=>(s==null?void 0:s.results.filter(t=>!t.success))||[],Dt=({status:s})=>{const t={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},n={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${t[s]||t.cancelled}`,children:n[s]||s})},wr=()=>{const[s,t]=i.useState([]),[n,d]=i.useState([]),[x,N]=i.useState([]),[S,F]=i.useState({}),[h,R]=i.useState("all"),[b,J]=i.useState(""),[ae,le]=i.useState(""),[oe,k]=i.useState(""),B=i.useRef(0),[re,Q]=i.useState(1),[H,z]=i.useState(1),[xe,ce]=i.useState(!1),[w,D]=i.useState(!1),[U,G]=i.useState(!1),[me,A]=i.useState(!1),[I,Z]=i.useState(null),[L,se]=i.useState(null),[ee,ke]=i.useState({}),[T,m]=i.useState(!1),[g,E]=i.useState(""),[P,ne]=i.useState(!1),[ge,K]=i.useState(null),[ye,C]=i.useState(null),[o,_]=i.useState(null),[r,v]=i.useState(!1),[O,V]=i.useState(null),[q,he]=i.useState(null),te=async()=>{const u=++B.current;ce(!0);try{const $=await yl(b||void 0,h,re,20,oe);if(u!==B.current)return;t($.data),z($.total_pages)}catch($){console.error("加载订单失败:",$)}finally{u===B.current&&ce(!1)}},ue=(u,$,ie)=>{if(ie&&ie.trim())return ie;if(S[`${u}:${$}`])return S[`${u}:${$}`];const we=n.find(Ke=>{if(ie&&Ke.item_title){const Ye=ie.toLowerCase(),Ue=Ke.item_title.toLowerCase();return Ue.includes(Ye)||Ye.includes(Ue)}return!1});return we!=null&&we.item_title?we.item_title:"未知商品"},Ie=u=>{const $={};u.forEach(ie=>{ie.item_id&&($[`${ie.cookie_id}:${ie.item_id}`]=ie.item_title||ie.item_id)}),F($)};i.useEffect(()=>{const u=window.setTimeout(()=>{Q(1),k(ae.trim())},300);return()=>window.clearTimeout(u)},[ae]),i.useEffect(()=>{te()},[b,h,re,oe]),i.useEffect(()=>{Promise.all([Ms(),gs()]).then(([u,$])=>{N(u),d($),Ie($)}).catch(u=>{console.error("加载商品列表失败:",u)})},[]);const ve=i.useMemo(()=>new Map(x.map(u=>[u.id,u])),[x]),Ve=u=>{const $=ve.get(u),ie=($==null?void 0:$.remark)||($==null?void 0:$.nickname);return ie?`${ie} · ${u.slice(0,6)}`:`账号 ${u.slice(0,8)}`},$e=u=>{const $=ve.get(u);return($==null?void 0:$.remark)||($==null?void 0:$.nickname)||"未命名账号"},Te=async()=>{ce(!0);try{const u=await Nl(b||void 0,h);await te(),u!=null&&u.message&&alert(u.message)}catch(u){console.error("同步订单失败:",u),alert((u==null?void 0:u.message)||"同步失败,请重试")}finally{ce(!1)}},qe=u=>{E(u),K(null),m(!0)},Ee=async u=>{var $;ne(!0),K(null);try{const ie=await wl([g],u),we=($=ie==null?void 0:ie.results)==null?void 0:$[0];we!=null&&we.success?(K({success:!0,message:we.message}),te()):K({success:!1,message:(we==null?void 0:we.message)||"发货失败"})}catch(ie){K({success:!1,message:(ie==null?void 0:ie.message)||"请求失败"})}finally{ne(!1)}},Ge=u=>{Z(u),D(!0)},Be=u=>{se({...u}),G(!0)},Pe=async()=>{if(!(!L||!L.order_id))try{const u={};L.status!==void 0&&(u.order_status=L.status),L.buyer_id!==void 0&&(u.buyer_id=L.buyer_id),L.amount!==void 0&&(u.amount=L.amount),L.receiver_name!==void 0&&(u.receiver_name=L.receiver_name),L.receiver_
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(q=>q.map(he=>`"${String(he).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),v=new Blob(["\uFEFF"+r],{type:"text/csv;charset=utf-8"}),O=URL.createObjectURL(v),V=document.createElement("a");V.href=O,V.download="卡密组批量导入模板.csv",document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(O)},K=async()=>{if(B){xe(!0),H(null);try{const o=await Il(B);if(H(o),o.created>0){const _=await Xe();t(_)}}catch(o){H({error:(o==null?void 0:o.message)||"上传失败"})}finally{xe(!1)}}},ye=async()=>{if(!(!ce||!D.trim())){xe(!0),me(null);try{const o=await $l(ce,D);me({added:o.added}),U("");const _=await Xe();t(_)}catch(o){alert("追加失败:"+((o==null?void 0:o.message)||"未知错误"))}finally{xe(!1)}}},C=()=>{var o;k("create"),re(null),H(null),w((o=P[0])!=null&&o.id?String(P[0].id):""),U(""),me(null),le(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:C,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(_s,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>N(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(es,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-[#FAFAFA] p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(Xt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:A,onChange:o=>I(o.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:Z,onChange:o=>L(o.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",ne.length," / ",s.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:ne.map(o=>{let _="";return o.type==="data"&&o.data_content?_=`库存: ${o.data_content.split(`
|
||||
`).filter(v=>v.trim()).length} 条`:o.type==="text"&&o.text_content?_=o.text_content:o.type==="api"&&o.api_config?_=o.api_config.url:o.type==="image"&&o.image_url&&(_="图片链接"),e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(se,{type:o.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:o.name,children:o.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>E(o.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:o.id}),e.jsx(Ca,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${o.type==="text"?"bg-blue-50 text-blue-600":o.type==="data"?"bg-purple-50 text-purple-600":o.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:o.type==="text"?"文本":o.type==="data"?"批量":o.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:_,children:_})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:o.description||"-",children:o.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>g(o),className:`w-12 h-8 rounded-full relative transition-colors ${o.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${o.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>ee(o),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(hs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>T(o.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Je,{className:"h-4 w-4"})})]})})]},o.id)})})]})}),ne.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(Jt,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:s.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),n&&S&&Le.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>d(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(_e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:h.name||"",onChange:o=>R({...h,name:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:h.type||"text",onChange:o=>R({...h,type:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(S==null?void 0:S.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),h.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:h.api_url||"",onChange:o=>R({...h,api_url:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码1
|
||||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:h.data_content?h.data_content.split(`
|
||||
`).filter(o=>o.trim()).length:0})," 条"]})]})]}),h.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:h.image_url||"",onChange:o=>R({...h,image_url:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),h.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:h.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:o=>{o.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:h.delay_seconds||0,onChange:o=>R({...h,delay_seconds:parseInt(o.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:h.description||"",onChange:o=>R({...h,description:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>R({...h,enabled:!h.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${h.enabled?"bg-[#0094f7]":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${h.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>d(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:ke,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(ss,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),x&&Le.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>N(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(_e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:b.name,onChange:o=>J({...b,name:o.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>J({...b,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="data"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(Ys,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>J({...b,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="text"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(ft,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>J({...b,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="image"?"bg-[#0094f7] text-white":"bg-gray-100 text-grayLine truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),b.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-[#0094f7]",children:b.content.split(`
|
||||
`).filter(o=>o.trim()).length})," 条"]})]}),b.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:b.api_method,onChange:o=>J({...b,api_method:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:b.api_timeout,onChange:o=>J({...b,api_timeout:parseInt(o.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:b.api_headers,onChange:o=>J({...b,api_headers:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:b.api_params,onChange:o=>J({...b,api_params:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:b.description,onChange:o=>J({...b,description:o.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:b.delay_seconds,onChange:o=>J({...b,delay_seconds:parseInt(o.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>N(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(es,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),ae&&Le.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>le(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(_e,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>k("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Sa,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>k("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(_s,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),oe==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:ge,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 tex
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),G&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",G.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>le(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),oe==="create"?e.jsxs("button",{onClick:K,disabled:!B||z,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[z?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(_s,{className:"w-4 h-4"}),z?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:ye,disabled:!ce||!D.trim()||z||P.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[z?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(es,{className:"w-4 h-4"}),z?"处理中...":"追加卡密"]})]})]})}),document.body)]})},Cr=s=>s.find(t=>t.status==="running"||t.status==="canceling"),Sr=s=>{const t=String(s||"").trim();return t?/^[¥¥]/.test(t)?t:`¥${t}`:"-"},Lr=({onConfigureDelivery:s})=>{const[t,n]=i.useState([]),[d,x]=i.useState([]),[N,S]=i.useState([]),[F,h]=i.useState(""),[R,b]=i.useState(""),[J,ae]=i.useState(!1),[le,oe]=i.useState(!1),[k,B]=i.useState(!1),[re,Q]=i.useState(!1),[H,z]=i.useState(!1),[xe,ce]=i.useState(!1),[w,D]=i.useState(!1),[U,G]=i.useState("upload"),[me,A]=i.useState(null),[I,Z]=i.useState(null),[L,se]=i.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[ee,ke]=i.useState(null),[T,m]=i.useState(null),[g,E]=i.useState(null),P=i.useRef(!1),[ne,ge]=i.useState(null),[K,ye]=i.useState({}),[C,o]=i.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[_,r]=i.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[v,O]=i.useState([]),V=i.useMemo(()=>{const l=new Map;return t.forEach(y=>{const Y=String(y.item_category||"").trim();if(!Y)return;let Ce="";try{const Me=JSON.parse(y.item_detail||"{}");Ce=String(Me.category_name||"").trim()}catch{}(!l.has(Y)||Ce)&&l.set(Y,Ce)}),Array.from(l,([y,Y])=>({catId:y,catName:Y}))},[t]);i.useEffect(()=>{if(!xe||_.images.length===0){O([]);return}const l=_.images.map((y,Y)=>({key:y.name+Y,url:URL.createObjectURL(y)}));return O(l),()=>{l.forEach(y=>URL.revokeObjectURL(y.url))}},[xe,_.images]);const q=async()=>{const l=await gs();n(l)},he=async()=>{x(await tt())};i.useEffect(()=>{Promise.all([Ms(),gs(),tt(),At(20)]).then(([l,y,Y,Ce])=>{S(l),n(y),x(Y);const Me=Ce.find(De=>["running","canceling"].includes(De.status))||Ce.find(De=>De.status!=="preview");E(Me||null)}).catch(l=>console.error("加载商品配置失败:",l))},[]),i.useEffect(()=>{if(!w||!(T!=null&&T.id)||!["running","canceling"].includes(T.status))return;const l=window.setInterval(async()=>{if(!P.current){P.current=!0;try{const y=await xs(T.id);m(y),E(y),["running","canceling"].includes(y.status)||(G("done"),await q(),await he())}catch(y){console.error("刷新批量铺货进度失败:",y)}finally{P.current=!1}}},3e3);return()=>{window.clearInterval(l)}},[w,T==null?void 0:T.id,T==null?void 0:T.status]);const te=async()=>{if(!F)return alert("请先选择账号");ae(!0);try{const l=await Rl(F);await q(),alert((l==null?void 0:l.message)||"商品同步完成")}catch(l){console.error("同步商品失败:",l),alert((l==null?void 0:l.message)||"同步失败,请重试")}finally{ae(!1)}},ue=l=>{ge(l),ye({...l}),Q(!0)},Ie=async()=>{if(ne)try{await Bl(ne.cookie_id,ne.item_id,{item_title:K.item_title||"",item_description:K.item_description||"",item_category:K.item_category||"",item_price:K.item_price||"",item_detail:K.item_detail||ne.item_detail||""}),await q(),await he(),Q(!1),ge(null)}catch(l){console.error("更新商品失败:",l),alert("更新失败,请重试")}},ve=async l=>{if(confirm(`确认删除商品"${l.item_title}"吗?`))try{await Pl(l.cookie_id,l.item_id),n(y=>y.filter(Y=>!(Y.cookie_id===l.cookie_id&&Y.item_id===l.item_id)))}catch(y){console.error("删除商品失败:",y),alert("删除失败,请重试")}},Ve=async()=>{try{if(!C.cookie_id||!C.item_id){alert("请选择账号并填写商品ID");return}await Dl(C.cookie_id,{item_id:C.item_id,item_title:C.item_title,item_price:C.item_price,item_detail:C.item_image?JSON.stringify({item_image:C.item_image}):""}),await q(),z(!1),o({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(l){console.error("添加商品失败:",l),alert("添加失败,请重试")}},$e=async()=>{if(!_.cookie_id)return alert("请选择发布账号");if(!_.title.trim())return alert("请填写商品标
Line truncated
|
||||
`),Ce=new Blob(["\uFEFF"+Y],{type:"text/csv;charset=utf-8"}),Me=URL.createObjectURL(Ce),De=document.createElement("a");De.href=Me,De.download="批量铺货模板.csv",document.body.appendChild(De),De.click(),De.remove(),URL.revokeObjectURL(Me)},ze=()=>{o(l=>({...l,cookie_id:F||l.cookie_id})),z(!0)},u=()=>{r(l=>({...l,cookie_id:F||l.cookie_id})),ce(!0)},$=l=>d.filter(y=>y.cookie_id===l.cookie_id&&y.item_id===l.item_id).length>0?d.filter(y=>y.cookie_id===l.cookie_id&&y.item_id===l.item_id):d.filter(y=>y.cookie_id===l.cookie_id&&!y.item_id),ie=l=>{switch(l){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return l||"-"}},we=l=>{switch(l){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},Ke=i.useMemo(()=>new Map(N.map(l=>[l.id,l])),[N]),Ye=i.useMemo(()=>R?t.filter(l=>l.cookie_id===R):t,[R,t]),Ue=l=>{const y=Ke.get(l),Y=(y==null?void 0:y.remark)||(y==null?void 0:y.nickname);return Y?`${Y} · ${l.slice(0,6)}`:`账号 ${l.slice(0,8)}`},We=l=>{const y=Ke.get(l);return(y==null?void 0:y.remark)||(y==null?void 0:y.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ia,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:l=>b(l.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),N.map(l=>e.jsx("option",{value:l.id,children:Ue(l.id)},l.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(is,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:F,onChange:l=>h(l.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),N.map(l=>e.jsx("option",{value:l.id,children:Ue(l.id)},l.id))]})]})]}),e.jsxs("button",{onClick:te,disabled:J||!F,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Oe,{className:`w-4 h-4 ${J?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:ze,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(es,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:u,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Us,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Te(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(As,{className:"w-4 h-4"}),g&&["running","canceling"].includes(g.status)?"继续批量任务":"批量铺货"]}),g&&!["running","canceling"].includes(g.status)&&e.jsx("button",{onClick:()=>void qe(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[Ye.map(l=>{const y=$(l),Y=y.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex
Line truncated
|
||||
@@ -0,0 +1,19 @@
|
||||
import{j as e,r as i,b as Le,c as ba,d as ya}from"./react-vendor-DZnRGM0-.js";import{L as fa,U as Wt,S as Vt,C as Zs,B as Gt,Z as Xs,a as ys,b as it,c as Jt,d as ja,e as cs,A as gt,D as Na,f as bt,P as Kt,g as Ls,E as Qt,T as va,h as wa,i as $e,Q as Us,j as ds,k as ss,l as bs,m as yt,R as Oe,n as Yt,o as _a,p as Je,X as ve,K as ka,q as os,r as rs,s as as,t as ts,u as ft,v as As,w as fs,x as Zt,y as Xt,z as Ss,F as Ht,G as Ca,H as jt,I as Nt,J as Sa,M as La,N as Aa,O as Ia,V as Ws,W as $s,Y as Hs,_ as $a,$ as Ra,a0 as et,a1 as Pa,a2 as Da,a3 as st,a4 as vt,a5 as Fa,a6 as Es,a7 as ea,a8 as Ta,a9 as Ea,aa as ot,ab as sa,ac as Ma,ad as Oa}from"./icons-vendor-RenKjhri.js";import{R as Rs,B as qa,X as wt,Y as _t,T as Vs,a as Ba,C as Gs,A as za,b as Ua,c as Wa,P as kt,d as Ct,L as Va}from"./charts-vendor-B_BfwiL0.js";import"./vendor-w5t2K9ux.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const x of document.querySelectorAll('link[rel="modulepreload"]'))d(x);new MutationObserver(x=>{for(const w of x)if(w.type==="childList")for(const S of w.addedNodes)S.tagName==="LINK"&&S.rel==="modulepreload"&&d(S)}).observe(document,{childList:!0,subtree:!0});function r(x){const w={};return x.integrity&&(w.integrity=x.integrity),x.referrerPolicy&&(w.referrerPolicy=x.referrerPolicy),x.crossOrigin==="use-credentials"?w.credentials="include":x.crossOrigin==="anonymous"?w.credentials="omit":w.credentials="same-origin",w}function d(x){if(x.ep)return;x.ep=!0;const w=r(x);fetch(x.href,w)}})();const Ga=({className:s="w-full h-full text-white"})=>e.jsx("svg",{className:s,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),tt=({sizeClass:s="w-12 h-12",logoClassName:t="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${s} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#0094f7"}),e.jsx("stop",{offset:"100%",stopColor:"#287efe"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23.51 12.25 L 27.29 10.34 L 31.54 8.78 L 36.33 7.56 L 41.84 6.69 L 48.52 6.17 L 60.00 6.00 L 71.48 6.17 L 78.16 6.69 L 83.67 7.56 L 88Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(it,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:us,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:y,children:"取消"}),e.jsxs("button",{onClick:Z,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:y,children:[y?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsx(as,{className:"w-4 h-4"}),y?"保存中...":"保存"]})]})})]})}),document.body)]})},vr=s=>({total:Number((s==null?void 0:s.total)||0),success_count:Number((s==null?void 0:s.success_count)||0),failed_count:Number((s==null?void 0:s.failed_count)||0),results:Array.isArray(s==null?void 0:s.results)?s.results.map(t=>({order_id:String((t==null?void 0:t.order_id)||"unknown"),success:(t==null?void 0:t.success)===!0,message:String((t==null?void 0:t.message)||"")})):[]}),wr=s=>(s==null?void 0:s.results.filter(t=>!t.success))||[],Ft=({status:s})=>{const t={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},r={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${t[s]||t.cancelled}`,children:r[s]||s})},_r=()=>{const[s,t]=i.useState([]),[r,d]=i.useState([]),[x,w]=i.useState([]),[S,F]=i.useState({}),[g,R]=i.useState("all"),[b,G]=i.useState(""),[se,re]=i.useState(""),[ie,k]=i.useState(""),B=i.useRef(0),[ne,J]=i.useState(1),[Y,z]=i.useState(1),[xe,oe]=i.useState(!1),[_,T]=i.useState(!1),[U,V]=i.useState(!1),[me,L]=i.useState(!1),[A,K]=i.useState(null),[I,ae]=i.useState(null),[we,Ce]=i.useState({}),[ue,m]=i.useState(!1),[h,q]=i.useState(""),[j,te]=i.useState(!1),[le,H]=i.useState(null),[je,P]=i.useState(null),[o,D]=i.useState(null),[n,y]=i.useState(!1),[E,C]=i.useState(null),[M,he]=i.useState(null),X=async()=>{const u=++B.current;oe(!0);try{const $=await yl(b||void 0,g,ne,20,ie);if(u!==B.current)return;t($.data),z($.total_pages)}catch($){console.error("加载订单失败:",$)}finally{u===B.current&&oe(!1)}},ee=(u,$,ce)=>{if(ce&&ce.trim())return ce;if(S[`${u}:${$}`])return S[`${u}:${$}`];const _e=r.find(Ye=>{if(ce&&Ye.item_title){const Ze=ce.toLowerCase(),Xe=Ye.item_title.toLowerCase();return Xe.includes(Ze)||Ze.includes(Xe)}return!1});return _e!=null&&_e.item_title?_e.item_title:"未知商品"},Se=u=>{const $={};u.forEach(ce=>{ce.item_id&&($[`${ce.cookie_id}:${ce.item_id}`]=ce.item_title||ce.item_id)}),F($)};i.useEffect(()=>{const u=window.setTimeout(()=>{J(1),k(se.trim())},300);return()=>window.clearTimeout(u)},[se]),i.useEffect(()=>{X()},[b,g,ne,ie]),i.useEffect(()=>{Promise.all([qs(),js()]).then(([u,$])=>{w(u),d($),Se($)}).catch(u=>{console.error("加载商品列表失败:",u)})},[]);const Ne=i.useMemo(()=>new Map(x.map(u=>[u.id,u])),[x]),We=u=>{const $=Ne.get(u),ce=($==null?void 0:$.remark)||($==null?void 0:$.nickname);return ce?`${ce} · ${u.slice(0,6)}`:`账号 ${u.slice(0,8)}`},Ie=u=>{const $=Ne.get(u);return($==null?void 0:$.remark)||($==null?void 0:$.nickname)||"未命名账号"},Fe=async()=>{oe(!0);try{const u=await Nl(b||void 0,g);await X(),u!=null&&u.message&&alert(u.message)}catch(u){console.error("同步订单失败:",u),alert((u==null?void 0:u.message)||"同步失败,请重试")}finally{oe(!1)}},qe=u=>{q(u),H(null),m(!0)},Te=async u=>{var $;te(!0),H(null);try{const ce=await wl([h],u),_e=($=ce==null?void 0:ce.results)==null?void 0:$[0];_e!=null&&_e.success?(H({success:!0,message:_e.message}),X()):H({success:!1,message:(_e==null?void 0:_e.message)||"发货失败"})}catch(ce){H({success:!1,message:(ce==null?void 0:ce.message)||"请求失败"})}finally{te(!1)}},Ve=u=>{K(u),T(!0)},Ee=u=>{ae({...u}),V(!0)},Re=async()=>{if(!(!I||!I.order_id))try{const u={};I.status!==void 0&&(u.order_status=I.status),I.buyer_id!==void 0&&(u.buyer_id=I.buyer_id),I.amount!==void 0&&(u.amount=I.amount),I.receiver_name!==void 0&&(u.receiver_name=I.receiver_name),I.receiver_phon
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(M=>M.map(he=>`"${String(he).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),y=new Blob(["\uFEFF"+n],{type:"text/csv;charset=utf-8"}),E=URL.createObjectURL(y),C=document.createElement("a");C.href=E,C.download="卡密组批量导入模板.csv",document.body.appendChild(C),C.click(),C.remove(),URL.revokeObjectURL(E)},H=async()=>{if(B){xe(!0),Y(null);try{const o=await Il(B);if(Y(o),o.created>0){const D=await es();t(D)}}catch(o){Y({error:(o==null?void 0:o.message)||"上传失败"})}finally{xe(!1)}}},je=async()=>{if(!(!oe||!T.trim())){xe(!0),me(null);try{const o=await $l(oe,T);me({added:o.added}),U("");const D=await es();t(D)}catch(o){alert("追加失败:"+((o==null?void 0:o.message)||"未知错误"))}finally{xe(!1)}}},P=()=>{var o;k("create"),ne(null),Y(null),_((o=j[0])!=null&&o.id?String(j[0].id):""),U(""),me(null),re(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:P,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Ss,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>w(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(ts,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-[#FAFAFA] p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(Ht,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:L,onChange:o=>A(o.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(As,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:K,onChange:o=>I(o.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",te.length," / ",s.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:te.map(o=>{let D="";return o.type==="data"&&o.data_content?D=`库存: ${o.data_content.split(`
|
||||
`).filter(y=>y.trim()).length} 条`:o.type==="text"&&o.text_content?D=o.text_content:o.type==="api"&&o.api_config?D=o.api_config.url:o.type==="image"&&o.image_url&&(D="图片链接"),e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(ae,{type:o.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:o.name,children:o.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>q(o.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:o.id}),e.jsx(Ca,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${o.type==="text"?"bg-blue-50 text-blue-600":o.type==="data"?"bg-purple-50 text-purple-600":o.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:o.type==="text"?"文本":o.type==="data"?"批量":o.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:D,children:D})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:o.description||"-",children:o.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>h(o),className:`w-12 h-8 rounded-full relative transition-colors ${o.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${o.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>we(o),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(fs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ue(o.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Je,{className:"h-4 w-4"})})]})})]},o.id)})})]})}),te.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(Kt,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:s.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),r&&S&&Le.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>d(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(ve,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:g.name||"",onChange:o=>R({...g,name:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:g.type||"text",onChange:o=>R({...g,type:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(S==null?void 0:S.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),g.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:g.api_url||"",onChange:o=>R({...g,api_url:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码1
|
||||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:g.data_content?g.data_content.split(`
|
||||
`).filter(o=>o.trim()).length:0})," 条"]})]})]}),g.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:g.image_url||"",onChange:o=>R({...g,image_url:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),g.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:g.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:o=>{o.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:g.delay_seconds||0,onChange:o=>R({...g,delay_seconds:parseInt(o.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:g.description||"",onChange:o=>R({...g,description:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>R({...g,enabled:!g.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${g.enabled?"bg-[#0094f7]":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${g.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>d(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Ce,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),x&&Le.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>w(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(ve,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:b.name,onChange:o=>G({...b,name:o.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>G({...b,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="data"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(Zs,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>G({...b,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="text"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(jt,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>G({...b,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${b.type==="image"?"bg-[#0094f7] text-white":"bg-gray-100 text-grayLine truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),b.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-[#0094f7]",children:b.content.split(`
|
||||
`).filter(o=>o.trim()).length})," 条"]})]}),b.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:b.api_method,onChange:o=>G({...b,api_method:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:b.api_timeout,onChange:o=>G({...b,api_timeout:parseInt(o.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:b.api_headers,onChange:o=>G({...b,api_headers:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:b.api_params,onChange:o=>G({...b,api_params:o.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:b.description,onChange:o=>G({...b,description:o.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:b.delay_seconds,onChange:o=>G({...b,delay_seconds:parseInt(o.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>w(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),se&&Le.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>re(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(ve,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>k("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${ie==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Sa,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>k("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${ie==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ss,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),ie==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:le,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 tex
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),V&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",V.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>re(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),ie==="create"?e.jsxs("button",{onClick:H,disabled:!B||z,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[z?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsx(Ss,{className:"w-4 h-4"}),z?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:je,disabled:!oe||!T.trim()||z||j.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[z?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsx(ts,{className:"w-4 h-4"}),z?"处理中...":"追加卡密"]})]})]})}),document.body)]})},Sr=s=>s.find(t=>t.status==="running"||t.status==="canceling"),Lr=s=>{const t=String(s||"").trim();return t?/^[¥¥]/.test(t)?t:`¥${t}`:"-"},Ar=({onConfigureDelivery:s})=>{const[t,r]=i.useState([]),[d,x]=i.useState([]),[w,S]=i.useState([]),[F,g]=i.useState(""),[R,b]=i.useState(""),[G,se]=i.useState(!1),[re,ie]=i.useState(!1),[k,B]=i.useState(!1),[ne,J]=i.useState(!1),[Y,z]=i.useState(!1),[xe,oe]=i.useState(!1),[_,T]=i.useState(!1),[U,V]=i.useState("upload"),[me,L]=i.useState(null),[A,K]=i.useState(null),[I,ae]=i.useState(""),[we,Ce]=i.useState(!1),[ue,m]=i.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[h,q]=i.useState(null),[j,te]=i.useState(null),[le,H]=i.useState(null),je=i.useRef(!1),[P,o]=i.useState(null),[D,n]=i.useState({}),[y,E]=i.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[C,M]=i.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[he,X]=i.useState([]);i.useEffect(()=>{if(!xe||C.images.length===0){X([]);return}const l=C.images.map((N,Z)=>({key:N.name+Z,url:URL.createObjectURL(N)}));return X(l),()=>{l.forEach(N=>URL.revokeObjectURL(N.url))}},[xe,C.images]);const ee=async()=>{const l=await js();r(l)},Se=async()=>{x(await lt())};i.useEffect(()=>{Promise.all([qs(),js(),lt(),It(20)]).then(([l,N,Z,Ue])=>{S(l),r(N),x(Z);const Ge=Ue.find(Pe=>["running","canceling"].includes(Pe.status))||Ue.find(Pe=>Pe.status!=="preview");H(Ge||null)}).catch(l=>console.error("加载商品配置失败:",l))},[]),i.useEffect(()=>{if(!_||!(j!=null&&j.id)||!["running","canceling"].includes(j.status))return;const l=window.setInterval(async()=>{if(!je.current){je.current=!0;try{const N=await hs(j.id);te(N),H(N),["running","canceling"].includes(N.status)||(V("done"),await ee(),await Se())}catch(N){console.error("刷新批量铺货进度失败:",N)}finally{je.current=!1}}},3e3);return()=>{window.clearInterval(l)}},[_,j==null?void 0:j.id,j==null?void 0:j.status]);const Ne=async()=>{if(!F)return alert("请先选择账号");se(!0);try{const l=await Rl(F);await ee(),alert((l==null?void 0:l.message)||"商品同步完成")}catch(l){console.error("同步商品失败:",l),alert((l==null?void 0:l.message)||"同步失败,请重试")}finally{se(!1)}},We=l=>{o(l),n({...l}),J(!0)},Ie=async()=>{if(P)try{await zl(P.cookie_id,P.item_id,{item_title:D.item_title||"",item_description:D.item_description||"",item_category:D.item_category||"",item_price:D.item_price||"",item_detail:D.item_detail||P.item_detail||""}),await ee(),await Se(),J(!1),o(null)}catch(l){console.error("更新商品失败:",l),alert("更新失败,请重试")}},Fe=async l=>{if(confirm(`确认删除商品"${l.item_title}"吗?`))try{await Pl(l.cookie_id,l.item_id),r(N=>N.filter(Z=>!(Z.cookie_id===l.cookie_id&&Z.item_id===l.item_id)))}catch(N){console.error("删除商品失败:",N),alert("删除失败,请重试")}},qe=async()=>{try{if(!y.cookie_id||!y.item_id){alert("请选择账号并填写商品ID");return}await Dl(y.cookie_id,{item_id:y.item_id,item_title:y.item_title,item_price:y.item_price,item_detail:y.item_image?JSON.stringify({item_image:y.item_image}):""}),await ee(),z(!1),E({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(l){console.error("添加商品失败:",l),alert("添加失败,请重试")}},Te=async()=>{if(!C.cookie_id)return alert("请选择发布账号");if(!C.title.trim())return alert("请填写商品标题");if(!C.price.trim())return alert("请填写商品价格");if(!C.quantity||Number(C.quantity)<=0)return alert("库存数量必须大于 0");if(C.images.length===0)return alert("至少上传 1 张商品图片");if(C.postage_mode==="fixed"&&!C.p
Line truncated
|
||||
`),Ue=new Blob(["\uFEFF"+Z],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Ue),Pe=document.createElement("a");Pe.href=Ge,Pe.download="批量铺货模板.csv",document.body.appendChild(Pe),Pe.click(),Pe.remove(),URL.revokeObjectURL(Ge)},_e=()=>{E(l=>({...l,cookie_id:F||l.cookie_id})),z(!0)},Ye=()=>{M(l=>({...l,cookie_id:F||l.cookie_id})),oe(!0)},Ze=l=>d.filter(N=>N.cookie_id===l.cookie_id&&N.item_id===l.item_id).length>0?d.filter(N=>N.cookie_id===l.cookie_id&&N.item_id===l.item_id):d.filter(N=>N.cookie_id===l.cookie_id&&!N.item_id),Xe=l=>{switch(l){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return l||"-"}},Be=l=>{switch(l){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},ze=i.useMemo(()=>new Map(w.map(l=>[l.id,l])),[w]),xs=i.useMemo(()=>R?t.filter(l=>l.cookie_id===R):t,[R,t]),He=l=>{const N=ze.get(l),Z=(N==null?void 0:N.remark)||(N==null?void 0:N.nickname);return Z?`${Z} · ${l.slice(0,6)}`:`账号 ${l.slice(0,8)}`},ms=l=>{const N=ze.get(l);return(N==null?void 0:N.remark)||(N==null?void 0:N.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ia,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:l=>b(l.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),w.map(l=>e.jsx("option",{value:l.id,children:He(l.id)},l.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ds,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:F,onChange:l=>g(l.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),w.map(l=>e.jsx("option",{value:l.id,children:He(l.id)},l.id))]})]})]}),e.jsxs("button",{onClick:Ne,disabled:G||!F,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Oe,{className:`w-4 h-4 ${G?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:_e,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(ts,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:Ye,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Ws,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Ve(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx($s,{className:"w-4 h-4"}),le&&["running","canceling"].includes(le.status)?"继续批量任务":"批量铺货"]}),le&&!["running","canceling"].includes(le.status)&&e.jsx("button",{onClick:()=>void Re(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[xs.map(l=>{const N=Ze(l),Z=N.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relat
Line truncated
|
||||
@@ -6,12 +6,12 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Ydisks闲鱼助手 - 自动发货与管家系统</title>
|
||||
<meta name="description" content="Ydisks闲鱼助手 - 自动回复、自动发货、订单管理、AI智能议价一体化解决方案" />
|
||||
<script type="module" crossorigin src="/static/assets/index-D1qb4SVL.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-av934L0W.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-DZnRGM0-.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-RenKjhri.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/vendor-w5t2K9ux.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/charts-vendor-B_BfwiL0.js">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-BgaWj1th.css">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-C7AaUlyC.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
+138
-24
@@ -65,7 +65,7 @@ type PublishImage struct {
|
||||
}
|
||||
|
||||
// PublishCategory 是发布商品时可使用的人工兜底类目。
|
||||
// CatID 和 CatName 必填;频道类目、淘宝类目 ID 没有时可以留空。
|
||||
// CatID、CatName 和 ChannelCatID 必填;部分闲鱼类目没有 TBCatID。
|
||||
type PublishCategory struct {
|
||||
CatID string `json:"cat_id"`
|
||||
CatName string `json:"cat_name"`
|
||||
@@ -73,6 +73,16 @@ type PublishCategory struct {
|
||||
TBCatID string `json:"tb_cat_id,omitempty"`
|
||||
}
|
||||
|
||||
// DefaultVirtualPublishCategory 是从闲鱼类目推荐响应中核实的“电子资料”类目。
|
||||
// 该类目没有 tbCatId,发布时必须保留为空而不是伪造淘宝类目 ID。
|
||||
func DefaultVirtualPublishCategory() PublishCategory {
|
||||
return PublishCategory{
|
||||
CatID: "50023914",
|
||||
CatName: "电子资料",
|
||||
ChannelCatID: "202036301",
|
||||
}
|
||||
}
|
||||
|
||||
type PublishItemRequest struct {
|
||||
Title string
|
||||
Description string
|
||||
@@ -82,9 +92,9 @@ type PublishItemRequest struct {
|
||||
PostageMode string
|
||||
PostageCents int64
|
||||
// Virtual 表示商品只通过系统的虚拟发货流程交付,不需要实物发货地址。
|
||||
Virtual bool
|
||||
FallbackCategory *PublishCategory
|
||||
Images []PublishImage
|
||||
Virtual bool
|
||||
PreferredCategory *PublishCategory
|
||||
Images []PublishImage
|
||||
}
|
||||
|
||||
type PublishItemResult struct {
|
||||
@@ -125,8 +135,8 @@ func (c *ClientImpl) PublishItem(ctx context.Context, cookiesStr string, req Pub
|
||||
if len(req.Images) > 9 {
|
||||
return nil, errors.New("商品图片最多 9 张")
|
||||
}
|
||||
if req.FallbackCategory != nil && !validPublishCategory(*req.FallbackCategory) {
|
||||
return nil, errors.New("兜底类目必须同时填写类目 ID 和类目名称")
|
||||
if req.PreferredCategory != nil && !validPublishCategory(*req.PreferredCategory) {
|
||||
return nil, errors.New("默认类目必须同时包含类目 ID、类目名称和频道类目 ID")
|
||||
}
|
||||
currentCookies := cookiesStr
|
||||
if session := cookieSessionFromContext(ctx); session != nil {
|
||||
@@ -143,15 +153,22 @@ func (c *ClientImpl) PublishItem(ctx context.Context, cookiesStr string, req Pub
|
||||
}
|
||||
uploaded = append(uploaded, res)
|
||||
}
|
||||
category, updated, err := c.recommendPublishCategory(ctx, currentCookies, req.Title, req.Description, uploaded)
|
||||
if updated != "" {
|
||||
currentCookies = updated
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrPublishCategoryUnrecognized) && req.FallbackCategory != nil {
|
||||
category = fallbackPublishCategory(*req.FallbackCategory)
|
||||
} else {
|
||||
return nil, err
|
||||
var category map[string]any
|
||||
var updated string
|
||||
var err error
|
||||
if req.PreferredCategory != nil {
|
||||
category = fallbackPublishCategory(*req.PreferredCategory)
|
||||
} else {
|
||||
category, updated, err = c.recommendPublishCategory(ctx, currentCookies, req.Title, req.Description, uploaded)
|
||||
if updated != "" {
|
||||
currentCookies = updated
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrPublishCategoryUnrecognized) {
|
||||
category = fallbackPublishCategory(DefaultVirtualPublishCategory())
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
var location map[string]any
|
||||
@@ -167,6 +184,29 @@ func (c *ClientImpl) PublishItem(ctx context.Context, cookiesStr string, req Pub
|
||||
return c.publishItemOnce(ctx, currentCookies, req, uploaded, category, location)
|
||||
}
|
||||
|
||||
// RecommendPublishCategory 根据关键词调用闲鱼推荐接口,返回可直接用于发布的完整类目。
|
||||
func (c *ClientImpl) RecommendPublishCategory(ctx context.Context, cookiesStr, keyword string) (PublishCategory, string, error) {
|
||||
keyword = strings.TrimSpace(keyword)
|
||||
if keyword == "" {
|
||||
return PublishCategory{}, cookiesStr, errors.New("类目关键词不能为空")
|
||||
}
|
||||
data, updated, err := c.recommendPublishCategory(ctx, cookiesStr, keyword, keyword, nil)
|
||||
if err != nil {
|
||||
return PublishCategory{}, updated, err
|
||||
}
|
||||
cat := mapFromAny(data["categoryPredictResult"])
|
||||
category := PublishCategory{
|
||||
CatID: strings.TrimSpace(mtopString(cat["catId"])),
|
||||
CatName: strings.TrimSpace(mtopString(cat["catName"])),
|
||||
ChannelCatID: strings.TrimSpace(mtopString(cat["channelCatId"])),
|
||||
TBCatID: strings.TrimSpace(mtopString(cat["tbCatId"])),
|
||||
}
|
||||
if !validPublishCategory(category) {
|
||||
return PublishCategory{}, updated, fmt.Errorf("%w: 推荐结果缺少完整类目路径", ErrPublishCategoryUnrecognized)
|
||||
}
|
||||
return category, updated, nil
|
||||
}
|
||||
|
||||
func (c *ClientImpl) uploadPublishImage(ctx context.Context, cookiesStr string, img PublishImage) (uploadedImage, string, error) {
|
||||
hc := c.HTTPClient
|
||||
if hc == nil {
|
||||
@@ -262,9 +302,11 @@ func (c *ClientImpl) recommendPublishCategory(ctx context.Context, cookiesStr, t
|
||||
"publishScene": "mainPublish",
|
||||
"scene": "newPublishChoice",
|
||||
"description": desc,
|
||||
"imageInfos": imageInfos,
|
||||
"uniqueCode": strconv.FormatInt(time.Now().UnixMicro(), 10),
|
||||
}
|
||||
if len(imageInfos) > 0 {
|
||||
data["imageInfos"] = imageInfos
|
||||
}
|
||||
decoded, updated, err := c.callMTop(ctx, cookiesStr, RecommendItemAPI, "mtop.taobao.idle.kgraph.property.recommend", "2.0", "a21ybx.publish.0.0", "a21ybx.item.sidebar.1.67321598K9Vgx8", "67321598K9Vgx8", data)
|
||||
if err != nil {
|
||||
return nil, updated, err
|
||||
@@ -277,24 +319,85 @@ func (c *ClientImpl) recommendPublishCategory(ctx context.Context, cookiesStr, t
|
||||
return nil, updated, fmt.Errorf("%w: 类目推荐响应缺少 data", ErrPublishCategoryUnrecognized)
|
||||
}
|
||||
cat := mapFromAny(dataMap["categoryPredictResult"])
|
||||
if cat == nil || mtopString(cat["catId"]) == "" {
|
||||
if !validPublishCategoryMap(cat) {
|
||||
// 部分账号/场景仅在 cardList 的“分类”卡片返回已选中的类目,
|
||||
// 不返回 categoryPredictResult。将其转换为统一的发布类目结构。
|
||||
if selected := selectedCategoryFromCards(dataMap); selected != nil {
|
||||
cat = selected
|
||||
dataMap["categoryPredictResult"] = selected
|
||||
}
|
||||
}
|
||||
if !validPublishCategoryMap(cat) {
|
||||
return nil, updated, ErrPublishCategoryUnrecognized
|
||||
}
|
||||
return dataMap, updated, nil
|
||||
}
|
||||
|
||||
func validPublishCategoryMap(category map[string]any) bool {
|
||||
return category != nil &&
|
||||
strings.TrimSpace(mtopString(category["catId"])) != "" &&
|
||||
strings.TrimSpace(mtopString(category["catName"])) != "" &&
|
||||
strings.TrimSpace(mtopString(category["channelCatId"])) != ""
|
||||
}
|
||||
|
||||
func selectedCategoryFromCards(data map[string]any) map[string]any {
|
||||
cards, _ := data["cardList"].([]any)
|
||||
for _, rawCard := range cards {
|
||||
cardData := mapFromAny(mapFromAny(rawCard)["cardData"])
|
||||
if cardData == nil || mtopString(cardData["propertyId"]) != "-10000" {
|
||||
continue
|
||||
}
|
||||
values, _ := cardData["valuesList"].([]any)
|
||||
for _, rawValue := range values {
|
||||
value := mapFromAny(rawValue)
|
||||
if value == nil || !publishLabelSelected(value["isClicked"]) || mtopString(value["catId"]) == "" {
|
||||
continue
|
||||
}
|
||||
return map[string]any{
|
||||
"catId": mtopString(value["catId"]),
|
||||
"catName": mtopString(value["catName"]),
|
||||
"channelCatId": mtopString(value["channelCatId"]),
|
||||
"tbCatId": mtopString(value["tbCatId"]),
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validPublishCategory(category PublishCategory) bool {
|
||||
return strings.TrimSpace(category.CatID) != "" && strings.TrimSpace(category.CatName) != ""
|
||||
return strings.TrimSpace(category.CatID) != "" &&
|
||||
strings.TrimSpace(category.CatName) != "" &&
|
||||
strings.TrimSpace(category.ChannelCatID) != ""
|
||||
}
|
||||
|
||||
func fallbackPublishCategory(category PublishCategory) map[string]any {
|
||||
category = PublishCategory{
|
||||
CatID: strings.TrimSpace(category.CatID),
|
||||
CatName: strings.TrimSpace(category.CatName),
|
||||
ChannelCatID: strings.TrimSpace(category.ChannelCatID),
|
||||
TBCatID: strings.TrimSpace(category.TBCatID),
|
||||
}
|
||||
return map[string]any{
|
||||
"categoryPredictResult": map[string]any{
|
||||
"catId": strings.TrimSpace(category.CatID),
|
||||
"catName": strings.TrimSpace(category.CatName),
|
||||
"channelCatId": strings.TrimSpace(category.ChannelCatID),
|
||||
"tbCatId": strings.TrimSpace(category.TBCatID),
|
||||
"catId": category.CatID,
|
||||
"catName": category.CatName,
|
||||
"channelCatId": category.ChannelCatID,
|
||||
"tbCatId": category.TBCatID,
|
||||
},
|
||||
// 闲鱼将分类作为已选择的标签一并提交;仅传 itemCatDTO 会导致
|
||||
// 部分频道类目无法还原完整路径。
|
||||
"cardList": []any{map[string]any{
|
||||
"cardData": map[string]any{
|
||||
"propertyId": "-10000",
|
||||
"propertyName": "分类",
|
||||
"valuesList": []any{map[string]any{
|
||||
"catName": category.CatName,
|
||||
"channelCatId": category.ChannelCatID,
|
||||
"tbCatId": category.TBCatID,
|
||||
"isClicked": true,
|
||||
}},
|
||||
},
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,8 +622,7 @@ func publishLabels(category map[string]any) []any {
|
||||
values, _ := cardData["valuesList"].([]any)
|
||||
for _, rawValue := range values {
|
||||
value := mapFromAny(rawValue)
|
||||
clicked, _ := value["isClicked"].(bool)
|
||||
if !clicked {
|
||||
if !publishLabelSelected(value["isClicked"]) {
|
||||
continue
|
||||
}
|
||||
propertyID := mtopString(cardData["propertyId"])
|
||||
@@ -552,6 +654,18 @@ func publishLabels(category map[string]any) []any {
|
||||
return out
|
||||
}
|
||||
|
||||
func publishLabelSelected(value any) bool {
|
||||
if selected, ok := value.(bool); ok {
|
||||
return selected
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(mtopString(value))) {
|
||||
case "1", "true":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func classifyPublishError(ret []string, decoded map[string]any) error {
|
||||
bodyBytes, _ := json.Marshal(decoded)
|
||||
body := string(bodyBytes)
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestPublishItemValidationFailures(t *testing.T) {
|
||||
{"zero quantity", PublishItemRequest{Title: "T", PriceCents: 100, Quantity: 0, Images: []PublishImage{{}}}, "库存数量必须大于 0"},
|
||||
{"no images", PublishItemRequest{Title: "T", PriceCents: 100, Quantity: 1}, "至少上传 1 张商品图片"},
|
||||
{"too many images", PublishItemRequest{Title: "T", PriceCents: 100, Quantity: 1, Images: make([]PublishImage, 10)}, "商品图片最多 9 张"},
|
||||
{"incomplete fallback category", PublishItemRequest{Title: "T", PriceCents: 100, Quantity: 1, FallbackCategory: &PublishCategory{CatID: "5001"}, Images: []PublishImage{{}}}, "兜底类目必须同时填写"},
|
||||
{"incomplete preferred category", PublishItemRequest{Title: "T", PriceCents: 100, Quantity: 1, PreferredCategory: &PublishCategory{CatID: "5001"}, Images: []PublishImage{{}}}, "默认类目必须同时包含"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
@@ -140,11 +140,10 @@ func TestPublishItemUploadImageFailure(t *testing.T) {
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
req := PublishItemRequest{
|
||||
Title: "T",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
FallbackCategory: &PublishCategory{CatID: "5001", CatName: "虚拟商品"},
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
Title: "T",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
}
|
||||
_, err := client.PublishItem(context.Background(), consignCookies, req)
|
||||
if err == nil || !strings.Contains(err.Error(), "图片上传响应缺少 url") {
|
||||
@@ -165,11 +164,10 @@ func TestPublishItemRecommendCategoryFailure(t *testing.T) {
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
req := PublishItemRequest{
|
||||
Title: "T",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
FallbackCategory: &PublishCategory{CatID: "5001", CatName: "虚拟商品"},
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
Title: "T",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
}
|
||||
_, err := client.PublishItem(context.Background(), consignCookies, req)
|
||||
if err == nil {
|
||||
@@ -182,7 +180,7 @@ func TestPublishItemRecommendCategoryFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestPublishItemRecommendCategoryMissingData: ret 成功但 data 缺 categoryPredictResult。
|
||||
func TestPublishItemRecommendCategoryMissingData(t *testing.T) {
|
||||
func TestPublishItemRecommendCategoryMissingDataUsesElectronicMaterials(t *testing.T) {
|
||||
png1 := tinyPNG(t)
|
||||
dt := &dispatchTransport{handlers: map[string]http.HandlerFunc{
|
||||
"_upload": func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -191,20 +189,24 @@ func TestPublishItemRecommendCategoryMissingData(t *testing.T) {
|
||||
"mtop.taobao.idle.kgraph.property.recommend": func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{}}`)
|
||||
},
|
||||
"mtop.idle.pc.idleitem.publish": func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{"itemId":"fallback-item"}}`)
|
||||
},
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
req := PublishItemRequest{
|
||||
Title: "T",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Virtual: true,
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
}
|
||||
_, err := client.PublishItem(context.Background(), consignCookies, req)
|
||||
if err == nil || !strings.Contains(err.Error(), "未能自动识别商品类目") {
|
||||
result, err := client.PublishItem(context.Background(), consignCookies, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
if !errors.Is(err, ErrPublishCategoryUnrecognized) {
|
||||
t.Fatalf("err=%v want ErrPublishCategoryUnrecognized", err)
|
||||
if result.CategoryID != "50023914" || result.CategoryName != "电子资料" {
|
||||
t.Fatalf("result=%+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +275,51 @@ func TestPublishVirtualItemSkipsLocation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishVirtualItemUsesFallbackCategoryWhenRecommendationIsEmpty(t *testing.T) {
|
||||
func TestPublishVirtualItemUsesPreferredCategoryWithoutRecommendation(t *testing.T) {
|
||||
png1 := tinyPNG(t)
|
||||
var publishedData map[string]any
|
||||
recommendCalled := false
|
||||
dt := &dispatchTransport{handlers: map[string]http.HandlerFunc{
|
||||
"_upload": func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"object":{"url":"https://cdn/a.jpg","pix":"800x600"}}`)
|
||||
},
|
||||
"mtop.taobao.idle.kgraph.property.recommend": func(w http.ResponseWriter, r *http.Request) {
|
||||
recommendCalled = true
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{}}`)
|
||||
},
|
||||
"mtop.idle.pc.idleitem.publish": func(w http.ResponseWriter, r *http.Request) {
|
||||
publishedData, _ = parseDataURL(readBody(r))
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{"itemId":"fallback-item-1"}}`)
|
||||
},
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
res, err := client.PublishItem(context.Background(), consignCookies, PublishItemRequest{
|
||||
Title: "虚拟商品",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Virtual: true,
|
||||
PreferredCategory: &PublishCategory{CatID: "5001", CatName: "虚拟服务", ChannelCatID: "6001", TBCatID: "7001"},
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
if recommendCalled {
|
||||
t.Fatal("配置默认类目后不应调用自动推荐接口")
|
||||
}
|
||||
if res.CategoryID != "5001" || res.CategoryName != "虚拟服务" {
|
||||
t.Fatalf("category result=%+v", res)
|
||||
}
|
||||
category, _ := publishedData["itemCatDTO"].(map[string]any)
|
||||
if category["catId"] != "5001" || category["catName"] != "虚拟服务" || category["channelCatId"] != "6001" || category["tbCatId"] != "7001" {
|
||||
t.Fatalf("published category=%+v", category)
|
||||
}
|
||||
if _, exists := publishedData["itemAddrDTO"]; exists {
|
||||
t.Fatalf("虚拟商品不应发送 itemAddrDTO: %+v", publishedData["itemAddrDTO"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishVirtualItemUsesElectronicMaterialsWhenRecommendationIsEmpty(t *testing.T) {
|
||||
png1 := tinyPNG(t)
|
||||
var publishedData map[string]any
|
||||
dt := &dispatchTransport{handlers: map[string]http.HandlerFunc{
|
||||
@@ -285,31 +331,27 @@ func TestPublishVirtualItemUsesFallbackCategoryWhenRecommendationIsEmpty(t *test
|
||||
},
|
||||
"mtop.idle.pc.idleitem.publish": func(w http.ResponseWriter, r *http.Request) {
|
||||
publishedData, _ = parseDataURL(readBody(r))
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{"itemId":"fallback-item-1"}}`)
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{"itemId":"electronic-item-1"}}`)
|
||||
},
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
res, err := client.PublishItem(context.Background(), consignCookies, PublishItemRequest{
|
||||
Title: "虚拟商品",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Virtual: true,
|
||||
FallbackCategory: &PublishCategory{CatID: "5001", CatName: "虚拟服务", ChannelCatID: "6001", TBCatID: "7001"},
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
Title: "无法识别的虚拟商品",
|
||||
PriceCents: 1000,
|
||||
Quantity: 1,
|
||||
Virtual: true,
|
||||
Images: []PublishImage{{Filename: "a.png", ContentType: "image/png", Data: png1}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
if res.CategoryID != "5001" || res.CategoryName != "虚拟服务" {
|
||||
if res.CategoryID != "50023914" || res.CategoryName != "电子资料" {
|
||||
t.Fatalf("category result=%+v", res)
|
||||
}
|
||||
category, _ := publishedData["itemCatDTO"].(map[string]any)
|
||||
if category["catId"] != "5001" || category["catName"] != "虚拟服务" || category["channelCatId"] != "6001" || category["tbCatId"] != "7001" {
|
||||
if category["channelCatId"] != "202036301" {
|
||||
t.Fatalf("published category=%+v", category)
|
||||
}
|
||||
if _, exists := publishedData["itemAddrDTO"]; exists {
|
||||
t.Fatalf("虚拟商品不应发送 itemAddrDTO: %+v", publishedData["itemAddrDTO"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestPublishItemFinalPublishFailure: 发布接口返回 token 过期错误。
|
||||
@@ -511,6 +553,43 @@ func TestRecommendPublishCategorySuccess(t *testing.T) {
|
||||
_ = png1
|
||||
}
|
||||
|
||||
func TestRecommendPublishCategoryUsesSelectedCategoryCard(t *testing.T) {
|
||||
imgs := []uploadedImage{{URL: "https://cdn/a.jpg", Width: 800, Height: 600}}
|
||||
dt := &dispatchTransport{handlers: map[string]http.HandlerFunc{
|
||||
"mtop.taobao.idle.kgraph.property.recommend": func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"],"data":{"cardList":[{"cardData":{"propertyId":"-10000","propertyName":"分类","valuesList":[{"catId":"50023914","catName":"电子资料","channelCatId":"202036301","isClicked":"1"}]}}]}}`)
|
||||
},
|
||||
}}
|
||||
client := &ClientImpl{HTTPClient: &http.Client{Transport: dt}}
|
||||
category, _, err := client.recommendPublishCategory(context.Background(), consignCookies, "其他虚拟资料", "其他虚拟资料", imgs)
|
||||
if err != nil {
|
||||
t.Fatalf("err=%v", err)
|
||||
}
|
||||
selected := category["categoryPredictResult"].(map[string]any)
|
||||
if selected["catId"] != "50023914" || selected["catName"] != "电子资料" || selected["channelCatId"] != "202036301" {
|
||||
t.Fatalf("selected=%+v", selected)
|
||||
}
|
||||
if labels := publishLabels(category); len(labels) != 1 {
|
||||
t.Fatalf("labels=%+v", labels)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultVirtualPublishCategoryIncludesSelectedCategoryLabel(t *testing.T) {
|
||||
category := DefaultVirtualPublishCategory()
|
||||
if category.CatID != "50023914" || category.CatName != "电子资料" || category.ChannelCatID != "202036301" || category.TBCatID != "" {
|
||||
t.Fatalf("default category=%+v", category)
|
||||
}
|
||||
fallback := fallbackPublishCategory(category)
|
||||
labels := publishLabels(fallback)
|
||||
if len(labels) != 1 {
|
||||
t.Fatalf("labels=%+v", labels)
|
||||
}
|
||||
label := labels[0].(map[string]any)
|
||||
if label["channelCateId"] != "202036301" || label["channelCateName"] != "电子资料" || label["propertyId"] != "-10000" {
|
||||
t.Fatalf("label=%+v", label)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecommendPublishCategoryDataNil(t *testing.T) {
|
||||
imgs := []uploadedImage{{URL: "u", Width: 1, Height: 1}}
|
||||
dt := &dispatchTransport{handlers: map[string]http.HandlerFunc{
|
||||
|
||||
Reference in new issue
Block a user