add point
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import { axios, type Page, type PageResult } from "timi-web";
|
||||
import type {
|
||||
PointAccount,
|
||||
PointAdjustRequest,
|
||||
PointLedger,
|
||||
PointLedgerPage,
|
||||
PointRule
|
||||
} from "@/types/Point";
|
||||
import { getCurrentStoreId, withCurrentStoreId, withCurrentStorePage } from "@/utils/store";
|
||||
|
||||
const BASE_URI = "/gao/customer/point";
|
||||
|
||||
type ListOptions = {
|
||||
allStores?: boolean;
|
||||
storeId?: string;
|
||||
};
|
||||
|
||||
/** 查询指定客户的积分账户。账户不存在表示客户尚未产生过积分流水。 */
|
||||
async function accountDetail(customerId: string, storeId?: string): Promise<PointAccount> {
|
||||
return await axios.post(`${BASE_URI}/account/detail`, undefined, {
|
||||
params: {
|
||||
customerId,
|
||||
storeId: storeId || getCurrentStoreId() || undefined
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 分页查询积分流水。全局管理员不传门店时允许查询全部门店。 */
|
||||
async function ledgerList(page: PointLedgerPage, options?: ListOptions): Promise<PageResult<PointLedger>> {
|
||||
if (options?.allStores) {
|
||||
return await axios.post(`${BASE_URI}/ledger/list`, page);
|
||||
}
|
||||
|
||||
if (options?.storeId) {
|
||||
return await axios.post(`${BASE_URI}/ledger/list`, {
|
||||
...page,
|
||||
storeId: options.storeId
|
||||
});
|
||||
}
|
||||
|
||||
return await axios.post(`${BASE_URI}/ledger/list`, withCurrentStoreId(page));
|
||||
}
|
||||
|
||||
/** 人工调整积分,后端使用 adjustRequestId 保证幂等。 */
|
||||
async function adjust(request: PointAdjustRequest): Promise<void> {
|
||||
await axios.post(`${BASE_URI}/adjust`, withCurrentStoreId(request));
|
||||
}
|
||||
|
||||
async function ruleList(page: Page<PointRule>, options?: ListOptions): Promise<PageResult<PointRule>> {
|
||||
if (options?.allStores) {
|
||||
return await axios.post(`${BASE_URI}/rule/list`, page);
|
||||
}
|
||||
|
||||
if (options?.storeId) {
|
||||
return await axios.post(`${BASE_URI}/rule/list`, {
|
||||
...page,
|
||||
equalsExample: {
|
||||
...(page.equalsExample || {}),
|
||||
storeId: options.storeId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return await axios.post(`${BASE_URI}/rule/list`, withCurrentStorePage(page));
|
||||
}
|
||||
|
||||
async function ruleDetail(id: string): Promise<PointRule> {
|
||||
return await axios.post(`${BASE_URI}/rule/detail`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
async function ruleCreate(rule: PointRule): Promise<string> {
|
||||
return await axios.post(`${BASE_URI}/rule/create`, withCurrentStoreId(rule));
|
||||
}
|
||||
|
||||
async function ruleUpdate(rule: PointRule): Promise<void> {
|
||||
await axios.post(`${BASE_URI}/rule/update`, withCurrentStoreId(rule));
|
||||
}
|
||||
|
||||
async function ruleRemove(id: string): Promise<void> {
|
||||
await axios.post(`${BASE_URI}/rule/delete`, undefined, {
|
||||
params: { id }
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
accountDetail,
|
||||
ledgerList,
|
||||
adjust,
|
||||
ruleList,
|
||||
ruleDetail,
|
||||
ruleCreate,
|
||||
ruleUpdate,
|
||||
ruleRemove
|
||||
};
|
||||
Reference in New Issue
Block a user