Compare commits
4 Commits
f2d03e2595
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d2e4ef57e | |||
| 4d434c9c67 | |||
| 73fd27bdf6 | |||
| 62e61a9e63 |
@@ -1,10 +1,11 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
Button, Input, InputNumber, Radio, Select, Space, Switch, Table, Typography, message,
|
||||
Button, Image, Input, InputNumber, Modal, Radio, Select, Space, Switch, Table, Typography, message,
|
||||
} from 'antd';
|
||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { EditOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { request } from '../lib/api';
|
||||
import { PRODUCT_STATUS_LABELS } from '../lib/constants';
|
||||
import OssUpload from './OssUpload';
|
||||
|
||||
type SpecValue = { id?: string; name: string; sortOrder?: number };
|
||||
type SpecAttr = { id?: string; name: string; sortOrder?: number; values: SpecValue[] };
|
||||
@@ -24,6 +25,7 @@ type SkuRow = {
|
||||
isDefault: boolean;
|
||||
sortOrder?: number;
|
||||
specText?: string;
|
||||
imageUrl?: string | null;
|
||||
};
|
||||
|
||||
function cartesian(attrs: SpecAttr[]): string[][] {
|
||||
@@ -73,6 +75,7 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
saleUnit: s.saleUnit === 'BOX' ? 'BOX' : 'BOTTLE',
|
||||
bottlesPerUnit: s.bottlesPerUnit || (s.saleUnit === 'BOX' ? 6 : 1),
|
||||
isDefault: !!s.isDefault,
|
||||
imageUrl: s.imageUrl ?? '',
|
||||
}))
|
||||
: [
|
||||
{
|
||||
@@ -86,10 +89,12 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
saleUnit: 'BOTTLE',
|
||||
bottlesPerUnit: 1,
|
||||
isDefault: true,
|
||||
imageUrl: '',
|
||||
},
|
||||
],
|
||||
);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [editIndex, setEditIndex] = useState<number | null>(null);
|
||||
|
||||
const combos = useMemo(() => cartesian(attrs.filter((a) => a.name.trim() && a.values.some((v) => v.name.trim()))), [attrs]);
|
||||
|
||||
@@ -111,12 +116,21 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
bottlesPerUnit: 1,
|
||||
isDefault: i === 0,
|
||||
sortOrder: i,
|
||||
imageUrl: '',
|
||||
};
|
||||
});
|
||||
if (next.length && !next.some((s) => s.isDefault)) next[0].isDefault = true;
|
||||
setSkus(next.length ? next : skus);
|
||||
}
|
||||
|
||||
function patchSku(index: number, patch: Partial<SkuRow>) {
|
||||
setSkus((prev) => {
|
||||
const next = [...prev];
|
||||
next[index] = { ...next[index], ...patch };
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
setSaving(true);
|
||||
try {
|
||||
@@ -157,8 +171,7 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
const payloadSkus = skus.map((s, i) => ({
|
||||
id: s.id,
|
||||
specValueIds: resolveIds(s.specValueIds ?? []),
|
||||
skuCode: s.skuCode,
|
||||
barcode69: s.barcode69,
|
||||
barcode69: s.barcode69.trim(),
|
||||
price: s.price,
|
||||
benefitAmount: s.benefitAmount,
|
||||
status: s.status,
|
||||
@@ -169,10 +182,13 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
bottlesPerUnit: s.saleUnit === 'BOX' ? s.bottlesPerUnit || 6 : 1,
|
||||
isDefault: !!s.isDefault,
|
||||
sortOrder: i,
|
||||
imageUrl: s.imageUrl?.trim() || null,
|
||||
}));
|
||||
|
||||
for (const row of payloadSkus) {
|
||||
if (!row.barcode69?.trim()) throw new Error('请填写全部 SKU 的 69 码');
|
||||
const barcodes = payloadSkus.map((row) => row.barcode69);
|
||||
if (barcodes.some((b) => !b)) throw new Error('每个规格须填写独立 69 码');
|
||||
if (new Set(barcodes).size !== barcodes.length) {
|
||||
throw new Error('同一商品内 69 码不可重复,每个规格请填写不同 69 码');
|
||||
}
|
||||
|
||||
await request(`/admin/products/${productId}/skus`, {
|
||||
@@ -188,10 +204,13 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
}
|
||||
}
|
||||
|
||||
const editing = editIndex != null ? skus[editIndex] : null;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Typography.Paragraph type="secondary">
|
||||
先配置销售规格轴(如「包装」),再生成 SKU 矩阵。未配置规格时仅保留默认一行 SKU,与基础信息价/码同步。
|
||||
SKU 码由系统自动生成(DK 开头),无需填写。每个规格必须填写<strong>互不相同</strong>的 69 码,并可单独上传主图。
|
||||
点「填写」在弹窗中编辑。先配置销售规格轴(如「包装」),再生成 SKU 矩阵。
|
||||
</Typography.Paragraph>
|
||||
|
||||
<Typography.Title level={5}>规格轴</Typography.Title>
|
||||
@@ -272,7 +291,7 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
size="small"
|
||||
rowKey={(_, i) => String(i)}
|
||||
pagination={false}
|
||||
scroll={{ x: 1100 }}
|
||||
scroll={{ x: 1240 }}
|
||||
dataSource={skus}
|
||||
columns={[
|
||||
{
|
||||
@@ -281,10 +300,20 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
render: (_, row) => row.specText || (row.specValueIds?.length ? row.specValueIds.join(',') : '默认'),
|
||||
},
|
||||
{
|
||||
title: '69码',
|
||||
width: 140,
|
||||
title: 'SKU',
|
||||
width: 110,
|
||||
render: (_, row) => (
|
||||
<Typography.Text type="secondary">
|
||||
{row.skuCode || '保存后自动生成'}
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: <span>69码 <Typography.Text type="danger">*</Typography.Text></span>,
|
||||
width: 180,
|
||||
render: (_, row, index) => (
|
||||
<Input
|
||||
placeholder="本规格独立 69 码"
|
||||
value={row.barcode69}
|
||||
onChange={(e) => {
|
||||
const next = [...skus];
|
||||
@@ -434,12 +463,154 @@ export default function ProductSpecsEditor({ productId, initialAttrs, initialSku
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
width: 72,
|
||||
render: (_, row) =>
|
||||
row.imageUrl ? (
|
||||
<Image src={row.imageUrl} width={40} height={40} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||
) : (
|
||||
<Typography.Text type="secondary">无</Typography.Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '编辑',
|
||||
width: 80,
|
||||
fixed: 'right',
|
||||
render: (_, row, index) => (
|
||||
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => setEditIndex(index)}>
|
||||
填写
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Button type="primary" loading={saving} style={{ marginTop: 16 }} onClick={() => void handleSave()}>
|
||||
保存规格与 SKU
|
||||
</Button>
|
||||
|
||||
<Modal
|
||||
title={`编辑规格${editing?.specText ? ` · ${editing.specText}` : editing?.skuCode ? ` · ${editing.skuCode}` : ''}`}
|
||||
open={editIndex != null}
|
||||
onCancel={() => setEditIndex(null)}
|
||||
onOk={() => setEditIndex(null)}
|
||||
okText="完成"
|
||||
width={560}
|
||||
destroyOnClose
|
||||
>
|
||||
{editing && editIndex != null ? (
|
||||
<Space direction="vertical" size={14} style={{ width: '100%' }}>
|
||||
<div>
|
||||
<Typography.Text type="secondary">SKU</Typography.Text>
|
||||
<div>{editing.skuCode || '保存后自动生成'}</div>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text>69 码 <Typography.Text type="danger">*</Typography.Text></Typography.Text>
|
||||
<Input
|
||||
placeholder="本规格独立 69 码"
|
||||
value={editing.barcode69}
|
||||
onChange={(e) => patchSku(editIndex, { barcode69: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text>主图</Typography.Text>
|
||||
<OssUpload
|
||||
bizType="COVER"
|
||||
value={editing.imageUrl || ''}
|
||||
onChange={(url) => patchSku(editIndex, { imageUrl: url })}
|
||||
/>
|
||||
</div>
|
||||
<Space>
|
||||
<div>
|
||||
<Typography.Text>售价</Typography.Text>
|
||||
<InputNumber
|
||||
min={0}
|
||||
style={{ width: 140 }}
|
||||
value={editing.price}
|
||||
onChange={(v) => patchSku(editIndex, { price: Number(v) || 0 })}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text>权益</Typography.Text>
|
||||
<InputNumber
|
||||
min={0}
|
||||
style={{ width: 140 }}
|
||||
value={editing.benefitAmount}
|
||||
onChange={(v) => patchSku(editIndex, { benefitAmount: v == null ? undefined : Number(v) })}
|
||||
/>
|
||||
</div>
|
||||
</Space>
|
||||
<div>
|
||||
<Typography.Text>状态</Typography.Text>
|
||||
<Select
|
||||
style={{ width: '100%' }}
|
||||
value={editing.status}
|
||||
options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))}
|
||||
onChange={(status) => patchSku(editIndex, { status })}
|
||||
/>
|
||||
</div>
|
||||
<Space>
|
||||
<Select
|
||||
style={{ width: 100 }}
|
||||
value={editing.saleUnit}
|
||||
options={[
|
||||
{ value: 'BOTTLE', label: '瓶' },
|
||||
{ value: 'BOX', label: '箱' },
|
||||
]}
|
||||
onChange={(saleUnit) =>
|
||||
patchSku(editIndex, {
|
||||
saleUnit,
|
||||
bottlesPerUnit: saleUnit === 'BOX' ? editing.bottlesPerUnit || 6 : 1,
|
||||
})
|
||||
}
|
||||
/>
|
||||
{editing.saleUnit === 'BOX' ? (
|
||||
<InputNumber
|
||||
min={1}
|
||||
value={editing.bottlesPerUnit}
|
||||
onChange={(v) => patchSku(editIndex, { bottlesPerUnit: Number(v) || 6 })}
|
||||
/>
|
||||
) : null}
|
||||
</Space>
|
||||
<Space>
|
||||
<Switch
|
||||
checkedChildren="线上"
|
||||
unCheckedChildren="线上"
|
||||
checked={editing.allowOnlinePurchase}
|
||||
onChange={(checked) =>
|
||||
patchSku(editIndex, {
|
||||
allowOnlinePurchase: checked,
|
||||
allowCrossCityDelivery: checked ? editing.allowCrossCityDelivery : false,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Switch
|
||||
checkedChildren="跨城"
|
||||
unCheckedChildren="跨城"
|
||||
disabled={!editing.allowOnlinePurchase}
|
||||
checked={editing.allowCrossCityDelivery}
|
||||
onChange={(checked) => patchSku(editIndex, { allowCrossCityDelivery: checked })}
|
||||
/>
|
||||
<Switch
|
||||
checkedChildren="现场"
|
||||
unCheckedChildren="现场"
|
||||
checked={editing.allowOnSitePickup}
|
||||
onChange={(checked) => patchSku(editIndex, { allowOnSitePickup: checked })}
|
||||
/>
|
||||
<Switch
|
||||
checkedChildren="默认"
|
||||
unCheckedChildren="默认"
|
||||
checked={editing.isDefault}
|
||||
onChange={(checked) => {
|
||||
if (!checked) return;
|
||||
setSkus((prev) => prev.map((s, i) => ({ ...s, isDefault: i === editIndex })));
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
</Space>
|
||||
) : null}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ import {
|
||||
} from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import {
|
||||
INVOICE_CATEGORY_LABELS,
|
||||
INVOICE_KIND_LABELS,
|
||||
INVOICE_STATUS_LABELS,
|
||||
INVOICE_TITLE_TYPE_LABELS,
|
||||
type InvoiceCategory,
|
||||
type InvoiceKind,
|
||||
type InvoiceStatus,
|
||||
type InvoiceTitleType,
|
||||
@@ -35,6 +37,7 @@ type Row = {
|
||||
orderNo?: string;
|
||||
titleType: InvoiceTitleType;
|
||||
invoiceKind: InvoiceKind;
|
||||
invoiceCategory?: InvoiceCategory;
|
||||
titleName: string;
|
||||
status: InvoiceStatus;
|
||||
overdue?: boolean;
|
||||
@@ -54,6 +57,7 @@ type CreateFormValues = {
|
||||
orderNo: string;
|
||||
titleType: InvoiceTitleType;
|
||||
invoiceKind: InvoiceKind;
|
||||
invoiceCategory?: InvoiceCategory;
|
||||
titleName: string;
|
||||
taxNo?: string;
|
||||
addressPhone?: string;
|
||||
@@ -156,6 +160,7 @@ export default function InvoicesPage() {
|
||||
orderNo: values.orderNo.trim(),
|
||||
titleType: values.titleType,
|
||||
invoiceKind: values.invoiceKind,
|
||||
invoiceCategory: values.invoiceCategory,
|
||||
titleName: values.titleName.trim(),
|
||||
taxNo: values.taxNo?.trim() || undefined,
|
||||
addressPhone: values.addressPhone?.trim() || undefined,
|
||||
@@ -186,9 +191,17 @@ export default function InvoicesPage() {
|
||||
},
|
||||
{
|
||||
title: '票种',
|
||||
width: 120,
|
||||
width: 140,
|
||||
render: (_, r) => INVOICE_KIND_LABELS[r.invoiceKind] ?? r.invoiceKind,
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
width: 88,
|
||||
render: (_, r) =>
|
||||
r.invoiceCategory
|
||||
? INVOICE_CATEGORY_LABELS[r.invoiceCategory] ?? r.invoiceCategory
|
||||
: '—',
|
||||
},
|
||||
{ title: '名称', dataIndex: 'titleName', ellipsis: true },
|
||||
{
|
||||
title: '状态',
|
||||
@@ -233,6 +246,7 @@ export default function InvoicesPage() {
|
||||
createForm.setFieldsValue({
|
||||
titleType: 'PERSONAL',
|
||||
invoiceKind: 'NORMAL',
|
||||
invoiceCategory: 'LIQUOR',
|
||||
});
|
||||
setCreateOpen(true);
|
||||
}}
|
||||
@@ -324,6 +338,11 @@ export default function InvoicesPage() {
|
||||
<Descriptions.Item label="发票类型">
|
||||
{INVOICE_KIND_LABELS[detail.invoiceKind]}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="类型">
|
||||
{detail.invoiceCategory
|
||||
? INVOICE_CATEGORY_LABELS[detail.invoiceCategory]
|
||||
: '—'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="抬头名称">{detail.titleName}</Descriptions.Item>
|
||||
<Descriptions.Item label="税号">{detail.taxNo ?? '—'}</Descriptions.Item>
|
||||
<Descriptions.Item label="地址电话">{detail.addressPhone ?? '—'}</Descriptions.Item>
|
||||
@@ -382,6 +401,18 @@ export default function InvoicesPage() {
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="invoiceCategory"
|
||||
label="类型"
|
||||
rules={[{ required: true, message: '请选择类型' }]}
|
||||
>
|
||||
<Select
|
||||
options={(Object.keys(INVOICE_CATEGORY_LABELS) as InvoiceCategory[]).map((k) => ({
|
||||
value: k,
|
||||
label: INVOICE_CATEGORY_LABELS[k],
|
||||
}))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="titleType"
|
||||
label="抬头类型"
|
||||
|
||||
@@ -222,8 +222,13 @@ function BaseInfoFields({ mode, form }: { mode: 'create' | 'edit'; form: FormIns
|
||||
<Form.Item label="SKU">
|
||||
<Input disabled placeholder="保存后自动生成" />
|
||||
</Form.Item>
|
||||
<Form.Item name="barcode69" label="69码" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
<Form.Item
|
||||
name="barcode69"
|
||||
label="69码"
|
||||
rules={[{ required: true, message: '请填写默认规格 69 码' }]}
|
||||
extra="默认规格的 69 码;若有多种规格,保存后请到「规格与 SKU」为每个规格分别填写不同 69 码"
|
||||
>
|
||||
<Input placeholder="默认规格 69 码" />
|
||||
</Form.Item>
|
||||
<Form.Item name="aromaType" label="香型" rules={[{ required: true }]}>
|
||||
<Select options={Object.entries(AROMA_TYPE_LABELS).map(([value, label]) => ({ value, label }))} />
|
||||
@@ -403,7 +408,7 @@ export default function ProductsPage() {
|
||||
</Form>
|
||||
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1320 }}
|
||||
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
||||
<Drawer title="编辑商品" width={720} open={drawerOpen} onClose={() => setDrawerOpen(false)}
|
||||
<Drawer title="编辑商品" width={1100} open={drawerOpen} onClose={() => setDrawerOpen(false)}
|
||||
extra={detail && (
|
||||
<Button type="primary" onClick={async () => {
|
||||
const v = await editForm.validateFields();
|
||||
@@ -421,8 +426,8 @@ export default function ProductsPage() {
|
||||
{detail && (
|
||||
<>
|
||||
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
||||
<Descriptions.Item label="SKU">{String(detail.skuCode)}</Descriptions.Item>
|
||||
<Descriptions.Item label="69码">{String(detail.barcode69)}</Descriptions.Item>
|
||||
<Descriptions.Item label="SKU">{String(detail.skuCode)}(系统生成)</Descriptions.Item>
|
||||
<Descriptions.Item label="默认 69 码">{String(detail.barcode69)}</Descriptions.Item>
|
||||
<Descriptions.Item label="香型">{AROMA_TYPE_LABELS[String(detail.aromaType)] || String(detail.aromaType)}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Form form={editForm} layout="vertical">
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
@@ -7,9 +7,9 @@ import SubPageHeader from '../../components/SubPageHeader';
|
||||
import { request, toast } from '../../lib/api';
|
||||
import { usePageView } from '../../lib/usePageView';
|
||||
import {
|
||||
INVOICE_KIND_LABELS,
|
||||
INVOICE_CATEGORY_LABELS,
|
||||
INVOICE_TITLE_TYPE_LABELS,
|
||||
type InvoiceKind,
|
||||
type InvoiceCategory,
|
||||
type UserInvoiceTitleDto,
|
||||
} from '@dukang/shared-types';
|
||||
|
||||
@@ -42,7 +42,8 @@ export default function InvoiceApplyPage() {
|
||||
|
||||
const [titles, setTitles] = useState<UserInvoiceTitleDto[]>([]);
|
||||
const [selectedId, setSelectedId] = useState('');
|
||||
const [invoiceKind, setInvoiceKind] = useState<InvoiceKind>('NORMAL');
|
||||
const [invoiceCategory, setInvoiceCategory] = useState<InvoiceCategory>('LIQUOR');
|
||||
const [remark, setRemark] = useState('');
|
||||
const [emailOverride, setEmailOverride] = useState('');
|
||||
const [phoneOverride, setPhoneOverride] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -103,19 +104,17 @@ export default function InvoiceApplyPage() {
|
||||
toast('请填写联系电话');
|
||||
return;
|
||||
}
|
||||
if (invoiceKind === 'SPECIAL' && selected.titleType !== 'ENTERPRISE') {
|
||||
toast('专用发票仅支持企业抬头');
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await request(`/trade/orders/${orderId}/invoices`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
titleId: selectedId,
|
||||
invoiceKind,
|
||||
invoiceKind: 'NORMAL',
|
||||
invoiceCategory,
|
||||
email,
|
||||
phone,
|
||||
remark: remark.trim() || undefined,
|
||||
},
|
||||
});
|
||||
toast('发票申请已提交', 'success');
|
||||
@@ -192,20 +191,26 @@ export default function InvoiceApplyPage() {
|
||||
) : null}
|
||||
|
||||
{canApply ? (
|
||||
<View className="invoice-title-field" style={{ marginBottom: 16 }}>
|
||||
<Text className="invoice-title-label">发票类型</Text>
|
||||
<View className="invoice-title-type-row">
|
||||
{(['NORMAL', 'SPECIAL'] as InvoiceKind[]).map((k) => (
|
||||
<Text
|
||||
key={k}
|
||||
className={`invoice-title-type-chip${invoiceKind === k ? ' active' : ''}`}
|
||||
onClick={() => setInvoiceKind(k)}
|
||||
>
|
||||
{INVOICE_KIND_LABELS[k]}
|
||||
</Text>
|
||||
))}
|
||||
<>
|
||||
<View className="invoice-title-field" style={{ marginBottom: 16 }}>
|
||||
<Text className="invoice-title-label">发票类型</Text>
|
||||
<Text className="invoice-kind-static">增值税普通发票</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="invoice-title-field" style={{ marginBottom: 16 }}>
|
||||
<Text className="invoice-title-label">类型</Text>
|
||||
<View className="invoice-title-type-row">
|
||||
{(['LIQUOR', 'CATERING'] as InvoiceCategory[]).map((k) => (
|
||||
<Text
|
||||
key={k}
|
||||
className={`invoice-title-type-chip${invoiceCategory === k ? ' active' : ''}`}
|
||||
onClick={() => setInvoiceCategory(k)}
|
||||
>
|
||||
{INVOICE_CATEGORY_LABELS[k]}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{canApply ? (
|
||||
@@ -258,7 +263,11 @@ export default function InvoiceApplyPage() {
|
||||
|
||||
{canApply && selected && !selected.email ? (
|
||||
<View className="invoice-title-field" style={{ marginTop: 16 }}>
|
||||
<Text className="invoice-title-label">接收邮箱</Text>
|
||||
<Text className="invoice-title-label">
|
||||
<Text className="invoice-title-star">*</Text>
|
||||
接收邮箱
|
||||
<Text className="invoice-title-label-hint">必填</Text>
|
||||
</Text>
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
placeholder="电子发票将发送至此邮箱"
|
||||
@@ -279,6 +288,19 @@ export default function InvoiceApplyPage() {
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{canApply ? (
|
||||
<View className="invoice-title-field" style={{ marginTop: 16 }}>
|
||||
<Text className="invoice-title-label">备注</Text>
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={200}
|
||||
placeholder="选填,将显示在发票申请备注中"
|
||||
value={remark}
|
||||
onInput={(e) => setRemark(e.detail.value)}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{canApply && titles.length > 0 ? (
|
||||
|
||||
@@ -26,6 +26,24 @@ const ACTION_ICONS = {
|
||||
|
||||
type EditDraft = UpsertInvoiceTitleRequest & { id?: string };
|
||||
|
||||
function FieldLabel({
|
||||
children,
|
||||
required,
|
||||
hint,
|
||||
}: {
|
||||
children: string;
|
||||
required?: boolean;
|
||||
hint?: string;
|
||||
}) {
|
||||
return (
|
||||
<Text className="invoice-title-label">
|
||||
{required ? <Text className="invoice-title-star">*</Text> : null}
|
||||
{children}
|
||||
{hint ? <Text className="invoice-title-label-hint">{hint}</Text> : null}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
function TitleActionIcon({
|
||||
kind,
|
||||
label,
|
||||
@@ -120,6 +138,15 @@ export default function InvoiceTitlesPage() {
|
||||
toast('企业抬头须填写税号');
|
||||
return;
|
||||
}
|
||||
const email = draft.email?.trim() || '';
|
||||
if (!email) {
|
||||
toast('请填写接收邮箱(必填)');
|
||||
return;
|
||||
}
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
toast('邮箱格式不正确');
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
const payload: UpsertInvoiceTitleRequest = {
|
||||
@@ -152,6 +179,10 @@ export default function InvoiceTitlesPage() {
|
||||
}
|
||||
|
||||
async function setDefault(t: UserInvoiceTitleDto) {
|
||||
if (!t.email?.trim()) {
|
||||
toast('请先补全接收邮箱后再设为默认');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await request(`/trade/invoice-titles/${t.id}`, {
|
||||
method: 'PUT',
|
||||
@@ -241,7 +272,7 @@ export default function InvoiceTitlesPage() {
|
||||
</Text>
|
||||
|
||||
<View className="invoice-title-field">
|
||||
<Text className="invoice-title-label">抬头类型</Text>
|
||||
<FieldLabel required>抬头类型</FieldLabel>
|
||||
<View className="invoice-title-type-row">
|
||||
{(['PERSONAL', 'ENTERPRISE'] as InvoiceTitleType[]).map((tp) => (
|
||||
<Text
|
||||
@@ -258,7 +289,7 @@ export default function InvoiceTitlesPage() {
|
||||
</View>
|
||||
|
||||
<View className="invoice-title-field">
|
||||
<Text className="invoice-title-label">抬头名称</Text>
|
||||
<FieldLabel required>抬头名称</FieldLabel>
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={128}
|
||||
@@ -270,7 +301,7 @@ export default function InvoiceTitlesPage() {
|
||||
|
||||
{draft.titleType === 'ENTERPRISE' ? (
|
||||
<View className="invoice-title-field">
|
||||
<Text className="invoice-title-label">税号</Text>
|
||||
<FieldLabel required>税号</FieldLabel>
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={32}
|
||||
@@ -282,11 +313,13 @@ export default function InvoiceTitlesPage() {
|
||||
) : null}
|
||||
|
||||
<View className="invoice-title-field">
|
||||
<Text className="invoice-title-label">接收邮箱</Text>
|
||||
<FieldLabel required hint="必填,电子发票将发送至此">
|
||||
接收邮箱
|
||||
</FieldLabel>
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={128}
|
||||
placeholder="电子发票将发送至此邮箱"
|
||||
placeholder="请填写邮箱(必填)"
|
||||
value={draft.email || ''}
|
||||
onInput={(e) => setDraft({ ...draft, email: e.detail.value })}
|
||||
/>
|
||||
@@ -311,7 +344,7 @@ export default function InvoiceTitlesPage() {
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={256}
|
||||
placeholder="专用发票需要,选填"
|
||||
placeholder="选填"
|
||||
value={draft.addressPhone || ''}
|
||||
onInput={(e) => setDraft({ ...draft, addressPhone: e.detail.value })}
|
||||
/>
|
||||
@@ -321,7 +354,7 @@ export default function InvoiceTitlesPage() {
|
||||
<Input
|
||||
className="invoice-title-input"
|
||||
maxlength={256}
|
||||
placeholder="专用发票需要,选填"
|
||||
placeholder="选填"
|
||||
value={draft.bankAccount || ''}
|
||||
onInput={(e) => setDraft({ ...draft, bankAccount: e.detail.value })}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import { View, Text, Image } from '@tarojs/components';
|
||||
import '../../styles/order.css';
|
||||
import Taro, { useDidShow, useRouter } from '@tarojs/taro';
|
||||
import PageShell from '../../components/PageShell';
|
||||
@@ -19,13 +19,13 @@ import { applyWechatLoginResult } from '../../lib/wechat-auth';
|
||||
import { isWechatEnv } from '../../lib/weixin';
|
||||
import { goLogin } from '../../lib/auth-nav';
|
||||
import { request, toast } from '../../lib/api';
|
||||
import payLogo from '../../assets/logo2.png';
|
||||
|
||||
export default function PayPage() {
|
||||
const router = useRouter();
|
||||
const orderId = router.params.orderId ?? '';
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [authLoading, setAuthLoading] = useState(false);
|
||||
const [mockMode, setMockMode] = useState(true);
|
||||
const [needsWechatAuth, setNeedsWechatAuth] = useState(false);
|
||||
const [msg, setMsg] = useState('');
|
||||
const [orderNo, setOrderNo] = useState('');
|
||||
@@ -39,7 +39,6 @@ export default function PayPage() {
|
||||
const refreshPayReadiness = useCallback(async () => {
|
||||
try {
|
||||
const [config, profile] = await Promise.all([fetchClientConfig(), fetchUserProfile()]);
|
||||
setMockMode(config.mockPay);
|
||||
setNeedsWechatAuth(needsWechatAuthForPay(config, profile));
|
||||
return profile;
|
||||
} catch {
|
||||
@@ -174,7 +173,7 @@ export default function PayPage() {
|
||||
<View className="sub-page-body">
|
||||
<View className="pay-status">
|
||||
<View className="pay-status-icon">
|
||||
<Text>¥</Text>
|
||||
<Image className="pay-status-brand" src={payLogo} mode="aspectFit" />
|
||||
</View>
|
||||
<Text className="pay-status-title">
|
||||
{needsWechatAuth ? '需完成微信授权' : '待支付'}
|
||||
@@ -204,12 +203,6 @@ export default function PayPage() {
|
||||
<Text className="order-row-label">支付方式</Text>
|
||||
<Text className="order-row-value">微信支付</Text>
|
||||
</View>
|
||||
<View className="order-row">
|
||||
<Text className="order-row-label">说明</Text>
|
||||
<Text className="order-row-value">
|
||||
{mockMode ? 'Mock 模式由服务端直接标记已付款' : '将调起微信收银台'}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
{msg ? (
|
||||
<Text className="pay-wechat-auth-msg" style={{ marginTop: 12 }}>
|
||||
|
||||
@@ -165,6 +165,12 @@ export default function ProductDetailPage() {
|
||||
allowOnSitePickup: activeSku.allowOnSitePickup,
|
||||
}
|
||||
: product;
|
||||
const carouselImages = (() => {
|
||||
const base = getProductCarouselImages(product);
|
||||
const skuImg = activeSku?.imageUrl?.trim();
|
||||
if (!skuImg) return base;
|
||||
return [skuImg, ...base.filter((url) => url !== skuImg)];
|
||||
})();
|
||||
|
||||
const sharePayload = useMemo(
|
||||
() =>
|
||||
@@ -172,9 +178,9 @@ export default function ProductDetailPage() {
|
||||
path: `/pages/product-detail/index?id=${productId}`,
|
||||
dynamicTitle: product?.name,
|
||||
dynamicDesc: product?.subtitle,
|
||||
dynamicImageUrl: product ? getProductMainImage(product) : undefined,
|
||||
dynamicImageUrl: (activeSku?.imageUrl?.trim() || (product ? getProductMainImage(product) : undefined)),
|
||||
}),
|
||||
[product, productId],
|
||||
[product, productId, activeSku],
|
||||
);
|
||||
|
||||
useShareAppMessage(() => toWeappShareMessage(sharePayload));
|
||||
@@ -249,7 +255,6 @@ export default function ProductDetailPage() {
|
||||
|
||||
const allowOnline = canBuyOnline(fulfillment ?? {});
|
||||
const allowOnSite = canPickupOnSite(fulfillment ?? {});
|
||||
const carouselImages = getProductCarouselImages(product);
|
||||
const detailImages = getProductDetailImages(product);
|
||||
const detail = product.detailContent ?? {};
|
||||
const features = detail.features ?? [];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { View, Text, Image } from '@tarojs/components';
|
||||
import { View, Text, Image, ScrollView } from '@tarojs/components';
|
||||
import '../../styles/store-detail.css';
|
||||
import Taro, {
|
||||
useDidShow,
|
||||
@@ -444,17 +444,19 @@ export default function StoreDetailPage() {
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{intro ? (
|
||||
{benefitRule ? (
|
||||
<View className="store-detail-section">
|
||||
<Text className="store-detail-section-title">门店详情</Text>
|
||||
<Text className="store-detail-intro">{intro}</Text>
|
||||
<Text className="store-detail-section-title store-detail-section-title--rule">使用规则</Text>
|
||||
<Text className="store-detail-intro">{benefitRule}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{benefitRule ? (
|
||||
{intro ? (
|
||||
<View className="store-detail-section">
|
||||
<Text className="store-detail-section-title">好客权益使用规则</Text>
|
||||
<Text className="store-detail-intro">{benefitRule}</Text>
|
||||
<Text className="store-detail-section-title">门店详情</Text>
|
||||
<ScrollView className="store-detail-intro-scroll" scrollY showScrollbar>
|
||||
<Text className="store-detail-intro">{intro}</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -153,6 +153,30 @@
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.invoice-title-star {
|
||||
color: #c62828;
|
||||
margin-right: 2px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.invoice-title-label-hint {
|
||||
margin-left: 6px;
|
||||
font-size: 12px;
|
||||
color: #c62828;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.invoice-kind-static {
|
||||
display: block;
|
||||
font-size: 15px;
|
||||
color: var(--color-on-surface, #1a1a1a);
|
||||
line-height: 44px;
|
||||
padding: 0 12px;
|
||||
background: var(--color-surface, #fafafa);
|
||||
border: 1px solid var(--color-outline, #ddd);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.invoice-title-input {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
|
||||
@@ -488,16 +488,20 @@
|
||||
}
|
||||
|
||||
.pay-status-icon {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
width: 88px;
|
||||
height: 88px;
|
||||
border-radius: 50%;
|
||||
background: rgba(166, 29, 36, 0.08);
|
||||
color: var(--color-heritage-red);
|
||||
font-size: 36px;
|
||||
background: #f7f4ee;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pay-status-brand {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
.pay-status-title {
|
||||
|
||||
@@ -130,6 +130,7 @@
|
||||
|
||||
.product-detail-promo {
|
||||
position: relative;
|
||||
margin-top: 8px;
|
||||
padding: 16px;
|
||||
border-radius: var(--radius-lg);
|
||||
background: linear-gradient(135deg, #fff9e6 0%, #fff0c2 100%);
|
||||
@@ -377,7 +378,7 @@
|
||||
}
|
||||
|
||||
.product-detail-specs {
|
||||
margin: 12px 0 4px;
|
||||
margin: 16px 0 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
|
||||
@@ -211,6 +211,17 @@
|
||||
color: var(--color-on-surface);
|
||||
}
|
||||
|
||||
.store-detail-section-title--rule {
|
||||
color: var(--color-heritage-red, #a61d24);
|
||||
}
|
||||
|
||||
.store-detail-intro-scroll {
|
||||
max-height: 168px;
|
||||
height: 168px;
|
||||
overflow-y: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.store-detail-env-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
+55
-16
@@ -10,26 +10,51 @@
|
||||
| 1 | 数据模型 | `common_product_item` 升级为 SPU;新增 `spec_attr` / `spec_value` / `sku` / `sku_spec`;订单快照 `sku_id` / `sale_unit` / `bottles_per_unit` |
|
||||
| 2 | 存量迁移 | 每商品 1 个默认瓶装 SKU;SQL:`prisma/migrate-product-sku-v354.sql`;脚本:`prisma/backfill-product-skus.ts` |
|
||||
| 3 | Catalog | 列表附加 `specEnabled`/`saleUnit`;详情附加 `specAttrs`/`skus`/`defaultSkuId`;旧字段拍平保留 |
|
||||
| 4 | Trade | preview/create 可选 `skuId`;单可售 SKU 自动回落;起购按瓶当量 |
|
||||
| 5 | Admin | `PUT /admin/products/:id/specs`、`PUT .../skus`;商品抽屉「规格与 SKU」 |
|
||||
| 6 | mini-user | 详情规格 chips;确认页带 `skuId`;箱装数量文案 |
|
||||
| 4 | Trade | preview/create 可选 `skuId`;无 SKU 回落 SPU;有可售 SKU 用默认/唯一 |
|
||||
| 5 | Admin | `PUT /admin/products/:id/specs`、`PUT .../skus`;商品抽屉加宽;规格弹窗填写;每规格主图 |
|
||||
| 6 | mini-user | 详情规格 chips;选规格切主图;确认页带 `skuId`;箱装数量文案 |
|
||||
| 7 | 代下单 | HQ / 合伙人可选规格 SKU |
|
||||
| 8 | 权益文案 | 「好客权益券」→「好客权益」;首页角标「享{amount}好客权益」(去掉门店 icon) |
|
||||
| 9 | SKU 码 | 系统生成 `DK` + 6 位数字,后台不可填;每规格独立 69 码 |
|
||||
| 10 | 规格主图 | `common_product_sku.image_url` 可选;空则 C 端回落商品封面 |
|
||||
|
||||
**不做**:SKU 规格图、库存、把现有酒祖 10/15/20 合并为一个 SPU。
|
||||
**不做**:库存、把现有酒祖 10/15/20 合并为一个 SPU。
|
||||
|
||||
## 兼容规则(线上)
|
||||
|
||||
- 不改 `/api/v1` 前缀;**只增字段,不删旧字段语义**。
|
||||
- 旧客户端不传 `skuId`:若该 SPU **恰好 1 个可售 SKU** → 自动使用(现网行为);多个可售 → `400 请选择规格`。
|
||||
- 旧 admin `PUT /admin/products/:id` 不传规格时:仅同步**唯一**默认 SKU(多规格时不同步,防误改)。
|
||||
- 旧客户端不传 `skuId`:
|
||||
- 有 ≥1 个可售 SKU → 用默认(或第一个)可售 SKU
|
||||
- **没有任何可售 SKU(未回填)→ 回落 SPU 字段,照常下单**(禁止再报「商品暂无可售规格」)
|
||||
- 传入 `skuId`(新客户端选规格)→ 按该 SKU 校验。
|
||||
- 旧 admin `PUT /admin/products/:id` 不传规格时:仅同步**唯一**默认 SKU(多规格时不同步,防误改);不同步覆盖已生成的 DK 码。
|
||||
- SPU 上 `sku_code` / `barcode_69` 去掉唯一约束,唯一下沉到 `common_product_sku`;SPU 列保留为默认 SKU 冗余。
|
||||
- 订单 `sku_id` 可空;无规格快照走商品 69 码 / 价格。
|
||||
|
||||
## 发版顺序
|
||||
## 发版一并执行
|
||||
|
||||
1. API + DB 迁移(每商品仅默认 SKU)。**此时不要给任何商品加第二 SKU。**
|
||||
2. 发布新 mini-user + admin 规格页 + 代下单 SKU 选择。
|
||||
3. 运营再配置「单瓶 / 整箱」等第二规格。
|
||||
按顺序在**目标环境库**执行(先测试后生产)。本机 `npx ts-node …` 只改本地 `.env` 库,不会自动打线上。
|
||||
|
||||
1. **规格表** `server/dukang-api/prisma/migrate-product-sku-v354.sql`
|
||||
建 spec/sku 表,订单加 `sku_id` / `sale_unit` / `bottles_per_unit`。
|
||||
2. **回填默认 SKU**
|
||||
`cd server/dukang-api && npx ts-node prisma/backfill-product-skus.ts`
|
||||
尚无 SKU 的商品各建 1 条默认瓶装 SKU(码用 DK)。
|
||||
3. **SKU 主图列** `server/dukang-api/prisma/migrate-sku-image.sql`
|
||||
```sql
|
||||
ALTER TABLE `common_product_sku`
|
||||
ADD COLUMN `image_url` VARCHAR(512) NULL AFTER `sort_order`;
|
||||
```
|
||||
4. **SKU 码改 DK**(生产须在服务器用 `.env.production` 的 `DATABASE_URL`)
|
||||
`npx dotenv -e .env.production -- npx ts-node prisma/rewrite-sku-codes-dk.ts`
|
||||
已是 `DK`+数字的不动;`JZ-10` / `QX-001` 等会改。**不改 69 码、订单、价格。**
|
||||
5. **发票品类列**(同批次)`server/dukang-api/prisma/migrate-invoice-category.sql`
|
||||
```sql
|
||||
ALTER TABLE `user_invoice`
|
||||
ADD COLUMN `invoice_category` VARCHAR(16) NOT NULL DEFAULT 'LIQUOR' AFTER `invoice_kind`;
|
||||
```
|
||||
6. 发布 API + mini-user + admin-web。
|
||||
**此时不要给商品加第二规格**,等新小程序上线后再配「单瓶 / 整箱」。
|
||||
|
||||
## 起购与物流
|
||||
|
||||
@@ -40,23 +65,37 @@
|
||||
## 关键表摘要
|
||||
|
||||
- `common_product_spec_attr` / `common_product_spec_value`
|
||||
- `common_product_sku`(`sale_unit`=`BOTTLE|BOX`,`bottles_per_unit`)
|
||||
- `common_product_sku`(`sale_unit`=`BOTTLE|BOX`,`bottles_per_unit`,`image_url` 可选)
|
||||
- `common_product_sku_spec`
|
||||
- `user_order.sku_id` / `sale_unit` / `bottles_per_unit`
|
||||
- `user_invoice.invoice_category`:`LIQUOR` 酒水类 / `CATERING` 餐饮类;票种 C 端固定增值税普通发票
|
||||
|
||||
## 权益文案(mini-user)
|
||||
## SKU 码与 69 码
|
||||
|
||||
- SKU 码:服务端生成 `DK000001` 起,后台只展示。
|
||||
- 每个规格必须填写**互不相同**的 69 码(全局不可与其它商品 SKU 冲突)。
|
||||
- 总部「规格与 SKU」点「填写」弹窗编辑 69 码 / 价 / 履约 / 主图。
|
||||
|
||||
## 权益与小程序 UI(同批次)
|
||||
|
||||
| 位置 | 变更 |
|
||||
|------|------|
|
||||
| 门店详情等 | 「好客权益券」→「好客权益」(如「好客权益使用规则」) |
|
||||
| 首页商品角标 `CouponBadge` | 由「享 + 门店 icon + 金额 + 好客权益」改为纯文案 **「享{amount}好客权益」** |
|
||||
| 门店详情等 | 「好客权益券」→「好客权益」 |
|
||||
| 首页商品角标 `CouponBadge` | 纯文案 **「享{amount}好客权益」**,无门店 icon |
|
||||
| 商品详情 | 规格区与「好客权益」说明之间加大间距 |
|
||||
| 待支付 / 收银台 | 顶部 logo 使用 `public/images/logo2.png`(杜康印章) |
|
||||
| 门店详情 | 「使用规则」四字红色,放在「门店详情」**上面**;门店详情正文限高,超出上下滚动 |
|
||||
| 发票申请 | 票种写死增值税普通发票;类型选酒水类/餐饮类;申请备注;抬头邮箱必填打 `*` |
|
||||
|
||||
其它页 `BenefitFigure`(我的/权益/核销等)仍保留门店核销图标,仅首页角标去 icon。
|
||||
|
||||
## 验收
|
||||
|
||||
- [ ] 未配规格:旧小程序/H5/代下单路径与现网一致
|
||||
- [ ] 多规格:详情选规格后价格/权益/履约变化;漏选下单 400
|
||||
- [ ] 未配规格:旧小程序/H5/代下单路径与现网一致(无 SKU 也能下单)
|
||||
- [ ] 多规格:详情选规格后价格/权益/履约/主图变化
|
||||
- [ ] 整箱 SKU:数量 1 过起购;订单快照 `bottles_per_unit=6`
|
||||
- [ ] `GET /catalog/products/:id` 仍含 `id/name/price/spec/skuCode/...`
|
||||
- [ ] 小程序无「好客权益券」字样;首页角标为「享{金额}好客权益」且无门店 icon
|
||||
- [ ] 后台 SKU 码为 DK 开头且不可手填;每规格独立 69 码与主图
|
||||
- [ ] 门店详情「使用规则」红色且在门店详情上方;门店详情超长可滚动
|
||||
- [ ] 待支付页顶部为 logo2 印章
|
||||
|
||||
@@ -35,6 +35,8 @@ export interface ProductSkuDto {
|
||||
saleUnit: ProductSaleUnit;
|
||||
bottlesPerUnit: number;
|
||||
isDefault: boolean;
|
||||
/** 规格主图;无则详情页回落商品封面/轮播 */
|
||||
imageUrl?: string | null;
|
||||
}
|
||||
|
||||
export interface ProductDto {
|
||||
@@ -129,6 +131,7 @@ export interface AdminProductSkuInput {
|
||||
id?: string;
|
||||
/** 规格值 id;无规格时为空数组 */
|
||||
specValueIds?: string[];
|
||||
/** 忽略;服务端自动生成 DK 码 */
|
||||
skuCode?: string;
|
||||
barcode69: string;
|
||||
price: number;
|
||||
@@ -141,4 +144,5 @@ export interface AdminProductSkuInput {
|
||||
bottlesPerUnit?: number;
|
||||
isDefault?: boolean;
|
||||
sortOrder?: number;
|
||||
imageUrl?: string | null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export type InvoiceTitleType = 'PERSONAL' | 'ENTERPRISE';
|
||||
export type InvoiceKind = 'NORMAL' | 'SPECIAL';
|
||||
/** C 端开票品类:酒水类 / 餐饮类(票种固定增值税普通发票) */
|
||||
export type InvoiceCategory = 'LIQUOR' | 'CATERING';
|
||||
export type InvoiceStatus = 'PENDING' | 'ISSUED' | 'REJECTED';
|
||||
|
||||
export const INVOICE_TITLE_TYPE_LABELS: Record<InvoiceTitleType, string> = {
|
||||
@@ -12,6 +14,11 @@ export const INVOICE_KIND_LABELS: Record<InvoiceKind, string> = {
|
||||
SPECIAL: '增值税专用发票',
|
||||
};
|
||||
|
||||
export const INVOICE_CATEGORY_LABELS: Record<InvoiceCategory, string> = {
|
||||
LIQUOR: '酒水类',
|
||||
CATERING: '餐饮类',
|
||||
};
|
||||
|
||||
export const INVOICE_STATUS_LABELS: Record<InvoiceStatus, string> = {
|
||||
PENDING: '待开票',
|
||||
ISSUED: '已开票',
|
||||
@@ -21,6 +28,7 @@ export const INVOICE_STATUS_LABELS: Record<InvoiceStatus, string> = {
|
||||
export interface CreateInvoiceRequest {
|
||||
titleType: InvoiceTitleType;
|
||||
invoiceKind: InvoiceKind;
|
||||
invoiceCategory?: InvoiceCategory;
|
||||
titleName: string;
|
||||
taxNo?: string;
|
||||
addressPhone?: string;
|
||||
@@ -37,6 +45,7 @@ export interface InvoiceDto {
|
||||
userId: string;
|
||||
titleType: InvoiceTitleType;
|
||||
invoiceKind: InvoiceKind;
|
||||
invoiceCategory?: InvoiceCategory;
|
||||
titleName: string;
|
||||
taxNo?: string | null;
|
||||
addressPhone?: string | null;
|
||||
|
||||
@@ -5,6 +5,30 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const PREFIX = 'DK';
|
||||
const PAD = 6;
|
||||
const RE = /^DK(\d+)$/;
|
||||
|
||||
async function nextDkCode() {
|
||||
const [items, skus] = await Promise.all([
|
||||
prisma.commonProductItem.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
prisma.commonProductSku.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
]);
|
||||
let maxSeq = 0;
|
||||
for (const row of [...items, ...skus]) {
|
||||
const m = RE.exec(row.skuCode);
|
||||
if (!m) continue;
|
||||
const n = Number(m[1]);
|
||||
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
|
||||
}
|
||||
return `${PREFIX}${String(maxSeq + 1).padStart(PAD, '0')}`;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const products = await prisma.commonProductItem.findMany({
|
||||
@@ -13,10 +37,11 @@ async function main() {
|
||||
let created = 0;
|
||||
for (const p of products) {
|
||||
if (p.skus.length > 0) continue;
|
||||
const skuCode = RE.test(p.skuCode) ? p.skuCode : await nextDkCode();
|
||||
await prisma.commonProductSku.create({
|
||||
data: {
|
||||
productId: p.id,
|
||||
skuCode: p.skuCode,
|
||||
skuCode,
|
||||
barcode69: p.barcode69,
|
||||
specKey: '',
|
||||
specText: p.spec,
|
||||
@@ -32,8 +57,14 @@ async function main() {
|
||||
sortOrder: 0,
|
||||
},
|
||||
});
|
||||
if (p.skuCode !== skuCode) {
|
||||
await prisma.commonProductItem.update({
|
||||
where: { id: p.id },
|
||||
data: { skuCode },
|
||||
});
|
||||
}
|
||||
created += 1;
|
||||
console.log(`created default sku for product ${p.id} ${p.skuCode}`);
|
||||
console.log(`created default sku for product ${p.id} ${skuCode}`);
|
||||
}
|
||||
console.log(`done, created=${created}, scanned=${products.length}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- 发票开票品类:酒水类 / 餐饮类(票种仍为增值税普通发票)
|
||||
-- 存量申请默认酒水类,与 Prisma InvoiceCategory 默认值一致
|
||||
|
||||
ALTER TABLE `user_invoice`
|
||||
ADD COLUMN `invoice_category` VARCHAR(16) NOT NULL DEFAULT 'LIQUOR' AFTER `invoice_kind`;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- SKU 规格主图(可选;空则 C 端回落商品封面)
|
||||
ALTER TABLE `common_product_sku`
|
||||
ADD COLUMN `image_url` VARCHAR(512) NULL AFTER `sort_order`;
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* 将存量商品 / SKU 的 sku_code 全部改成 DK + 6 位数字。
|
||||
* 已是 DK 数字码的保持不变;其余先写临时码再分配,避免唯一约束冲突。
|
||||
*
|
||||
* 用法:cd server/dukang-api && npx ts-node prisma/rewrite-sku-codes-dk.ts
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
const PREFIX = 'DK';
|
||||
const PAD = 6;
|
||||
const RE = /^DK(\d+)$/;
|
||||
|
||||
function isDk(code: string) {
|
||||
return RE.test(code);
|
||||
}
|
||||
|
||||
function formatCode(seq: number) {
|
||||
return `${PREFIX}${String(seq).padStart(PAD, '0')}`;
|
||||
}
|
||||
|
||||
async function maxExistingSeq(): Promise<number> {
|
||||
const [items, skus] = await Promise.all([
|
||||
prisma.commonProductItem.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
prisma.commonProductSku.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
]);
|
||||
let maxSeq = 0;
|
||||
for (const row of [...items, ...skus]) {
|
||||
const m = RE.exec(row.skuCode);
|
||||
if (!m) continue;
|
||||
const n = Number(m[1]);
|
||||
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
|
||||
}
|
||||
return maxSeq;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const skus = await prisma.commonProductSku.findMany({
|
||||
orderBy: [{ productId: 'asc' }, { id: 'asc' }],
|
||||
select: { id: true, productId: true, skuCode: true, isDefault: true },
|
||||
});
|
||||
const products = await prisma.commonProductItem.findMany({
|
||||
select: { id: true, skuCode: true },
|
||||
});
|
||||
|
||||
const skuNeed = skus.filter((s) => !isDk(s.skuCode));
|
||||
const productNeed = products.filter((p) => !isDk(p.skuCode));
|
||||
console.log(`sku total=${skus.length} rewrite=${skuNeed.length}`);
|
||||
console.log(`product total=${products.length} rewrite=${productNeed.length}`);
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
for (const s of skuNeed) {
|
||||
await tx.commonProductSku.update({
|
||||
where: { id: s.id },
|
||||
data: { skuCode: `TMP${s.id.toString()}` },
|
||||
});
|
||||
}
|
||||
for (const p of productNeed) {
|
||||
await tx.commonProductItem.update({
|
||||
where: { id: p.id },
|
||||
data: { skuCode: `TMPP${p.id.toString()}` },
|
||||
});
|
||||
}
|
||||
|
||||
const seqStart = await (async () => {
|
||||
const [items, skuRows] = await Promise.all([
|
||||
tx.commonProductItem.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
tx.commonProductSku.findMany({
|
||||
where: { skuCode: { startsWith: PREFIX } },
|
||||
select: { skuCode: true },
|
||||
}),
|
||||
]);
|
||||
let maxSeq = 0;
|
||||
for (const row of [...items, ...skuRows]) {
|
||||
const m = RE.exec(row.skuCode);
|
||||
if (!m) continue;
|
||||
const n = Number(m[1]);
|
||||
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
|
||||
}
|
||||
return maxSeq;
|
||||
})();
|
||||
|
||||
let seq = seqStart;
|
||||
const defaultSkuCodeByProduct = new Map<string, string>();
|
||||
|
||||
for (const s of skuNeed) {
|
||||
seq += 1;
|
||||
const code = formatCode(seq);
|
||||
await tx.commonProductSku.update({
|
||||
where: { id: s.id },
|
||||
data: { skuCode: code },
|
||||
});
|
||||
if (s.isDefault) defaultSkuCodeByProduct.set(s.productId.toString(), code);
|
||||
console.log(`sku ${s.id} ${s.skuCode} -> ${code}`);
|
||||
}
|
||||
|
||||
for (const p of productNeed) {
|
||||
const fromDefault = defaultSkuCodeByProduct.get(p.id.toString());
|
||||
let code = fromDefault;
|
||||
if (!code) {
|
||||
seq += 1;
|
||||
code = formatCode(seq);
|
||||
}
|
||||
await tx.commonProductItem.update({
|
||||
where: { id: p.id },
|
||||
data: { skuCode: code },
|
||||
});
|
||||
console.log(`product ${p.id} ${p.skuCode} -> ${code}`);
|
||||
}
|
||||
|
||||
const stillDefault = await tx.commonProductSku.findMany({
|
||||
where: { isDefault: true },
|
||||
select: { productId: true, skuCode: true },
|
||||
});
|
||||
for (const s of stillDefault) {
|
||||
if (!isDk(s.skuCode)) continue;
|
||||
await tx.commonProductItem.updateMany({
|
||||
where: { id: s.productId, NOT: { skuCode: s.skuCode } },
|
||||
data: { skuCode: s.skuCode },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const leftoverSku = await prisma.commonProductSku.count({
|
||||
where: { NOT: { skuCode: { startsWith: PREFIX } } },
|
||||
});
|
||||
const leftoverProduct = await prisma.commonProductItem.count({
|
||||
where: { NOT: { skuCode: { startsWith: PREFIX } } },
|
||||
});
|
||||
console.log(`done leftoverSku=${leftoverSku} leftoverProduct=${leftoverProduct} maxWas=${await maxExistingSeq()}`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(() => prisma.$disconnect());
|
||||
@@ -146,6 +146,12 @@ enum InvoiceKind {
|
||||
SPECIAL
|
||||
}
|
||||
|
||||
/// C 端开票品类(增值税票种固定普通发票)
|
||||
enum InvoiceCategory {
|
||||
LIQUOR
|
||||
CATERING
|
||||
}
|
||||
|
||||
enum InvoiceStatus {
|
||||
PENDING
|
||||
ISSUED
|
||||
@@ -888,6 +894,8 @@ model CommonProductSku {
|
||||
bottlesPerUnit Int @default(1) @map("bottles_per_unit")
|
||||
isDefault Boolean @default(false) @map("is_default")
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
/// 规格主图;空则回落商品封面
|
||||
imageUrl String? @map("image_url") @db.VarChar(512)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.DateTime(3)
|
||||
|
||||
@@ -1678,6 +1686,8 @@ model UserInvoice {
|
||||
userId BigInt @map("user_id") @db.UnsignedBigInt
|
||||
titleType InvoiceTitleType @map("title_type")
|
||||
invoiceKind InvoiceKind @map("invoice_kind")
|
||||
/// 酒水类 / 餐饮类;历史单默认酒水类
|
||||
invoiceCategory InvoiceCategory @default(LIQUOR) @map("invoice_category")
|
||||
titleName String @map("title_name") @db.VarChar(128)
|
||||
taxNo String? @map("tax_no") @db.VarChar(32)
|
||||
addressPhone String? @map("address_phone") @db.VarChar(256)
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
mapSkuDto,
|
||||
mapSpecAttrsDto,
|
||||
pickDisplaySku,
|
||||
resolveOrderSku,
|
||||
resolveOrderSale,
|
||||
} from './product-sku.util';
|
||||
|
||||
export type CatalogViewer = {
|
||||
@@ -204,7 +204,7 @@ export class CatalogService {
|
||||
});
|
||||
}
|
||||
|
||||
/** 下单前校验:白名单商品仅全局测试白名单手机号可买;返回 SPU + 解析后的 SKU */
|
||||
/** 下单前校验:白名单商品仅全局测试白名单手机号可买;无 SKU 时回落 SPU 字段 */
|
||||
async assertPurchasable(
|
||||
productId: bigint,
|
||||
viewerPhone?: string | null,
|
||||
@@ -224,8 +224,8 @@ export class CatalogService {
|
||||
throw new BadRequestException('该商品暂不对当前账号开放');
|
||||
}
|
||||
}
|
||||
const sku = resolveOrderSku(product.skus, skuId);
|
||||
return { product, sku };
|
||||
const sale = resolveOrderSale(product, product.skus ?? [], skuId);
|
||||
return { product, sale };
|
||||
}
|
||||
|
||||
async resolveUserPhone(userId: bigint): Promise<string | null> {
|
||||
|
||||
@@ -37,23 +37,79 @@ export function buildSpecText(
|
||||
.join(' / ');
|
||||
}
|
||||
|
||||
/** 下单用销售快照:有可售 SKU 则用 SKU,否则回落 SPU(旧客户端 / 未回填) */
|
||||
export type OrderSaleSnapshot = {
|
||||
skuId: bigint | null;
|
||||
skuCode: string;
|
||||
barcode69: string;
|
||||
specText: string;
|
||||
price: CommonProductSku['price'];
|
||||
benefitAmount: CommonProductSku['benefitAmount'];
|
||||
allowOnSitePickup: boolean;
|
||||
allowOnlinePurchase: boolean;
|
||||
allowCrossCityDelivery: boolean;
|
||||
saleUnit: ProductSaleUnit;
|
||||
bottlesPerUnit: number;
|
||||
};
|
||||
|
||||
export function saleSnapshotFromProduct(product: CommonProductItem): OrderSaleSnapshot {
|
||||
return {
|
||||
skuId: null,
|
||||
skuCode: product.skuCode,
|
||||
barcode69: product.barcode69,
|
||||
specText: product.spec,
|
||||
price: product.price,
|
||||
benefitAmount: product.benefitAmount,
|
||||
allowOnSitePickup: product.allowOnSitePickup,
|
||||
allowOnlinePurchase: product.allowOnlinePurchase,
|
||||
allowCrossCityDelivery: product.allowCrossCityDelivery,
|
||||
saleUnit: 'BOTTLE',
|
||||
bottlesPerUnit: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function saleSnapshotFromSku(
|
||||
sku: CommonProductSku,
|
||||
product: CommonProductItem,
|
||||
): OrderSaleSnapshot {
|
||||
return {
|
||||
skuId: sku.id,
|
||||
skuCode: sku.skuCode,
|
||||
barcode69: sku.barcode69,
|
||||
specText: sku.specText || product.spec,
|
||||
price: sku.price,
|
||||
benefitAmount: sku.benefitAmount,
|
||||
allowOnSitePickup: sku.allowOnSitePickup,
|
||||
allowOnlinePurchase: sku.allowOnlinePurchase,
|
||||
allowCrossCityDelivery: sku.allowCrossCityDelivery,
|
||||
saleUnit: sku.saleUnit,
|
||||
bottlesPerUnit: sku.bottlesPerUnit > 0 ? sku.bottlesPerUnit : sku.saleUnit === 'BOX' ? BOTTLES_PER_BOX : 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析下单 SKU:显式 skuId,或单可售自动回落;多可售且未传则 400。
|
||||
* 现网兼容:
|
||||
* - 不传 skuId:有可售 SKU 用默认/唯一可售;一个都没有则回落 SPU 字段(未回填也能下单)
|
||||
* - 传入 skuId:按 SKU 校验(新客户端选规格)
|
||||
* 不在旧接口上因「无 SKU」或「多规格未选」打断现网下单。
|
||||
*/
|
||||
export function resolveOrderSku(
|
||||
export function resolveOrderSale(
|
||||
product: CommonProductItem,
|
||||
skus: CommonProductSku[],
|
||||
skuId?: string | null,
|
||||
): CommonProductSku {
|
||||
const onSale = skus.filter(isSkuOnSale);
|
||||
): OrderSaleSnapshot {
|
||||
if (skuId) {
|
||||
const found = skus.find((s) => s.id.toString() === String(skuId));
|
||||
if (!found) throw new BadRequestException('规格不存在');
|
||||
if (!isSkuOnSale(found)) throw new BadRequestException('该规格暂不可购买');
|
||||
return found;
|
||||
return saleSnapshotFromSku(found, product);
|
||||
}
|
||||
if (onSale.length === 1) return onSale[0];
|
||||
if (onSale.length === 0) throw new BadRequestException('商品暂无可售规格');
|
||||
throw new BadRequestException('请选择规格');
|
||||
const onSale = skus.filter(isSkuOnSale);
|
||||
if (onSale.length >= 1) {
|
||||
const picked = onSale.find((s) => s.isDefault) ?? onSale[0];
|
||||
return saleSnapshotFromSku(picked, product);
|
||||
}
|
||||
return saleSnapshotFromProduct(product);
|
||||
}
|
||||
|
||||
/** 列表/拍平:优先默认可售 → 最低价可售 → 默认任意 → 任意 */
|
||||
@@ -132,6 +188,7 @@ export function mapSkuDto(sku: SkuWithSpecs) {
|
||||
isDefault: sku.isDefault,
|
||||
skuCode: sku.skuCode,
|
||||
barcode69: sku.barcode69,
|
||||
imageUrl: (sku as { imageUrl?: string | null }).imageUrl || undefined,
|
||||
sortOrder: sku.sortOrder,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ function normalizePhones(phones?: string[]): string[] {
|
||||
|
||||
const SKU_AUTO_PREFIX = 'DK';
|
||||
const SKU_AUTO_PAD = 6;
|
||||
const SKU_AUTO_RE = /^DK(\d+)$/;
|
||||
|
||||
function isDkSkuCode(code: string | null | undefined): boolean {
|
||||
return !!code && SKU_AUTO_RE.test(code);
|
||||
}
|
||||
const MAX_SPEC_ATTRS = 3;
|
||||
const MAX_SPEC_VALUES = 10;
|
||||
|
||||
@@ -465,14 +470,31 @@ export class AdminProductsService {
|
||||
throw new BadRequestException('请且仅指定一个默认 SKU');
|
||||
}
|
||||
|
||||
const barcodes = rows.map((r) => r.barcode69.trim());
|
||||
const barcodes = rows.map((r) => r.barcode69.trim()).filter(Boolean);
|
||||
if (barcodes.length !== rows.length) {
|
||||
throw new BadRequestException('每个规格须填写 69 码');
|
||||
}
|
||||
if (new Set(barcodes).size !== barcodes.length) {
|
||||
throw new BadRequestException('69 码不可重复');
|
||||
throw new BadRequestException('同一商品内 69 码不可重复,每个规格须使用不同 69 码');
|
||||
}
|
||||
const barcodeTaken = await this.prisma.commonProductSku.findFirst({
|
||||
where: { barcode69: { in: barcodes }, productId: { not: productId } },
|
||||
select: { barcode69: true },
|
||||
});
|
||||
if (barcodeTaken) {
|
||||
throw new BadRequestException(`69 码已存在:${barcodeTaken.barcode69}`);
|
||||
}
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
const existing = await tx.commonProductSku.findMany({ where: { productId } });
|
||||
const keepIds = new Set(rows.map((r) => r.id).filter(Boolean) as string[]);
|
||||
const needGenerate = rows.filter((row) => {
|
||||
if (!row.id) return true;
|
||||
const old = existing.find((s) => s.id.toString() === row.id);
|
||||
return !old || !isDkSkuCode(old.skuCode);
|
||||
}).length;
|
||||
const generatedCodes = await this.allocateAutoSkuCodesTx(tx, needGenerate);
|
||||
let genIdx = 0;
|
||||
|
||||
for (const old of existing) {
|
||||
if (keepIds.has(old.id.toString())) continue;
|
||||
@@ -508,7 +530,12 @@ export class AdminProductsService {
|
||||
? BOTTLES_PER_BOX
|
||||
: 1;
|
||||
const status = (row.status ?? 'DRAFT') as 'DRAFT' | 'ON_SALE' | 'OFF_SALE';
|
||||
const skuCode = row.skuCode?.trim() || (await this.nextAutoSkuCodeTx(tx));
|
||||
const old = row.id ? existing.find((s) => s.id.toString() === row.id) : undefined;
|
||||
const skuCode =
|
||||
old && isDkSkuCode(old.skuCode) ? old.skuCode : generatedCodes[genIdx++];
|
||||
if (!skuCode) {
|
||||
throw new BadRequestException('SKU 码生成失败,请重试');
|
||||
}
|
||||
|
||||
let skuId: bigint;
|
||||
if (row.id) {
|
||||
@@ -528,7 +555,8 @@ export class AdminProductsService {
|
||||
bottlesPerUnit,
|
||||
isDefault: !!row.isDefault,
|
||||
sortOrder: row.sortOrder ?? i,
|
||||
},
|
||||
imageUrl: row.imageUrl?.trim() || null,
|
||||
} as never,
|
||||
});
|
||||
await tx.commonProductSkuSpec.deleteMany({ where: { skuId } });
|
||||
} else {
|
||||
@@ -547,7 +575,8 @@ export class AdminProductsService {
|
||||
bottlesPerUnit,
|
||||
isDefault: !!row.isDefault,
|
||||
sortOrder: row.sortOrder ?? i,
|
||||
},
|
||||
imageUrl: row.imageUrl?.trim() || null,
|
||||
} as never,
|
||||
});
|
||||
skuId = created.id;
|
||||
}
|
||||
@@ -609,7 +638,7 @@ export class AdminProductsService {
|
||||
await this.prisma.commonProductSku.create({
|
||||
data: {
|
||||
productId,
|
||||
skuCode: product.skuCode,
|
||||
skuCode: await this.nextAutoSkuCode(),
|
||||
barcode69: product.barcode69,
|
||||
specKey: '',
|
||||
specText: product.spec,
|
||||
@@ -635,7 +664,6 @@ export class AdminProductsService {
|
||||
await this.prisma.commonProductSku.update({
|
||||
where: { id: defaultSku.id },
|
||||
data: {
|
||||
skuCode: product.skuCode,
|
||||
barcode69: product.barcode69,
|
||||
specText: product.spec,
|
||||
price: product.price,
|
||||
@@ -651,12 +679,22 @@ export class AdminProductsService {
|
||||
|
||||
/** 生成 DK + 6 位自增 SKU,冲突重试 */
|
||||
private async nextAutoSkuCode(): Promise<string> {
|
||||
return this.nextAutoSkuCodeTx(this.prisma);
|
||||
const [code] = await this.allocateAutoSkuCodesTx(this.prisma, 1);
|
||||
return code;
|
||||
}
|
||||
|
||||
private async nextAutoSkuCodeTx(
|
||||
db: Prisma.TransactionClient | PrismaService,
|
||||
): Promise<string> {
|
||||
const [code] = await this.allocateAutoSkuCodesTx(db, 1);
|
||||
return code;
|
||||
}
|
||||
|
||||
private async allocateAutoSkuCodesTx(
|
||||
db: Prisma.TransactionClient | PrismaService,
|
||||
count: number,
|
||||
): Promise<string[]> {
|
||||
if (count <= 0) return [];
|
||||
const [fromItem, fromSku] = await Promise.all([
|
||||
db.commonProductItem.findMany({
|
||||
where: { skuCode: { startsWith: SKU_AUTO_PREFIX } },
|
||||
@@ -668,14 +706,15 @@ export class AdminProductsService {
|
||||
}),
|
||||
]);
|
||||
let maxSeq = 0;
|
||||
const re = new RegExp(`^${SKU_AUTO_PREFIX}(\\d+)$`);
|
||||
for (const row of [...fromItem, ...fromSku]) {
|
||||
const m = re.exec(row.skuCode);
|
||||
const m = SKU_AUTO_RE.exec(row.skuCode);
|
||||
if (!m) continue;
|
||||
const n = Number(m[1]);
|
||||
if (Number.isFinite(n) && n > maxSeq) maxSeq = n;
|
||||
}
|
||||
return `${SKU_AUTO_PREFIX}${String(maxSeq + 1).padStart(SKU_AUTO_PAD, '0')}`;
|
||||
return Array.from({ length: count }, (_, i) => {
|
||||
return `${SKU_AUTO_PREFIX}${String(maxSeq + 1 + i).padStart(SKU_AUTO_PAD, '0')}`;
|
||||
});
|
||||
}
|
||||
|
||||
private async createWithGeneratedSku(
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
Min,
|
||||
Max,
|
||||
MinLength,
|
||||
@@ -1353,6 +1354,7 @@ class AdminSkuRowDto {
|
||||
@IsString({ each: true })
|
||||
specValueIds?: string[];
|
||||
|
||||
/** 忽略;服务端自动生成 DK 码 */
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
skuCode?: string;
|
||||
@@ -1399,6 +1401,12 @@ class AdminSkuRowDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
sortOrder?: number;
|
||||
|
||||
/** 规格主图 URL;空则回落商品封面 */
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(512)
|
||||
imageUrl?: string | null;
|
||||
}
|
||||
|
||||
export class SaveProductSkusDto {
|
||||
|
||||
@@ -53,6 +53,12 @@ export class CreateInvoiceDto {
|
||||
@IsIn(['NORMAL', 'SPECIAL'])
|
||||
invoiceKind?: string;
|
||||
|
||||
/** 酒水类 / 餐饮类;缺省酒水类。C 端票种固定普通发票 */
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@IsIn(['LIQUOR', 'CATERING'])
|
||||
invoiceCategory?: string;
|
||||
|
||||
@ValidateIf((o: CreateInvoiceDto) => !o.titleId)
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
|
||||
@@ -40,7 +40,7 @@ export class InvoiceTitleService {
|
||||
titleType: body.titleType,
|
||||
titleName: body.titleName.trim(),
|
||||
taxNo: body.taxNo?.trim() || null,
|
||||
email: body.email?.trim() || null,
|
||||
email: body.email!.trim(),
|
||||
phone: body.phone?.trim() || null,
|
||||
addressPhone: body.addressPhone?.trim() || null,
|
||||
bankAccount: body.bankAccount?.trim() || null,
|
||||
@@ -73,7 +73,7 @@ export class InvoiceTitleService {
|
||||
titleType: body.titleType,
|
||||
titleName: body.titleName.trim(),
|
||||
taxNo: body.taxNo?.trim() || null,
|
||||
email: body.email?.trim() || null,
|
||||
email: body.email!.trim(),
|
||||
phone: body.phone?.trim() || null,
|
||||
addressPhone: body.addressPhone?.trim() || null,
|
||||
bankAccount: body.bankAccount?.trim() || null,
|
||||
@@ -101,6 +101,13 @@ export class InvoiceTitleService {
|
||||
if (body.titleType === 'ENTERPRISE' && !body.taxNo?.trim()) {
|
||||
throw new BadRequestException('企业抬头须填写税号');
|
||||
}
|
||||
const email = body.email?.trim() || '';
|
||||
if (!email) {
|
||||
throw new BadRequestException('请填写接收邮箱');
|
||||
}
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
throw new BadRequestException('邮箱格式不正确');
|
||||
}
|
||||
if (isUpdate && body.titleType === undefined) {
|
||||
throw new BadRequestException('titleType 必填');
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import { AlertService } from '../../common/alert/alert.service';
|
||||
import { PayRedeemAnomalyService } from '../../common/alert/pay-redeem-anomaly.service';
|
||||
import { WecomMessagePushService } from '../../integrations/wecom/wecom-message-push.service';
|
||||
import type { Request } from 'express';
|
||||
import type { CommonProductSku } from '@prisma/client';
|
||||
import type { ProductSaleUnit } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class TradeService {
|
||||
@@ -64,23 +64,34 @@ export class TradeService {
|
||||
|
||||
private readonly logger = new Logger(TradeService.name);
|
||||
|
||||
private overlayProductWithSku(
|
||||
private overlayProductWithSale(
|
||||
productDto: Record<string, unknown>,
|
||||
sku: CommonProductSku,
|
||||
sale: {
|
||||
skuId: bigint | null;
|
||||
skuCode: string;
|
||||
specText: string;
|
||||
price: unknown;
|
||||
benefitAmount: unknown;
|
||||
allowOnSitePickup: boolean;
|
||||
allowOnlinePurchase: boolean;
|
||||
allowCrossCityDelivery: boolean;
|
||||
saleUnit: ProductSaleUnit;
|
||||
bottlesPerUnit: number;
|
||||
},
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
...productDto,
|
||||
skuCode: sku.skuCode,
|
||||
spec: sku.specText || productDto.spec,
|
||||
price: Number(sku.price),
|
||||
benefitAmount: Number(sku.benefitAmount ?? sku.price),
|
||||
benefitDisplay: Number(sku.benefitAmount ?? sku.price),
|
||||
allowOnSitePickup: sku.allowOnSitePickup,
|
||||
allowOnlinePurchase: sku.allowOnlinePurchase,
|
||||
allowCrossCityDelivery: sku.allowCrossCityDelivery,
|
||||
saleUnit: sku.saleUnit,
|
||||
bottlesPerUnit: sku.bottlesPerUnit,
|
||||
selectedSkuId: sku.id.toString(),
|
||||
skuCode: sale.skuCode,
|
||||
spec: sale.specText || productDto.spec,
|
||||
price: Number(sale.price),
|
||||
benefitAmount: Number(sale.benefitAmount ?? sale.price),
|
||||
benefitDisplay: Number(sale.benefitAmount ?? sale.price),
|
||||
allowOnSitePickup: sale.allowOnSitePickup,
|
||||
allowOnlinePurchase: sale.allowOnlinePurchase,
|
||||
allowCrossCityDelivery: sale.allowCrossCityDelivery,
|
||||
saleUnit: sale.saleUnit,
|
||||
bottlesPerUnit: sale.bottlesPerUnit,
|
||||
...(sale.skuId ? { selectedSkuId: sale.skuId.toString() } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,7 +106,7 @@ export class TradeService {
|
||||
},
|
||||
) {
|
||||
const viewerPhone = await this.catalogService.resolveUserPhone(userId);
|
||||
const { product: spu, sku } = await this.catalogService.assertPurchasable(
|
||||
const { product: spu, sale } = await this.catalogService.assertPurchasable(
|
||||
BigInt(body.productId),
|
||||
viewerPhone,
|
||||
body.skuId,
|
||||
@@ -104,13 +115,13 @@ export class TradeService {
|
||||
if (!productDto || productDto.status !== 'ON_SALE') {
|
||||
throw new BadRequestException('商品不可购买');
|
||||
}
|
||||
const product = this.overlayProductWithSku(productDto as Record<string, unknown>, sku);
|
||||
const product = this.overlayProductWithSale(productDto as Record<string, unknown>, sale);
|
||||
|
||||
const city = await this.prisma.commonCity.findFirst({ where: { status: 'ACTIVE' } });
|
||||
if (!city) throw new BadRequestException('暂无开城城市');
|
||||
|
||||
const onSitePickup = !!body.onSitePickup;
|
||||
if (onSitePickup && !sku.allowOnSitePickup) {
|
||||
if (onSitePickup && !sale.allowOnSitePickup) {
|
||||
throw new BadRequestException('该规格不支持现场取货');
|
||||
}
|
||||
|
||||
@@ -129,8 +140,8 @@ export class TradeService {
|
||||
let addressOk = true;
|
||||
let addressMessage: string | null = null;
|
||||
if (!onSitePickup) {
|
||||
const allowOnline = sku.allowOnlinePurchase !== false;
|
||||
const allowCross = sku.allowCrossCityDelivery !== false;
|
||||
const allowOnline = sale.allowOnlinePurchase !== false;
|
||||
const allowCross = sale.allowCrossCityDelivery !== false;
|
||||
if (deliveryType === 'LOCAL' && !allowOnline) {
|
||||
addressOk = false;
|
||||
addressMessage = '该规格不支持线上购买';
|
||||
@@ -145,20 +156,20 @@ export class TradeService {
|
||||
}
|
||||
}
|
||||
|
||||
const bottlesPerUnit = sku.bottlesPerUnit > 0 ? sku.bottlesPerUnit : 1;
|
||||
const bottlesPerUnit = sale.bottlesPerUnit > 0 ? sale.bottlesPerUnit : 1;
|
||||
const check = validateMinPurchase(
|
||||
deliveryType,
|
||||
body.quantity,
|
||||
city.localMinQty,
|
||||
city.crossMinQty,
|
||||
{ bottlesPerUnit, saleUnit: sku.saleUnit },
|
||||
{ bottlesPerUnit, saleUnit: sale.saleUnit },
|
||||
);
|
||||
|
||||
const unitPrice = Number(sku.price);
|
||||
const unitPrice = Number(sale.price);
|
||||
const productAmount = unitPrice * body.quantity;
|
||||
const benefitPerUnit = calcBenefitAmount({
|
||||
price: unitPrice,
|
||||
benefitAmount: sku.benefitAmount != null ? Number(sku.benefitAmount) : null,
|
||||
benefitAmount: sale.benefitAmount != null ? Number(sale.benefitAmount) : null,
|
||||
});
|
||||
|
||||
const freightPayType: FreightPayType | null = deliveryType === 'CROSS_CITY' ? 'COD' : null;
|
||||
@@ -186,10 +197,13 @@ export class TradeService {
|
||||
addressMessage,
|
||||
minQty,
|
||||
onSitePickup,
|
||||
allowCrossCityDelivery: sku.allowCrossCityDelivery !== false,
|
||||
allowOnlinePurchase: sku.allowOnlinePurchase !== false,
|
||||
skuId: sku.id.toString(),
|
||||
saleUnit: sku.saleUnit,
|
||||
allowCrossCityDelivery: sale.allowCrossCityDelivery !== false,
|
||||
allowOnlinePurchase: sale.allowOnlinePurchase !== false,
|
||||
skuId: sale.skuId?.toString(),
|
||||
barcode69: sale.barcode69,
|
||||
productSpec: sale.specText,
|
||||
unitPrice,
|
||||
saleUnit: sale.saleUnit,
|
||||
bottlesPerUnit,
|
||||
bottleQuantity: body.quantity * bottlesPerUnit,
|
||||
};
|
||||
@@ -247,9 +261,6 @@ export class TradeService {
|
||||
const product = await this.prisma.commonProductItem.findUniqueOrThrow({
|
||||
where: { id: BigInt(body.productId) },
|
||||
});
|
||||
const sku = await this.prisma.commonProductSku.findUniqueOrThrow({
|
||||
where: { id: BigInt(preview.skuId) },
|
||||
});
|
||||
const city = await this.prisma.commonCity.findFirstOrThrow({ where: { status: 'ACTIVE' } });
|
||||
const orderNo = generateOrderNo();
|
||||
const payExpireAt = new Date(Date.now() + 30 * 60 * 1000);
|
||||
@@ -282,15 +293,15 @@ export class TradeService {
|
||||
payStatus: 'UNPAID',
|
||||
deliveryType: preview.deliveryType as 'LOCAL' | 'CROSS_CITY' | 'ON_SITE_PICKUP',
|
||||
productId: product.id,
|
||||
skuId: sku.id,
|
||||
barcode69: sku.barcode69,
|
||||
skuId: preview.skuId ? BigInt(preview.skuId) : null,
|
||||
barcode69: preview.barcode69 || product.barcode69,
|
||||
productName: product.name,
|
||||
productSpec: sku.specText || product.spec,
|
||||
productSpec: preview.productSpec || product.spec,
|
||||
imageResourceId: product.coverResourceId,
|
||||
quantity: body.quantity,
|
||||
saleUnit: sku.saleUnit,
|
||||
saleUnit: preview.saleUnit,
|
||||
bottlesPerUnit: preview.bottlesPerUnit,
|
||||
listUnitPrice: sku.price,
|
||||
listUnitPrice: preview.unitPrice,
|
||||
listAmount: preview.productAmount,
|
||||
productAmount: preview.productAmount,
|
||||
receiverName,
|
||||
@@ -346,7 +357,7 @@ export class TradeService {
|
||||
extraJson: {
|
||||
orderId: order.id.toString(),
|
||||
productId: body.productId,
|
||||
skuId: sku.id.toString(),
|
||||
skuId: preview.skuId,
|
||||
quantity: body.quantity,
|
||||
onSitePickup,
|
||||
},
|
||||
@@ -1080,6 +1091,7 @@ export class TradeService {
|
||||
titleId?: string;
|
||||
titleType?: string;
|
||||
invoiceKind?: string;
|
||||
invoiceCategory?: string;
|
||||
titleName?: string;
|
||||
taxNo?: string | null;
|
||||
addressPhone?: string | null;
|
||||
@@ -1088,6 +1100,7 @@ export class TradeService {
|
||||
phone?: string;
|
||||
remark?: string;
|
||||
},
|
||||
opts?: { allowSpecialKind?: boolean },
|
||||
) {
|
||||
const order = await this.prisma.order.findFirst({ where: { id: orderId, userId } });
|
||||
if (!order) throw new NotFoundException('订单不存在');
|
||||
@@ -1137,7 +1150,8 @@ export class TradeService {
|
||||
if (resolved.titleType === 'ENTERPRISE' && !resolved.taxNo?.trim()) {
|
||||
throw new BadRequestException('企业抬头须填写税号');
|
||||
}
|
||||
const invoiceKind = body.invoiceKind || 'NORMAL';
|
||||
const invoiceKind =
|
||||
opts?.allowSpecialKind && body.invoiceKind === 'SPECIAL' ? 'SPECIAL' : 'NORMAL';
|
||||
if (invoiceKind === 'SPECIAL') {
|
||||
if (resolved.titleType !== 'ENTERPRISE') {
|
||||
throw new BadRequestException('专用发票仅支持企业抬头');
|
||||
@@ -1146,6 +1160,7 @@ export class TradeService {
|
||||
throw new BadRequestException('专用发票须填写税号、地址电话与开户行账号');
|
||||
}
|
||||
}
|
||||
const invoiceCategory = body.invoiceCategory === 'CATERING' ? 'CATERING' : 'LIQUOR';
|
||||
|
||||
const invoice = await this.prisma.userInvoice.create({
|
||||
data: {
|
||||
@@ -1154,6 +1169,7 @@ export class TradeService {
|
||||
userId,
|
||||
titleType: resolved.titleType as never,
|
||||
invoiceKind: invoiceKind as never,
|
||||
invoiceCategory: invoiceCategory as never,
|
||||
titleName: resolved.titleName.trim(),
|
||||
taxNo: resolved.taxNo?.trim() || null,
|
||||
addressPhone: resolved.addressPhone?.trim() || null,
|
||||
@@ -1161,7 +1177,7 @@ export class TradeService {
|
||||
email: resolved.email.trim(),
|
||||
phone: resolved.phone.trim(),
|
||||
remark: body.remark?.trim() || null,
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
if (!order.isTest) {
|
||||
@@ -1254,6 +1270,7 @@ export class TradeService {
|
||||
titleId?: string;
|
||||
titleType?: string;
|
||||
invoiceKind?: string;
|
||||
invoiceCategory?: string;
|
||||
titleName?: string;
|
||||
taxNo?: string;
|
||||
addressPhone?: string;
|
||||
@@ -1267,7 +1284,7 @@ export class TradeService {
|
||||
if (!orderNo) throw new BadRequestException('请填写订单号');
|
||||
const order = await this.prisma.order.findFirst({ where: { orderNo } });
|
||||
if (!order) throw new NotFoundException('订单不存在');
|
||||
return this.createInvoice(order.userId, order.id, body);
|
||||
return this.createInvoice(order.userId, order.id, body, { allowSpecialKind: true });
|
||||
}
|
||||
|
||||
async adminListInvoices(query: {
|
||||
@@ -1598,7 +1615,7 @@ export class TradeService {
|
||||
},
|
||||
viewer?: { phone?: string | null; bypassWhitelist?: boolean },
|
||||
) {
|
||||
const { product: spu, sku } = await this.catalogService.assertPurchasable(
|
||||
const { product: spu, sale } = await this.catalogService.assertPurchasable(
|
||||
BigInt(body.productId),
|
||||
viewer?.phone,
|
||||
body.skuId,
|
||||
@@ -1620,7 +1637,7 @@ export class TradeService {
|
||||
let deliveryType: 'LOCAL' | 'CROSS_CITY' | 'ON_SITE_PICKUP' = 'LOCAL';
|
||||
|
||||
if (deliveryMode === 'ON_SITE_PICKUP') {
|
||||
if (!sku.allowOnSitePickup) {
|
||||
if (!sale.allowOnSitePickup) {
|
||||
throw new BadRequestException('该规格不支持现场提货');
|
||||
}
|
||||
deliveryType = 'ON_SITE_PICKUP';
|
||||
@@ -1629,8 +1646,8 @@ export class TradeService {
|
||||
if (receiverCity && receiverCity !== city.name && receiverCity !== '郑州市') {
|
||||
deliveryType = 'CROSS_CITY';
|
||||
}
|
||||
const allowOnline = sku.allowOnlinePurchase !== false;
|
||||
const allowCross = sku.allowCrossCityDelivery !== false;
|
||||
const allowOnline = sale.allowOnlinePurchase !== false;
|
||||
const allowCross = sale.allowCrossCityDelivery !== false;
|
||||
if (deliveryType === 'LOCAL' && !allowOnline) {
|
||||
throw new BadRequestException('该规格不支持线上购买');
|
||||
}
|
||||
@@ -1644,21 +1661,21 @@ export class TradeService {
|
||||
}
|
||||
}
|
||||
|
||||
const bottlesPerUnit = sku.bottlesPerUnit > 0 ? sku.bottlesPerUnit : 1;
|
||||
const bottlesPerUnit = sale.bottlesPerUnit > 0 ? sale.bottlesPerUnit : 1;
|
||||
const check = validateMinPurchase(
|
||||
deliveryType === 'CROSS_CITY' ? 'CROSS_CITY' : deliveryType === 'ON_SITE_PICKUP' ? 'ON_SITE_PICKUP' : 'LOCAL',
|
||||
body.quantity,
|
||||
city.localMinQty,
|
||||
city.crossMinQty,
|
||||
{ bottlesPerUnit, saleUnit: sku.saleUnit },
|
||||
{ bottlesPerUnit, saleUnit: sale.saleUnit },
|
||||
);
|
||||
if (!check.ok) throw new BadRequestException(check.message);
|
||||
|
||||
const unitPrice = Number(sku.price);
|
||||
const unitPrice = Number(sale.price);
|
||||
const productAmount = unitPrice * body.quantity;
|
||||
const benefitPerUnit = calcBenefitAmount({
|
||||
price: unitPrice,
|
||||
benefitAmount: sku.benefitAmount != null ? Number(sku.benefitAmount) : null,
|
||||
benefitAmount: sale.benefitAmount != null ? Number(sale.benefitAmount) : null,
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -1667,8 +1684,10 @@ export class TradeService {
|
||||
benefitAmount: benefitPerUnit * body.quantity,
|
||||
deliveryType,
|
||||
unitPrice,
|
||||
skuId: sku.id.toString(),
|
||||
saleUnit: sku.saleUnit,
|
||||
skuId: sale.skuId?.toString(),
|
||||
barcode69: sale.barcode69,
|
||||
productSpec: sale.specText,
|
||||
saleUnit: sale.saleUnit,
|
||||
bottlesPerUnit,
|
||||
bottleQuantity: body.quantity * bottlesPerUnit,
|
||||
minQuantity: toMinSaleQuantity(
|
||||
@@ -1755,9 +1774,6 @@ export class TradeService {
|
||||
const product = await this.prisma.commonProductItem.findUniqueOrThrow({
|
||||
where: { id: BigInt(body.productId) },
|
||||
});
|
||||
const sku = await this.prisma.commonProductSku.findUniqueOrThrow({
|
||||
where: { id: BigInt(preview.skuId) },
|
||||
});
|
||||
const city = await this.prisma.commonCity.findFirstOrThrow({ where: { status: 'ACTIVE' } });
|
||||
|
||||
let receiverName = body.receiverName?.trim() || `用户${normalizedPhone.slice(-4)}`;
|
||||
@@ -1815,15 +1831,15 @@ export class TradeService {
|
||||
channelSource: 'PROXY_ONLINE',
|
||||
promoCodeId,
|
||||
productId: product.id,
|
||||
skuId: sku.id,
|
||||
barcode69: sku.barcode69,
|
||||
skuId: preview.skuId ? BigInt(preview.skuId) : null,
|
||||
barcode69: preview.barcode69 || product.barcode69,
|
||||
productName: product.name,
|
||||
productSpec: sku.specText || product.spec,
|
||||
productSpec: preview.productSpec || product.spec,
|
||||
imageResourceId: product.coverResourceId,
|
||||
quantity: body.quantity,
|
||||
saleUnit: sku.saleUnit,
|
||||
saleUnit: preview.saleUnit,
|
||||
bottlesPerUnit: preview.bottlesPerUnit,
|
||||
listUnitPrice: sku.price,
|
||||
listUnitPrice: preview.unitPrice,
|
||||
listAmount: preview.productAmount,
|
||||
productAmount: preview.productAmount,
|
||||
payAmount: preview.payAmount,
|
||||
@@ -2171,9 +2187,6 @@ export class TradeService {
|
||||
const product = await this.prisma.commonProductItem.findUniqueOrThrow({
|
||||
where: { id: BigInt(body.productId) },
|
||||
});
|
||||
const sku = await this.prisma.commonProductSku.findUniqueOrThrow({
|
||||
where: { id: BigInt(preview.skuId) },
|
||||
});
|
||||
const city = await this.prisma.commonCity.findFirstOrThrow({ where: { status: 'ACTIVE' } });
|
||||
|
||||
let receiverName = body.receiverName?.trim() || `用户${normalizedPhone.slice(-4)}`;
|
||||
@@ -2231,15 +2244,15 @@ export class TradeService {
|
||||
channelSource: 'PROXY_ONLINE',
|
||||
promoCodeId,
|
||||
productId: product.id,
|
||||
skuId: sku.id,
|
||||
barcode69: sku.barcode69,
|
||||
skuId: preview.skuId ? BigInt(preview.skuId) : null,
|
||||
barcode69: preview.barcode69 || product.barcode69,
|
||||
productName: product.name,
|
||||
productSpec: sku.specText || product.spec,
|
||||
productSpec: preview.productSpec || product.spec,
|
||||
imageResourceId: product.coverResourceId,
|
||||
quantity: body.quantity,
|
||||
saleUnit: sku.saleUnit,
|
||||
saleUnit: preview.saleUnit,
|
||||
bottlesPerUnit: preview.bottlesPerUnit,
|
||||
listUnitPrice: sku.price,
|
||||
listUnitPrice: preview.unitPrice,
|
||||
listAmount: preview.productAmount,
|
||||
productAmount: preview.productAmount,
|
||||
payAmount: preview.payAmount,
|
||||
|
||||
Reference in New Issue
Block a user