feat(payment): sync plans and add coins rules
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
PaymentVipStatusResponse,
|
||||
} from "@/data/dto/payment";
|
||||
import { PaymentApi, paymentApi } from "@/data/services/api";
|
||||
import { PaymentPlansStorage } from "@/data/storage/payment";
|
||||
import type { IPaymentRepository } from "@/data/repositories/interfaces";
|
||||
import { Result } from "@/utils/result";
|
||||
|
||||
@@ -23,7 +24,20 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
|
||||
/** 获取套餐列表。 */
|
||||
async getPlans(): Promise<Result<PaymentPlansResponse>> {
|
||||
return Result.wrap(() => this.api.getPlans());
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.getPlans();
|
||||
await PaymentPlansStorage.setPlans(response.toJson());
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取本地缓存套餐列表。 */
|
||||
async getCachedPlans(): Promise<Result<PaymentPlansResponse | null>> {
|
||||
return Result.wrap(async () => {
|
||||
const result = await PaymentPlansStorage.getPlans();
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
return result.data ? PaymentPlansResponse.from(result.data) : null;
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取会员套餐列表。 */
|
||||
@@ -73,21 +87,9 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
export const paymentRepository = new PaymentRepository(paymentApi);
|
||||
|
||||
export function isVipPaymentPlan(plan: PaymentPlan): boolean {
|
||||
const orderType = plan.orderType.toLowerCase();
|
||||
const planId = plan.planId.toLowerCase();
|
||||
return orderType.startsWith("vip_") || planId.startsWith("vip_");
|
||||
return plan.vipDays !== null;
|
||||
}
|
||||
|
||||
export function isCreditPaymentPlan(plan: PaymentPlan): boolean {
|
||||
const orderType = plan.orderType.toLowerCase();
|
||||
const planId = plan.planId.toLowerCase();
|
||||
return (
|
||||
plan.dolAmount !== null ||
|
||||
orderType.startsWith("dol_") ||
|
||||
orderType.startsWith("credit_") ||
|
||||
planId.startsWith("dol_") ||
|
||||
planId.startsWith("credit_") ||
|
||||
orderType.includes("credit") ||
|
||||
planId.includes("credit")
|
||||
);
|
||||
return plan.dolAmount !== null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user