Files
gao-customer-h5/src/api/StoreChartAPI.ts
T
2026-09-11 18:47:14 +08:00

65 lines
3.0 KiB
TypeScript

import { axios } from "timi-web-api";
import EventAPI from "@/api/EventAPI";
import StoreAPI from "@/api/StoreAPI";
import type { CustomerAgeStatView, CustomerDailyStatView, CustomerGenderStatView } from "@/types/Customer";
import type { EventItem } from "@/types/EventItem";
import type { StoreBusinessDay, StoreChartReq, StoreEventRecordCalendarView, StoreEventRecordDailyStatView, StoreEventRecordNumberValueDailyStatView } from "@/types/Store";
import { getStoreChartCache } from "@/utils/storeChartCache";
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
const BASE_URI = "/gao/store/chart";
async function customerDailyStat(req: StoreChartReq): Promise<CustomerDailyStatView[]> {
const request = withCurrentStoreId(req);
return await getStoreChartCache(`customer-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/customer/daily`, request));
}
async function customerGenderStat(): Promise<CustomerGenderStatView[]> {
const storeId = getCurrentStoreId();
return await getStoreChartCache(`customer-gender:${storeId}`, async () => await axios.post(`${BASE_URI}/customer/gender`, undefined, {
params: { storeId }
}));
}
async function customerAgeStat(): Promise<CustomerAgeStatView[]> {
const storeId = getCurrentStoreId();
return await getStoreChartCache(`customer-age:${storeId}`, async () => await axios.post(`${BASE_URI}/customer/age`, undefined, {
params: { storeId }
}));
}
async function eventRecordDailyStat(req: StoreChartReq): Promise<StoreEventRecordDailyStatView[]> {
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/daily`, request));
}
async function eventRecordNumberValueDailyStat(req: StoreChartReq): Promise<StoreEventRecordNumberValueDailyStatView[]> {
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-number-value-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/number-value/daily`, request));
}
async function eventRecordCalendar(req: StoreChartReq): Promise<StoreEventRecordCalendarView[]> {
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-calendar:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/calendar`, request));
}
async function listValidEvents(): Promise<EventItem[]> {
const storeId = getCurrentStoreId();
return await getStoreChartCache(`valid-events:${storeId}`, async () => await EventAPI.listValid());
}
async function businessDayCalendar(storeId: string, beginDateValue: number, endDateValue: number): Promise<StoreBusinessDay[]> {
return await getStoreChartCache(`business-day-calendar:${storeId}:${beginDateValue}:${endDateValue}`, async () => await StoreAPI.businessDayCalendar(storeId, beginDateValue, endDateValue));
}
export default {
customerDailyStat,
customerGenderStat,
customerAgeStat,
eventRecordDailyStat,
eventRecordNumberValueDailyStat,
eventRecordCalendar,
listValidEvents,
businessDayCalendar
};