生日提醒用于联系商户,不再按角色脱敏;商户管理列表权限保持不变。 Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import { Prisma } from "@prisma/client";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { birthdayMatchLists } from "@/lib/lunar";
|
|
import { Card } from "@/components/ui/card";
|
|
import { BirthdayControl } from "./birthday-control";
|
|
import { BirthdayList, type BirthdayRow } from "./birthday-list";
|
|
|
|
function baseDate(s?: string): Date {
|
|
if (s) {
|
|
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
if (m) return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
}
|
|
return new Date();
|
|
}
|
|
|
|
export default async function BirthdayPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ mode?: string; date?: string }>;
|
|
}) {
|
|
const sp = await searchParams;
|
|
const mode = sp.mode === "week" ? "week" : "today";
|
|
const dateStr = sp.date ?? "";
|
|
const base = baseDate(sp.date);
|
|
|
|
const { solar, lunar } =
|
|
mode === "week"
|
|
? birthdayMatchLists(base, 7, false)
|
|
: birthdayMatchLists(base, 1, true);
|
|
|
|
const rows = await prisma.$queryRaw<BirthdayRow[]>(Prisma.sql`
|
|
SELECT
|
|
id,
|
|
customer_name AS customerName,
|
|
customer_no AS customerNo,
|
|
contacts,
|
|
contacts_phone AS contactsPhone,
|
|
balance_user AS balanceUser,
|
|
COALESCE(NULLIF(balance_user_phone, ''), phone) AS balanceUserPhone,
|
|
detail,
|
|
deposit,
|
|
buy,
|
|
salesman,
|
|
report_date AS reportDate,
|
|
birthday,
|
|
birthday_type AS birthdayType,
|
|
remark
|
|
FROM customers
|
|
WHERE deleted_at IS NULL AND (
|
|
(birthday_type = 1 AND DATE_FORMAT(birthday, '%m-%d') IN (${Prisma.join(solar)}))
|
|
OR
|
|
(birthday_type = 2 AND DATE_FORMAT(birthday, '%m-%d') IN (${Prisma.join(lunar)}))
|
|
)
|
|
ORDER BY DATE_FORMAT(birthday, '%m-%d')
|
|
`);
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
<Card className="flex flex-col gap-3 p-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between">
|
|
<BirthdayControl mode={mode} date={dateStr} />
|
|
<div className="text-sm text-[var(--color-muted-foreground)] sm:pr-1">
|
|
共 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位商户过生日
|
|
</div>
|
|
</Card>
|
|
|
|
<BirthdayList rows={rows} />
|
|
</div>
|
|
);
|
|
}
|