feat: 新增拼多多店铺日推广费和开放接口

This commit is contained in:
2026-08-16 11:10:46 +08:00
parent c21dbc2d5c
commit 2f32d955eb
25 changed files with 1813 additions and 1 deletions
@@ -0,0 +1,41 @@
import type { PageQueryDTO, PageResultVO } from '#/types/common';
import { requestClient } from '#/api/request';
import type { PddGoodsAdFeeDTO, PddGoodsAdFeeVO } from './types';
export async function getPddGoodsAdFeePageApi(
params: PageQueryDTO<PddGoodsAdFeeDTO.Filters>,
) {
return requestClient.post<PageResultVO<PddGoodsAdFeeVO.Info>>(
'/channel/pdd/goods/adfee/list',
params,
);
}
export async function getPddGoodsAdFeeDetailApi(id: number) {
return requestClient.get<PddGoodsAdFeeVO.Info>(
`/channel/pdd/goods/adfee/detail/${id}`,
);
}
export async function createPddGoodsAdFeeApi(data: PddGoodsAdFeeDTO.Create) {
return requestClient.post<PddGoodsAdFeeVO.Info>(
'/channel/pdd/goods/adfee/create',
data,
);
}
export async function updatePddGoodsAdFeeApi(
id: number,
data: PddGoodsAdFeeDTO.Update,
) {
return requestClient.put<PddGoodsAdFeeVO.Info>(
`/channel/pdd/goods/adfee/update/${id}`,
data,
);
}
export async function deletePddGoodsAdFeeApi(id: number) {
return requestClient.delete<void>(`/channel/pdd/goods/adfee/delete/${id}`);
}
@@ -0,0 +1,2 @@
export * from './apis';
export type { PddGoodsAdFeeDTO, PddGoodsAdFeeVO } from './types';
@@ -0,0 +1,42 @@
/**
* 拼多多商品广告费 DTO / VO
*/
export namespace PddGoodsAdFeeDTO {
export interface Filters {
channelShopId?: number;
goodsId?: string;
feeDateStart?: string;
feeDateEnd?: string;
}
export interface Create {
channelShopId: number;
goodsId: string;
feeDate: string;
feeAmount: number;
}
export interface Update {
channelShopId: number;
goodsId: string;
feeDate: string;
feeAmount: number;
}
}
export namespace PddGoodsAdFeeVO {
export interface Info {
id: number;
companyId?: number;
channelShopId: number;
channelShopName?: string;
mallId?: number;
goodsId: string;
goodsName?: string;
feeDate: string;
feeAmount: number;
lastSyncTime?: string;
createTime?: string;
updateTime?: string;
}
}
@@ -0,0 +1,292 @@
<script setup lang="ts">
import type {
PddGoodsAdFeeDTO,
PddGoodsAdFeeVO,
} from '#/api/channel/pdd/goods-ad-fee';
import type { PddShopVO } from '#/api/channel/pdd/shop';
import { nextTick, ref, watch } from 'vue';
import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
import { useVbenModal } from '@vben/common-ui';
import { DatePicker, Form, InputNumber, message, Select } from 'ant-design-vue';
import {
createPddGoodsAdFeeApi,
updatePddGoodsAdFeeApi,
} from '#/api/channel/pdd/goods-ad-fee';
import { getPddGoodsPageApi } from '#/api/channel/pdd/goods';
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
defineOptions({ name: 'GoodsAdFeeFormModal' });
interface Props {
open: boolean;
adFeeData?: null | PddGoodsAdFeeVO.Info;
presetChannelShopId?: number | null;
}
const props = withDefaults(defineProps<Props>(), {
presetChannelShopId: null,
});
const emit = defineEmits<{
'update:open': [value: boolean];
success: [];
cancel: [];
}>();
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[640px]',
destroyOnClose: false,
onCancel() {
handleCancel();
},
onConfirm() {
void handleOk();
},
onOpenChange(isOpen: boolean) {
if (!isOpen) {
emit('update:open', false);
resetFormData();
}
},
});
const formRef = ref();
const isEdit = ref(false);
type FormState = {
channelShopId?: number;
goodsId?: string;
feeDate?: Dayjs;
feeAmount?: number;
};
const formData = ref<FormState>({
channelShopId: undefined,
goodsId: undefined,
feeDate: undefined,
feeAmount: undefined,
});
const rules = {
channelShopId: [
{ required: true, message: '请选择渠道店铺', trigger: 'change' },
],
goodsId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }],
feeAmount: [
{ required: true, message: '请输入广告费金额', trigger: 'blur' },
],
feeDate: [{ required: true, message: '请选择统计日期', trigger: 'change' }],
} as any;
const shopOptions = ref<{ label: string; value: number }[]>([]);
const shopLoading = ref(false);
const goodsOptions = ref<{ label: string; value: string }[]>([]);
const goodsLoading = ref(false);
async function loadShops() {
shopLoading.value = true;
try {
const result = await getPddShopPageApi({
page: 1,
pageSize: 500,
filters: {},
});
shopOptions.value = (result.records ?? []).map((s: PddShopVO.Info) => ({
label: s.mallName
? `${s.mallName}${s.mallId != null ? ` (${s.mallId})` : ''}`
: `店铺 #${s.id}`,
value: s.id,
}));
} catch {
shopOptions.value = [];
} finally {
shopLoading.value = false;
}
}
async function loadGoodsOptions(channelShopId?: number) {
if (!channelShopId) {
goodsOptions.value = [];
return;
}
goodsLoading.value = true;
try {
const result = await getPddGoodsPageApi({
page: 1,
pageSize: 500,
filters: { shopId: channelShopId },
});
goodsOptions.value = (result.records ?? []).map((g) => ({
label: g.goodsName
? `${g.goodsName} (${g.goodsId})`
: String(g.goodsId),
value: String(g.goodsId),
}));
} catch {
goodsOptions.value = [];
} finally {
goodsLoading.value = false;
}
}
function resetFormData() {
formData.value = {
channelShopId: undefined,
goodsId: undefined,
feeDate: undefined,
feeAmount: undefined,
};
formRef.value?.resetFields?.();
}
function fillForm() {
if (props.adFeeData) {
isEdit.value = true;
formData.value = {
channelShopId: props.adFeeData.channelShopId,
goodsId: props.adFeeData.goodsId,
feeDate: props.adFeeData.feeDate
? dayjs(props.adFeeData.feeDate)
: undefined,
feeAmount: props.adFeeData.feeAmount,
};
void loadGoodsOptions(props.adFeeData.channelShopId);
modalApi.setState({ title: '编辑商品广告费' });
} else {
isEdit.value = false;
formData.value = {
channelShopId: props.presetChannelShopId ?? undefined,
goodsId: undefined,
feeDate: undefined,
feeAmount: undefined,
};
void loadGoodsOptions(props.presetChannelShopId ?? undefined);
modalApi.setState({ title: '新增商品广告费' });
}
}
watch(
() => props.open,
async (open) => {
if (open) {
modalApi.open();
await loadShops();
await nextTick();
fillForm();
} else {
modalApi.close();
}
},
);
watch(
() => formData.value.channelShopId,
(shopId, prev) => {
if (shopId === prev) return;
if (!isEdit.value) {
formData.value.goodsId = undefined;
}
void loadGoodsOptions(shopId);
},
);
function handleCancel() {
emit('cancel');
emit('update:open', false);
modalApi.close();
}
async function handleOk() {
try {
await formRef.value?.validate();
} catch {
return;
}
const payload: PddGoodsAdFeeDTO.Create = {
channelShopId: formData.value.channelShopId!,
goodsId: String(formData.value.goodsId).trim(),
feeDate: formData.value.feeDate!.format('YYYY-MM-DD'),
feeAmount: Number(formData.value.feeAmount),
};
modalApi.setState({ confirmLoading: true });
try {
if (isEdit.value && props.adFeeData?.id) {
await updatePddGoodsAdFeeApi(props.adFeeData.id, payload);
message.success('更新成功');
} else {
await createPddGoodsAdFeeApi(payload);
message.success('创建成功');
}
emit('success');
emit('update:open', false);
modalApi.close();
} catch (error: any) {
message.error(error?.message || '保存失败');
} finally {
modalApi.setState({ confirmLoading: false });
}
}
</script>
<template>
<Modal>
<Form
ref="formRef"
:model="formData"
:rules="rules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 16 }"
class="py-2"
>
<Form.Item label="渠道店铺" name="channelShopId">
<Select
v-model:value="formData.channelShopId"
show-search
allow-clear
:options="shopOptions"
:loading="shopLoading"
option-filter-prop="label"
placeholder="请选择渠道店铺"
/>
</Form.Item>
<Form.Item label="商品" name="goodsId">
<Select
v-model:value="formData.goodsId"
show-search
allow-clear
:options="goodsOptions"
:loading="goodsLoading"
option-filter-prop="label"
placeholder="请先选店铺,再选商品"
:disabled="!formData.channelShopId"
/>
</Form.Item>
<Form.Item label="统计日期" name="feeDate">
<DatePicker
v-model:value="formData.feeDate"
class="w-full"
value-format=""
placeholder="选择日期"
/>
</Form.Item>
<Form.Item label="广告费金额" name="feeAmount">
<InputNumber
v-model:value="formData.feeAmount"
class="w-full"
:min="0"
:precision="2"
placeholder="元"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -0,0 +1,240 @@
<script setup lang="ts">
import type { PddShopVO } from '#/api/channel/pdd/shop';
import { computed, onMounted, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Card,
Empty,
Input,
message,
Spin,
} from 'ant-design-vue';
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
defineOptions({ name: 'PddShopSidebarList' });
const props = withDefaults(
defineProps<{
selectedShopId?: number;
showAddAction?: boolean;
}>(),
{
selectedShopId: undefined,
showAddAction: true,
},
);
const emit = defineEmits<{
'update:selectedShopId': [id: number | undefined];
select: [shop: PddShopVO.Info | null];
addForShop: [shopId: number];
}>();
const StoreIcon = createIconifyIcon('lucide:store');
const PlusIcon = createIconifyIcon('lucide:plus');
const shopSearchName = ref('');
const shops = ref<PddShopVO.Info[]>([]);
const shopsLoading = ref(false);
const shopPagination = ref({ current: 1, pageSize: 20, total: 0 });
const shopTotalPages = computed(() => {
const { total, pageSize } = shopPagination.value;
return Math.max(1, Math.ceil(total / pageSize) || 1);
});
const allSelected = computed(() => props.selectedShopId === undefined);
async function searchShops(resetPage = false) {
if (resetPage) {
shopPagination.value.current = 1;
}
shopsLoading.value = true;
try {
const result = await getPddShopPageApi({
page: shopPagination.value.current,
pageSize: shopPagination.value.pageSize,
filters: {
mallName: shopSearchName.value || undefined,
},
});
shops.value = result.records ?? [];
shopPagination.value.total = result.total ?? 0;
} catch (error: any) {
message.error(error?.message || '获取渠道店铺列表失败');
shops.value = [];
} finally {
shopsLoading.value = false;
}
}
function resetShopSearch() {
shopSearchName.value = '';
void searchShops(true);
}
function goShopPage(page: number) {
const next = Math.min(shopTotalPages.value, Math.max(1, page));
if (next === shopPagination.value.current) return;
shopPagination.value.current = next;
void searchShops();
}
function selectAll() {
emit('update:selectedShopId', undefined);
emit('select', null);
}
function selectShop(shop: PddShopVO.Info) {
emit('update:selectedShopId', shop.id);
emit('select', shop);
}
function handleAdd(shopId: number) {
const shop = shops.value.find((s) => s.id === shopId) ?? null;
emit('update:selectedShopId', shopId);
if (shop) {
emit('select', shop);
}
emit('addForShop', shopId);
}
onMounted(() => {
void searchShops();
});
</script>
<template>
<Card
class="flex h-full w-[320px] shrink-0 flex-col overflow-hidden"
:body-style="{
height: '100%',
display: 'flex',
flexDirection: 'column',
gap: '8px',
minHeight: 0,
minWidth: 0,
overflow: 'hidden',
padding: '12px',
}"
>
<template #title>
<span class="flex items-center gap-2 text-base font-semibold">
<StoreIcon class="h-4 w-4" />
渠道店铺
</span>
</template>
<div class="flex min-w-0 shrink-0 items-center gap-2">
<Input
v-model:value="shopSearchName"
placeholder="店铺名称"
allow-clear
class="min-w-0 flex-1"
@press-enter="searchShops(true)"
/>
<Button type="primary" class="shrink-0" @click="searchShops(true)">
搜索
</Button>
<Button class="shrink-0" @click="resetShopSearch">重置</Button>
</div>
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
<div class="min-h-0 flex-1 overflow-y-auto">
<Card
size="small"
:body-style="{ padding: '10px 12px' }"
class="mb-2 cursor-pointer !shadow-none hover:border-primary"
:class="allSelected ? 'border-primary bg-primary/5' : undefined"
@click="selectAll"
>
<div class="flex items-center justify-between gap-2">
<span class="min-w-0 truncate text-sm font-medium">全部店铺</span>
<span class="shrink-0 text-xs text-muted-foreground">全部记录</span>
</div>
</Card>
<Spin :spinning="shopsLoading">
<Empty
v-if="!shopsLoading && shops.length === 0"
class="py-8"
description="暂无渠道店铺"
/>
<template v-else>
<Card
v-for="shop in shops"
:key="shop.id"
size="small"
:body-style="{ padding: '10px 12px' }"
class="group mb-2 cursor-pointer !shadow-none last:mb-0 hover:border-primary"
:class="
selectedShopId === shop.id
? 'border-primary bg-primary/5'
: undefined
"
@click="selectShop(shop)"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0 flex-1">
<div class="truncate text-sm font-medium">
{{ shop.mallName || `店铺 #${shop.id}` }}
</div>
<div
v-if="shop.mallId != null"
class="mt-1 text-xs text-muted-foreground"
>
mall_id: {{ shop.mallId }}
</div>
</div>
<Button
v-if="showAddAction"
type="link"
size="small"
class="!h-7 shrink-0 !px-1 !text-xs opacity-80 group-hover:opacity-100"
@click.stop="handleAdd(shop.id)"
>
<PlusIcon class="mr-0.5 inline h-3.5 w-3.5" />
添加
</Button>
</div>
</Card>
</template>
</Spin>
</div>
<div
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
>
<Button
size="small"
class="shrink-0"
:disabled="shopPagination.current <= 1 || shopsLoading"
@click="goShopPage(shopPagination.current - 1)"
>
上一页
</Button>
<span
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
>
{{ shopPagination.current }} / {{ shopTotalPages }}
<span class="ml-1 opacity-70">({{ shopPagination.total }})</span>
</span>
<Button
size="small"
class="shrink-0"
:disabled="
shopPagination.current >= shopTotalPages || shopsLoading
"
@click="goShopPage(shopPagination.current + 1)"
>
下一页
</Button>
</div>
</div>
</Card>
</template>
@@ -0,0 +1,358 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PddGoodsAdFeeVO } from '#/api/channel/pdd/goods-ad-fee';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Card,
DatePicker,
Flex,
Input,
message,
Popconfirm,
Space,
} from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePddGoodsAdFeeApi,
getPddGoodsAdFeePageApi,
} from '#/api/channel/pdd/goods-ad-fee';
import GoodsAdFeeFormModal from './components/GoodsAdFeeFormModal.vue';
import PddShopSidebarList from './components/PddShopSidebarList.vue';
defineOptions({ name: 'PddGoodsAdFeeManagement' });
const PlusIcon = createIconifyIcon('lucide:plus');
const loading = ref(false);
const selectedShopId = ref<number | undefined>(undefined);
const selectedShopName = ref<string | undefined>(undefined);
const formModalVisible = ref(false);
const currentAdFeeData = ref<null | PddGoodsAdFeeVO.Info>(null);
const presetChannelShopId = ref<number | null>(null);
const searchForm = ref({
goodsId: undefined as string | undefined,
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
const selectedShopLabel = computed(() => {
if (selectedShopId.value == null) {
return '全部店铺';
}
return selectedShopName.value || `店铺 #${selectedShopId.value}`;
});
function onShopSelect(shop: { id: number; mallName?: string } | null) {
if (!shop) {
selectedShopId.value = undefined;
selectedShopName.value = undefined;
return;
}
selectedShopId.value = shop.id;
selectedShopName.value = shop.mallName;
}
function handleAddForShop(shopId: number) {
currentAdFeeData.value = null;
presetChannelShopId.value = shopId;
formModalVisible.value = true;
}
const gridOptions: VxeGridProps<PddGoodsAdFeeVO.Info> = {
columns: [
{
type: 'seq' as const,
minWidth: 56,
title: '序号',
},
{
field: 'channelShopName',
title: '渠道店铺',
minWidth: 140,
showOverflow: 'tooltip' as const,
},
{
field: 'goodsName',
title: '商品',
minWidth: 180,
showOverflow: 'tooltip' as const,
slots: { default: 'goods' },
},
{
title: '广告费金额',
minWidth: 110,
slots: { default: 'feeAmount' },
},
{
field: 'feeDate',
title: '统计日期',
minWidth: 110,
},
{
field: 'lastSyncTime',
title: '最近同步',
minWidth: 160,
},
{
title: '操作',
minWidth: 140,
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: '100%',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<{
channelShopId?: number;
goodsId?: string;
feeDateStart?: string;
feeDateEnd?: string;
}> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
channelShopId: selectedShopId.value,
goodsId: searchForm.value.goodsId || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
},
};
const data = await getPddGoodsAdFeePageApi(params);
return { items: data.records, total: data.total };
} catch {
message.error('获取商品广告费列表失败');
return { items: [], total: 0 };
} finally {
loading.value = false;
}
},
},
},
};
function refreshTable() {
gridApi?.reload();
}
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
tableTitle: '广告费记录',
});
watch(selectedShopId, () => {
gridApi.reload();
});
function resetModalPreset() {
presetChannelShopId.value = null;
}
function handleAdd() {
currentAdFeeData.value = null;
resetModalPreset();
formModalVisible.value = true;
}
function handleEdit(record: PddGoodsAdFeeVO.Info) {
resetModalPreset();
currentAdFeeData.value = record;
formModalVisible.value = true;
}
async function handleDelete(id: number) {
try {
await deletePddGoodsAdFeeApi(id);
message.success('删除成功');
refreshTable();
} catch {
message.error('删除失败');
}
}
function handleFormSuccess() {
resetModalPreset();
refreshTable();
}
function handleFormCancel() {
resetModalPreset();
formModalVisible.value = false;
}
const formatAmount = (amount: number) => `¥${Number(amount || 0).toFixed(2)}`;
</script>
<template>
<Page title="商品广告费" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
左侧选择拼多多渠道店铺筛选右侧按日广告费;未选店铺时展示全部记录。可在店铺行快捷新增。
</div>
</template>
<template #extra>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增广告费
</Button>
</Space>
</template>
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
<PddShopSidebarList
:selected-shop-id="selectedShopId"
@select="onShopSelect"
@add-for-shop="handleAddForShop"
/>
<Card
class="flex h-full min-h-0 min-w-0 flex-1 flex-col"
:body-style="{
height: '100%',
minHeight: 0,
padding: 0,
display: 'flex',
flexDirection: 'column',
}"
>
<template #title>
<span class="text-base font-semibold">广告费记录</span>
</template>
<template #extra>
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
<Input
v-model:value="searchForm.goodsId"
allow-clear
placeholder="goods_id"
class="w-[140px]"
@press-enter="() => refreshTable()"
@change="() => refreshTable()"
/>
<DatePicker
v-model:value="searchForm.feeDateStart"
value-format="YYYY-MM-DD"
placeholder="开始"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
<span class="text-muted-foreground">—</span>
<DatePicker
v-model:value="searchForm.feeDateEnd"
value-format="YYYY-MM-DD"
placeholder="结束"
class="w-[118px]"
allow-clear
@change="() => refreshTable()"
/>
</Space>
</template>
<div
class="shrink-0 border-t border-border px-4 py-2 text-xs text-muted-foreground"
>
当前:{{ selectedShopLabel }}
</div>
<div
class="min-h-0 flex-1 overflow-hidden px-2 pb-2 pt-0 sm:px-3 sm:pb-3"
>
<Grid :loading="loading" class="h-full min-h-0">
<template #toolbar-tools>
<span class="text-xs text-muted-foreground">
使用上方 goods_id 与日期筛选
</span>
</template>
<template #feeAmount="{ row }">
<span class="font-semibold text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<template #goods="{ row }">
<div>
<div>{{ row.goodsName || '—' }}</div>
<div class="text-xs text-muted-foreground">
{{ row.goodsId }}
</div>
</div>
</template>
<template #action="{ row }">
<Space>
<Button size="small" @click="handleEdit(row)">编辑</Button>
<Popconfirm
title="确定要删除这条广告费记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
</Card>
</Flex>
<GoodsAdFeeFormModal
v-model:open="formModalVisible"
:ad-fee-data="currentAdFeeData"
:preset-channel-shop-id="presetChannelShopId"
@success="handleFormSuccess"
@cancel="handleFormCancel"
/>
</Page>
</template>