Merge branches 'dev_jacy' and 'dev' of git.yqidian.com:jacy/dukang into dev
This commit is contained in:
@@ -21,6 +21,22 @@ type ProductDetailContentDto = {
|
|||||||
features?: Array<{ icon: string; title: string; desc: string }>;
|
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 = {
|
type Row = {
|
||||||
id: string;
|
id: string;
|
||||||
skuCode: string;
|
skuCode: string;
|
||||||
@@ -30,9 +46,15 @@ type Row = {
|
|||||||
aromaType: string;
|
aromaType: string;
|
||||||
spec: string;
|
spec: string;
|
||||||
price: number;
|
price: number;
|
||||||
|
priceMin?: number;
|
||||||
|
priceMax?: number;
|
||||||
|
soldBottles?: number;
|
||||||
benefitAmount: number;
|
benefitAmount: number;
|
||||||
status: string;
|
status: string;
|
||||||
sortOrder: number;
|
sortOrder: number;
|
||||||
|
skuCount?: number;
|
||||||
|
specEnabled?: boolean;
|
||||||
|
skus?: SkuListRow[];
|
||||||
allowOnSitePickup?: boolean;
|
allowOnSitePickup?: boolean;
|
||||||
allowOnlinePurchase?: boolean;
|
allowOnlinePurchase?: boolean;
|
||||||
allowCrossCityDelivery?: 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{mode === 'create' && (
|
{mode === 'create' && (
|
||||||
@@ -256,39 +304,47 @@ function BaseInfoFields({ mode, form }: { mode: 'create' | 'edit'; form: FormIns
|
|||||||
<Form.Item name="sortOrder" label="排序">
|
<Form.Item name="sortOrder" label="排序">
|
||||||
<InputNumber min={0} style={{ width: '100%' }} />
|
<InputNumber min={0} style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
{hideFulfillment ? (
|
||||||
name="allowOnlinePurchase"
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 16 }}>
|
||||||
label="允许线上购买"
|
该商品有多种规格,履约(线上 / 跨城 / 现场)请到「规格与 SKU」中按规格设置。
|
||||||
valuePropName="checked"
|
</Typography.Paragraph>
|
||||||
extra="配送到址(同城)"
|
) : (
|
||||||
>
|
<>
|
||||||
<Switch
|
|
||||||
checkedChildren="开"
|
|
||||||
unCheckedChildren="关"
|
|
||||||
onChange={(checked) => {
|
|
||||||
if (!checked) form.setFieldsValue({ allowCrossCityDelivery: false });
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.allowOnlinePurchase !== cur.allowOnlinePurchase}>
|
|
||||||
{() => (
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="allowCrossCityDelivery"
|
name="allowOnlinePurchase"
|
||||||
label="允许跨城配送"
|
label="允许线上购买"
|
||||||
valuePropName="checked"
|
valuePropName="checked"
|
||||||
extra="须先开启线上购买"
|
extra="配送到址(同城)"
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
checkedChildren="开"
|
checkedChildren="开"
|
||||||
unCheckedChildren="关"
|
unCheckedChildren="关"
|
||||||
disabled={!form.getFieldValue('allowOnlinePurchase')}
|
onChange={(checked) => {
|
||||||
|
if (!checked) form.setFieldsValue({ allowCrossCityDelivery: false });
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.allowOnlinePurchase !== cur.allowOnlinePurchase}>
|
||||||
</Form.Item>
|
{() => (
|
||||||
<Form.Item name="allowOnSitePickup" label="允许现场取货" valuePropName="checked">
|
<Form.Item
|
||||||
<Switch checkedChildren="开" unCheckedChildren="关" />
|
name="allowCrossCityDelivery"
|
||||||
</Form.Item>
|
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} />
|
<VisibilityWhitelistFields form={form} />
|
||||||
<Form.Item name="coverUrl" label="封面">
|
<Form.Item name="coverUrl" label="封面">
|
||||||
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
<OssUpload bizType="COVER" mediaType="IMAGE" />
|
||||||
@@ -332,12 +388,35 @@ export default function ProductsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnsType<Row> = useMemo(() => [
|
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: 'aromaType', width: 80, render: (v) => AROMA_TYPE_LABELS[v] || v },
|
||||||
{ title: '规格', dataIndex: 'spec', width: 120, ellipsis: true },
|
{ title: '品名', dataIndex: 'name', width: 200, ellipsis: true },
|
||||||
{ title: '售价', dataIndex: 'price', width: 80, render: (v) => `¥${v}` },
|
{
|
||||||
{ title: '权益额', dataIndex: 'benefitAmount', width: 80, render: (v) => `¥${v}` },
|
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) => (
|
{ title: '状态', dataIndex: 'status', width: 80, render: (s) => (
|
||||||
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
|
<Tag color={s === 'ON_SALE' ? 'green' : undefined}>{PRODUCT_STATUS_LABELS[s] || s}</Tag>
|
||||||
) },
|
) },
|
||||||
@@ -348,23 +427,7 @@ export default function ProductsPage() {
|
|||||||
render: (v: boolean) =>
|
render: (v: boolean) =>
|
||||||
v ? <Tag color="orange">限测</Tag> : <Tag>公开</Tag>,
|
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: 'sortOrder', width: 60 },
|
||||||
{ title: '创建', dataIndex: 'createdAt', width: 160, render: fmtTime },
|
|
||||||
{
|
{
|
||||||
title: '操作', width: 120,
|
title: '操作', width: 120,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
@@ -377,7 +440,7 @@ export default function ProductsPage() {
|
|||||||
}}>编辑</Button>
|
}}>编辑</Button>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title="确认删除该商品?"
|
title="确认删除该商品?"
|
||||||
description={`将永久删除「${row.name}」(${row.skuCode}),此操作不可恢复。`}
|
description={`将永久删除「${row.name}」,此操作不可恢复。`}
|
||||||
okText="确认删除"
|
okText="确认删除"
|
||||||
cancelText="取消"
|
cancelText="取消"
|
||||||
okButtonProps={{ danger: true }}
|
okButtonProps={{ danger: true }}
|
||||||
@@ -390,6 +453,46 @@ export default function ProductsPage() {
|
|||||||
},
|
},
|
||||||
], [detail, editForm]);
|
], [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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
<Space style={{ marginBottom: 16, width: '100%', justifyContent: 'space-between' }}>
|
||||||
@@ -397,7 +500,9 @@ export default function ProductsPage() {
|
|||||||
<Button type="primary" onClick={() => setCreateOpen(true)}>新建商品</Button>
|
<Button type="primary" onClick={() => setCreateOpen(true)}>新建商品</Button>
|
||||||
</Space>
|
</Space>
|
||||||
<Form form={form} layout="inline" style={{ marginBottom: 16 }} onFinish={(v) => { setFilters(v); setPage(1); }}>
|
<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="状态">
|
<Form.Item name="status" label="状态">
|
||||||
<Select allowClear style={{ width: 110 }} options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
<Select allowClear style={{ width: 110 }} options={Object.entries(PRODUCT_STATUS_LABELS).map(([value, label]) => ({ value, label }))} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -406,17 +511,46 @@ export default function ProductsPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
<Form.Item><Button type="primary" htmlType="submit">查询</Button></Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
<Table rowKey="id" className="admin-table-nowrap" loading={loading} columns={columns} dataSource={data?.items ?? []} scroll={{ x: 1320 }}
|
<Table
|
||||||
pagination={{ current: page, pageSize, total: data?.total ?? 0, showSizeChanger: true, onChange: (p, ps) => { setPage(p); setPageSize(ps); } }} />
|
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)}
|
<Drawer title="编辑商品" width={1100} open={drawerOpen} onClose={() => setDrawerOpen(false)}
|
||||||
extra={detail && (
|
extra={detail && (
|
||||||
<Button type="primary" onClick={async () => {
|
<Button type="primary" onClick={async () => {
|
||||||
const v = await editForm.validateFields();
|
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('请至少勾选「允许线上购买」或「允许现场取货」之一');
|
message.error('请至少勾选「允许线上购买」或「允许现场取货」之一');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const payload = buildProductPayload(v);
|
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) });
|
await request(`/admin/products/${detail.id}`, { method: 'PUT', body: JSON.stringify(payload) });
|
||||||
message.success('已保存');
|
message.success('已保存');
|
||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
@@ -426,13 +560,24 @@ export default function ProductsPage() {
|
|||||||
{detail && (
|
{detail && (
|
||||||
<>
|
<>
|
||||||
<Descriptions column={1} bordered size="small" style={{ marginBottom: 16 }}>
|
<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="默认 69 码">{String(detail.barcode69)}</Descriptions.Item>
|
||||||
<Descriptions.Item label="香型">{AROMA_TYPE_LABELS[String(detail.aromaType)] || String(detail.aromaType)}</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>
|
</Descriptions>
|
||||||
<Form form={editForm} layout="vertical">
|
<Form form={editForm} layout="vertical">
|
||||||
<Tabs items={[
|
<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',
|
key: 'detail',
|
||||||
label: '详情页',
|
label: '详情页',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dukang/mini-user",
|
"name": "@dukang/mini-user",
|
||||||
"version": "3.4.15",
|
"version": "3.5.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "杜康好客 · C 端用户微信小程序(Taro)",
|
"description": "杜康好客 · C 端用户微信小程序(Taro)",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Taro from '@tarojs/taro';
|
|||||||
import { fetchClientConfig } from './pay-wechat';
|
import { fetchClientConfig } from './pay-wechat';
|
||||||
|
|
||||||
/** 与 package.json version 同步,供服务端 minClientVersion 比对 */
|
/** 与 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}`;
|
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 page = query.page ?? 1;
|
||||||
const pageSize = query.pageSize ?? 20;
|
const pageSize = query.pageSize ?? 20;
|
||||||
const where: Prisma.CommonProductItemWhereInput = {};
|
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.status) where.status = query.status as Prisma.EnumProductStatusFilter['equals'];
|
||||||
if (query.aromaType) where.aromaType = query.aromaType as Prisma.EnumAromaTypeFilter['equals'];
|
if (query.aromaType) where.aromaType = query.aromaType as Prisma.EnumAromaTypeFilter['equals'];
|
||||||
|
|
||||||
@@ -99,7 +111,25 @@ export class AdminProductsService {
|
|||||||
include: {
|
include: {
|
||||||
coverResource: true,
|
coverResource: true,
|
||||||
visibilityPhones: { select: { phone: true }, orderBy: { phone: 'asc' } },
|
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 } },
|
specAttrs: { select: { id: true } },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -120,13 +150,101 @@ export class AdminProductsService {
|
|||||||
: [];
|
: [];
|
||||||
const resourceMap = groupResourcesByProductId(resources);
|
const resourceMap = groupResourcesByProductId(resources);
|
||||||
|
|
||||||
|
/** productId → skuIdKey → bottles;skuIdKey 用 '' 表示历史无 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({
|
return serializeBigInt({
|
||||||
items: items.map((p) => {
|
items: items.map((p) => {
|
||||||
const { skus, specAttrs, ...rest } = 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 {
|
return {
|
||||||
...this.formatProduct(rest as never, resourceMap.get(p.id.toString()) ?? []),
|
...formatted,
|
||||||
specEnabled: specAttrs.length > 0 || skus.length > 1,
|
specEnabled: specAttrs.length > 0 || skus.length > 1,
|
||||||
skuCount: skus.length,
|
skuCount: skus.length,
|
||||||
|
priceMin,
|
||||||
|
priceMax,
|
||||||
|
soldBottles,
|
||||||
|
skus: skuRows,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
total,
|
total,
|
||||||
@@ -246,10 +364,14 @@ export class AdminProductsService {
|
|||||||
const existing = await this.prisma.commonProductItem.findUnique({ where: { id } });
|
const existing = await this.prisma.commonProductItem.findUnique({ where: { id } });
|
||||||
if (!existing) throw new NotFoundException('商品不存在');
|
if (!existing) throw new NotFoundException('商品不存在');
|
||||||
|
|
||||||
|
const skuCount = await this.prisma.commonProductSku.count({ where: { productId: id } });
|
||||||
|
/** 多规格时履约只在规格 SKU 上改;忽略基础信息里的履约字段,避免误覆盖默认 SKU 冗余 */
|
||||||
|
const applyFulfillment = skuCount <= 1;
|
||||||
const fulfillmentTouched =
|
const fulfillmentTouched =
|
||||||
dto.allowOnlinePurchase !== undefined ||
|
applyFulfillment &&
|
||||||
dto.allowCrossCityDelivery !== undefined ||
|
(dto.allowOnlinePurchase !== undefined ||
|
||||||
dto.allowOnSitePickup !== undefined;
|
dto.allowCrossCityDelivery !== undefined ||
|
||||||
|
dto.allowOnSitePickup !== undefined);
|
||||||
const flags = fulfillmentTouched
|
const flags = fulfillmentTouched
|
||||||
? resolveFulfillmentFlags({
|
? resolveFulfillmentFlags({
|
||||||
allowOnlinePurchase: dto.allowOnlinePurchase,
|
allowOnlinePurchase: dto.allowOnlinePurchase,
|
||||||
|
|||||||
Reference in New Issue
Block a user