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 { 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 { const storeId = getCurrentStoreId(); return await getStoreChartCache(`customer-gender:${storeId}`, async () => await axios.post(`${BASE_URI}/customer/gender`, undefined, { params: { storeId } })); } async function customerAgeStat(): Promise { 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 { 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 { 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 { 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 { const storeId = getCurrentStoreId(); return await getStoreChartCache(`valid-events:${storeId}`, async () => await EventAPI.listValid()); } async function businessDayCalendar(storeId: string, beginDateValue: number, endDateValue: number): Promise { 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 };