mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 09:14:11 +05:30
release: prepare J-Board Lite 3.1.1
This commit is contained in:
@@ -5,6 +5,7 @@ import { requireAdmin } from "@/lib/require-auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { confirmPendingOrder } from "@/services/payment/process";
|
||||
import { actorFromSession, recordAuditLog } from "@/services/audit";
|
||||
import { orderReviewStatusLabels } from "@/lib/domain-labels";
|
||||
|
||||
export async function confirmOrder(orderId: string) {
|
||||
const session = await requireAdmin();
|
||||
@@ -66,7 +67,7 @@ export async function updateOrderReview(
|
||||
targetType: "Order",
|
||||
targetId: order.id,
|
||||
targetLabel: order.id,
|
||||
message: `将订单 ${order.id} 标记为 ${reviewStatus}`,
|
||||
message: `将订单 ${order.id} 标记为${orderReviewStatusLabels[reviewStatus]}`,
|
||||
});
|
||||
|
||||
revalidatePath("/admin/orders");
|
||||
|
||||
@@ -11,8 +11,19 @@ import {
|
||||
preparePaymentConfigForStorage,
|
||||
} from "@/services/payment/catalog";
|
||||
import { actorFromSession, recordAuditLog } from "@/services/audit";
|
||||
import { getErrorMessage } from "@/lib/errors";
|
||||
import { z } from "zod";
|
||||
|
||||
type PaymentActionResult = { ok: true } | { ok: false; error: string };
|
||||
|
||||
function formatPaymentConfigError(error: unknown, fallback: string) {
|
||||
if (error instanceof z.ZodError) {
|
||||
const details = error.issues.map((issue) => issue.message).filter(Boolean).join(";");
|
||||
return details || getErrorMessage(error, fallback);
|
||||
}
|
||||
return getErrorMessage(error, fallback);
|
||||
}
|
||||
|
||||
export async function savePaymentConfig(
|
||||
provider: string,
|
||||
config: Record<string, string>,
|
||||
@@ -60,3 +71,56 @@ export async function savePaymentConfig(
|
||||
});
|
||||
revalidatePath("/admin/payments");
|
||||
}
|
||||
|
||||
export async function setPaymentConfigEnabled(
|
||||
provider: string,
|
||||
enabled: boolean,
|
||||
): Promise<PaymentActionResult> {
|
||||
try {
|
||||
const session = await requireAdmin();
|
||||
const current = await prisma.paymentConfig.findUnique({
|
||||
where: { provider },
|
||||
select: { config: true, enabled: true },
|
||||
});
|
||||
|
||||
if (!current) {
|
||||
if (!enabled) return { ok: true };
|
||||
throw new Error("请先编辑并保存完整支付配置,再启用该支付方式");
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
try {
|
||||
parsePaymentConfig(
|
||||
provider,
|
||||
decryptPaymentConfigForUse(provider, current.config as Record<string, unknown>),
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
throw new Error("请先编辑并保存完整支付配置,再启用该支付方式");
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (current.enabled !== enabled) {
|
||||
await prisma.paymentConfig.update({
|
||||
where: { provider },
|
||||
data: { enabled },
|
||||
});
|
||||
|
||||
await recordAuditLog({
|
||||
actor: actorFromSession(session),
|
||||
action: "payment.toggle",
|
||||
targetType: "PaymentConfig",
|
||||
targetId: provider,
|
||||
targetLabel: getPaymentProviderName(provider),
|
||||
message: `${enabled ? "启用" : "停用"}支付方式 ${getPaymentProviderName(provider)}`,
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath("/admin/payments");
|
||||
return { ok: true };
|
||||
} catch (error) {
|
||||
return { ok: false, error: formatPaymentConfigError(error, "更新支付开关失败") };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user