merge(dev): HQ product list as SPU with expandable SKUs
CI / verify (push) Waiting to run

This commit is contained in:
2026-08-21 23:52:41 +08:00
5 changed files with 329 additions and 62 deletions
+199 -54
View File
@@ -21,6 +21,22 @@ type ProductDetailContentDto = {
features?: Array<{ icon: string; title: string; desc: string }>;
};
type SkuListRow = {
id: string;
skuCode: string;
barcode69: string;
specText: string;
price: number;
benefitAmount: number;
status: string;
isDefault?: boolean;
allowOnSitePickup?: boolean;
allowOnlinePurchase?: boolean;
allowCrossCityDelivery?: boolean;
soldBottles?: number;
virtual?: boolean;
};
type Row = {
id: string;
skuCode: string;
@@ -30,9 +46,15 @@ type Row = {
aromaType: string;
spec: string;
price: number;
priceMin?: number;
priceMax?: number;
soldBottles?: number;
benefitAmount: number;
status: string;
sortOrder: number;
skuCount?: number;
specEnabled?: boolean;
skus?: SkuListRow[];
allowOnSitePickup?: boolean;
allowOnlinePurchase?: boolean;
allowCrossCityDelivery?: boolean;
@@ -214,7 +236,33 @@ function VisibilityWhitelistFields({ form }: { form: FormInstance }) {
);
}
function BaseInfoFields({ mode, form }: { mode: 'create' | 'edit'; form: FormInstance }) {
function FulfillmentTags(row: {
allowOnlinePurchase?: boolean;
allowCrossCityDelivery?: boolean;
allowOnSitePickup?: boolean;
}) {
return (
<Space size={[0, 4]} wrap>
{row.allowOnlinePurchase !== false ? <Tag color="blue">线</Tag> : null}
{row.allowOnlinePurchase !== false && row.allowCrossCityDelivery !== false ? (
<Tag color="cyan"></Tag>
) : null}
{row.allowOnSitePickup ? <Tag color="green"></Tag> : null}
{row.allowOnlinePurchase === false && !row.allowOnSitePickup ? <Tag></Tag> : null}
</Space>
);
}
function BaseInfoFields({
mode,
form,
hideFulfillment,
}: {
mode: 'create' | 'edit';
form: FormInstance;
/** 多规格商品:履约只在规格 SKU 上编辑 */
hideFulfillment?: boolean;
}) {
return (
<>
{mode === 'create' && (
@@ -256,39 +304,47 @@ function BaseInfoFields({ mode, form }: { mode: 'create' | 'edit'; form: FormIns
<Form.Item name="sortOrder" label="排序">
<InputNumber min={0} style={{ width: '100%' }} />
</Form.Item>
<Form.Item
name="allowOnlinePurchase"
label="允许线上购买"
valuePropName="checked"
extra="配送到址(同城)"
>
<Switch
checkedChildren="开"
unCheckedChildren="关"
onChange={(checked) => {
if (!checked) form.setFieldsValue({ allowCrossCityDelivery: false });
}}
/>
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.allowOnlinePurchase !== cur.allowOnlinePurchase}>
{() => (
{hideFulfillment ? (
<Typography.Paragraph type="secondary" style={{ marginBottom: 16 }}>
线 / / SKU
</Typography.Paragraph>
) : (
<>
<Form.Item
name="allowCrossCityDelivery"
label="允许跨城配送"
name="allowOnlinePurchase"
label="允许线上购买"
valuePropName="checked"
extra="须先开启线上购买"
extra="配送到址(同城)"
>
<Switch
checkedChildren="开"
unCheckedChildren="关"
disabled={!form.getFieldValue('allowOnlinePurchase')}
onChange={(checked) => {
if (!checked) form.setFieldsValue({ allowCrossCityDelivery: false });
}}
/>
</Form.Item>
)}
</Form.Item>
<Form.Item name="allowOnSitePickup" label="允许现场取货" valuePropName="checked">
<Switch checkedChildren="开" unCheckedChildren="关" />
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.allowOnlinePurchase !== cur.allowOnlinePurchase}>
{() => (
<Form.Item
name="allowCrossCityDelivery"
label="允许跨城配送"
valuePropName="checked"
extra="须先开启线上购买"
>
<Switch
checkedChildren="开"
unCheckedChildren="关"
disabled={!form.getFieldValue('allowOnlinePurchase')}
/>
</Form.Item>
)}
</Form.Item>
<Form.Item name="allowOnSitePickup" label="允许现场取货" valuePropName="checked">
<Switch checkedChildren="开" unCheckedChildren="关" />
</Form.Item>
</>
)}
<VisibilityWhitelistFields form={form} />
<Form.Item name="coverUrl" label="封面">
<OssUpload bizType="COVER" mediaType="IMAGE" />
@@ -332,12 +388,35 @@ export default function ProductsPage() {
}
const columns: ColumnsType<Row> = useMemo(() => [
{ title: 'SKU', dataIndex: 'skuCode', width: 90 },
{ title: '商品名', dataIndex: 'name', width: 180, ellipsis: true },
{ title: '香型', dataIndex: 'aromaType', width: 80, render: (v) => AROMA_TYPE_LABELS[v] || v },
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
{ title: '品名', dataIndex: 'name', width: 200, ellipsis: true },
{
title: '累计销售',
dataIndex: 'soldBottles',
width: 110,
render: (v: number | undefined) => `累计 ${v ?? 0}`,
},
{
title: '售价',
key: 'priceRange',
width: 120,
render: (_, row) => {
const min = row.priceMin ?? row.price;
const max = row.priceMax ?? row.price;
if (min === max) return `¥${min}`;
return `¥${min} ~ ¥${max}`;
},
},
{
title: '规格数',
dataIndex: 'skuCount',
width: 80,
render: (v: number | undefined, row) => {
const real = v ?? 0;
if (real > 0) return real;
return row.skus?.some((s) => s.virtual) ? 1 : 0;
},
},
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => (
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
) },
@@ -348,23 +427,7 @@ export default function ProductsPage() {
render: (v: boolean) =>
v ? <Tag color="orange"></Tag> : <Tag></Tag>,
},
{
title: '履约',
key: 'fulfillment',
width: 160,
render: (_, row) => (
<Space size={[0, 4]} wrap>
{row.allowOnlinePurchase !== false ? <Tag color="blue">线</Tag> : null}
{row.allowOnlinePurchase !== false && row.allowCrossCityDelivery !== false ? (
<Tag color="cyan"></Tag>
) : null}
{row.allowOnSitePickup ? <Tag color="green"></Tag> : null}
{row.allowOnlinePurchase === false && !row.allowOnSitePickup ? <Tag></Tag> : null}
</Space>
),
},
{ title: '排序', dataIndex: 'sortOrder', width: 60 },
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
{
title: '操作', width: 120,
render: (_, row) => (
@@ -377,7 +440,7 @@ export default function ProductsPage() {
}}></Button>
<Popconfirm
title="确认删除该商品?"
description={`将永久删除「${row.name}${row.skuCode},此操作不可恢复。`}
description={`将永久删除「${row.name}」,此操作不可恢复。`}
okText="确认删除"
cancelText="取消"
okButtonProps={{ danger: true }}
@@ -390,6 +453,46 @@ export default function ProductsPage() {
},
], [detail, editForm]);
const skuColumns: ColumnsType<SkuListRow> = useMemo(() => [
{
title: '规格',
dataIndex: 'specText',
width: 140,
ellipsis: true,
render: (v: string, row) => (
<Space size={4}>
<span>{v || '默认'}</span>
{row.isDefault ? <Tag color="blue"></Tag> : null}
{row.virtual ? <Tag>SKU</Tag> : null}
</Space>
),
},
{ title: 'SKU', dataIndex: 'skuCode', width: 110 },
{ title: '69码', dataIndex: 'barcode69', width: 160, ellipsis: true },
{ title: '售价', dataIndex: 'price', width: 90, render: (v) => `¥${v}` },
{ title: '权益额', dataIndex: 'benefitAmount', width: 90, render: (v) => `¥${v}` },
{
title: '累计销售',
dataIndex: 'soldBottles',
width: 100,
render: (v: number | undefined) => `${v ?? 0}`,
},
{
title: '履约',
key: 'fulfillment',
width: 160,
render: (_, row) => <FulfillmentTags {...row} />,
},
{
title: '状态',
dataIndex: 'status',
width: 90,
render: (s) => (
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
),
},
], []);
return (
<div>
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
@@ -397,7 +500,9 @@ export default function ProductsPage() {
<Button type="primary" onClick={() => setCreateOpen(true)}></Button>
</Space>
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={(v) => { setFilters(v); setPage(1); }}>
<Form.Item name="name" label="名称"><Input allowClear /></Form.Item>
<Form.Item name="name" label="名称">
<Input allowClear placeholder="名称 / SKU / 69 码" style={{ width: 200 }} />
</Form.Item>
<Form.Item name="status" label="状态">
<Select allowClear style={{ width: 110 }} options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
</Form.Item>
@@ -406,17 +511,46 @@ export default function ProductsPage() {
</Form.Item>
<Form.Item><Button type="primary" htmlType="submit"></Button></Form.Item>
</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); } }} />
<Table
rowKey="id"
className="admin-table-nowrap"
loading={loading}
columns={columns}
dataSource={data?.items ?? []}
scroll={{ x: 1080 }}
expandable={{
rowExpandable: () => true,
expandedRowRender: (row) => (
<div style={{ margin: '-8px -8px -8px 24px', padding: 12, background: '#f5f5f5', borderRadius: 6 }}>
<Table
size="small"
rowKey="id"
pagination={false}
columns={skuColumns}
dataSource={row.skus ?? []}
scroll={{ x: 980 }}
style={{ background: 'transparent' }}
/>
</div>
),
}}
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }}
/>
<Drawer title="编辑商品" width={1100} open={drawerOpen} onClose={() => setDrawerOpen(false)}
extra={detail && (
<Button type="primary" onClick={async () => {
const v = await editForm.validateFields();
if (!v.allowOnlinePurchase && !v.allowOnSitePickup) {
const multiSku = Array.isArray(detail.skus) && (detail.skus as unknown[]).length > 1;
if (!multiSku && !v.allowOnlinePurchase && !v.allowOnSitePickup) {
message.error('请至少勾选「允许线上购买」或「允许现场取货」之一');
return;
}
const payload = buildProductPayload(v);
if (multiSku) {
delete (payload as { allowOnlinePurchase?: boolean }).allowOnlinePurchase;
delete (payload as { allowCrossCityDelivery?: boolean }).allowCrossCityDelivery;
delete (payload as { allowOnSitePickup?: boolean }).allowOnSitePickup;
}
await request(`/admin/products/${detail.id}`, { method: 'PUT', body: JSON.stringify(payload) });
message.success('已保存');
setDrawerOpen(false);
@@ -426,13 +560,24 @@ 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="默认 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.Item label="创建时间">{fmtTime(String(detail.createdAt ?? ''))}</Descriptions.Item>
</Descriptions>
<Form form={editForm} layout="vertical">
<Tabs items={[
{ key: 'base', label: '基础信息', children: <BaseInfoFields mode="edit" form={editForm} /> },
{
key: 'base',
label: '基础信息',
children: (
<BaseInfoFields
mode="edit"
form={editForm}
hideFulfillment={Array.isArray(detail.skus) && (detail.skus as unknown[]).length > 1}
/>
),
},
{
key: 'detail',
label: '详情页',
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@dukang/mini-user",
"version": "3.4.15",
"version": "3.5.4",
"private": true,
"description": "杜康好客 · C 端用户微信小程序(Taro)",
"scripts": {
+1 -1
View File
@@ -2,7 +2,7 @@ import Taro from '@tarojs/taro';
import { fetchClientConfig } from './pay-wechat';
/** 与 package.json version 同步,供服务端 minClientVersion 比对 */
export const APP_VERSION = '3.4.15';
export const APP_VERSION = '3.5.4';
export const APP_VERSION_LABEL = `v${APP_VERSION}`;
Binary file not shown.

After

Width:  |  Height:  |  Size: 921 KiB

@@ -86,7 +86,19 @@ export class AdminProductsService {
const page = query.page ?? 1;
const pageSize = query.pageSize ?? 20;
const where: Prisma.CommonProductItemWhereInput = {};
if (query.name) where.name = { contains: query.name };
if (query.name?.trim()) {
const kw = query.name.trim();
where.OR = [
{ name: { contains: kw } },
{
skus: {
some: {
OR: [{ skuCode: { contains: kw } }, { barcode69: { contains: kw } }],
},
},
},
];
}
if (query.status) where.status = query.status as Prisma.EnumProductStatusFilter['equals'];
if (query.aromaType) where.aromaType = query.aromaType as Prisma.EnumAromaTypeFilter['equals'];
@@ -99,7 +111,25 @@ export class AdminProductsService {
include: {
coverResource: true,
visibilityPhones: { select: { phone: true }, orderBy: { phone: 'asc' } },
skus: { select: { id: true }, take: 2 },
skus: {
orderBy: [{ sortOrder: 'asc' }, { id: 'asc' }],
select: {
id: true,
skuCode: true,
barcode69: true,
specText: true,
price: true,
benefitAmount: true,
status: true,
isDefault: true,
sortOrder: true,
allowOnSitePickup: true,
allowOnlinePurchase: true,
allowCrossCityDelivery: true,
saleUnit: true,
bottlesPerUnit: true,
},
},
specAttrs: { select: { id: true } },
},
}),
@@ -120,13 +150,101 @@ export class AdminProductsService {
: [];
const resourceMap = groupResourcesByProductId(resources);
/** productId → skuIdKey → bottlesskuIdKey 用 '' 表示历史无 sku */
const soldByProductSku = new Map<string, Map<string, number>>();
if (productIds.length) {
const saleOrders = await this.prisma.order.findMany({
where: {
productId: { in: productIds },
payStatus: 'PAID',
isTest: false,
status: { notIn: ['PENDING_PAY', 'CANCELLED', 'REFUNDED'] },
},
select: {
productId: true,
skuId: true,
quantity: true,
bottlesPerUnit: true,
},
});
for (const o of saleOrders) {
const pid = o.productId.toString();
const sid = o.skuId?.toString() ?? '';
const bottles = o.quantity * (o.bottlesPerUnit > 0 ? o.bottlesPerUnit : 1);
let bySku = soldByProductSku.get(pid);
if (!bySku) {
bySku = new Map();
soldByProductSku.set(pid, bySku);
}
bySku.set(sid, (bySku.get(sid) ?? 0) + bottles);
}
}
return serializeBigInt({
items: items.map((p) => {
const { skus, specAttrs, ...rest } = p;
const formatted = this.formatProduct(rest as never, resourceMap.get(p.id.toString()) ?? []);
const prices = skus.length
? skus.map((s) => Number(s.price))
: [Number(p.price)];
const priceMin = Math.min(...prices);
const priceMax = Math.max(...prices);
const pid = p.id.toString();
const bySku = soldByProductSku.get(pid);
let soldBottles = 0;
if (bySku) {
for (const n of bySku.values()) soldBottles += n;
}
const skuRows =
skus.length > 0
? skus.map((s) => ({
id: s.id.toString(),
skuCode: s.skuCode,
barcode69: s.barcode69,
specText: s.specText,
price: Number(s.price),
benefitAmount: Number(s.benefitAmount ?? s.price),
status: s.status,
isDefault: s.isDefault,
sortOrder: s.sortOrder,
allowOnSitePickup: s.allowOnSitePickup,
allowOnlinePurchase: s.allowOnlinePurchase,
allowCrossCityDelivery: s.allowCrossCityDelivery,
saleUnit: s.saleUnit,
bottlesPerUnit: s.bottlesPerUnit,
soldBottles: bySku?.get(s.id.toString()) ?? 0,
virtual: false,
}))
: [
{
id: `virtual-${pid}`,
skuCode: p.skuCode,
barcode69: p.barcode69,
specText: p.spec,
price: Number(p.price),
benefitAmount: Number(p.benefitAmount ?? p.price),
status: p.status,
isDefault: true,
sortOrder: 0,
allowOnSitePickup: p.allowOnSitePickup,
allowOnlinePurchase: p.allowOnlinePurchase,
allowCrossCityDelivery: p.allowCrossCityDelivery,
saleUnit: 'BOTTLE' as const,
bottlesPerUnit: 1,
soldBottles,
virtual: true,
},
];
return {
...this.formatProduct(rest as never, resourceMap.get(p.id.toString()) ?? []),
...formatted,
specEnabled: specAttrs.length > 0 || skus.length > 1,
skuCount: skus.length,
priceMin,
priceMax,
soldBottles,
skus: skuRows,
};
}),
total,
@@ -246,10 +364,14 @@ export class AdminProductsService {
const existing = await this.prisma.commonProductItem.findUnique({ where: { id } });
if (!existing) throw new NotFoundException('商品不存在');
const skuCount = await this.prisma.commonProductSku.count({ where: { productId: id } });
/** 多规格时履约只在规格 SKU 上改;忽略基础信息里的履约字段,避免误覆盖默认 SKU 冗余 */
const applyFulfillment = skuCount <= 1;
const fulfillmentTouched =
dto.allowOnlinePurchase !== undefined ||
dto.allowCrossCityDelivery !== undefined ||
dto.allowOnSitePickup !== undefined;
applyFulfillment &&
(dto.allowOnlinePurchase !== undefined ||
dto.allowCrossCityDelivery !== undefined ||
dto.allowOnSitePickup !== undefined);
const flags = fulfillmentTouched
? resolveFulfillmentFlags({
allowOnlinePurchase: dto.allowOnlinePurchase,