feat: 联动支付 CRM 后台(Next.js + TS + Prisma 重构)
从旧 Laravel 5.7 重构为现代技术栈,对接现有 MySQL。 - 技术栈: Next.js 15 App Router + TypeScript + Prisma + Auth.js + Tailwind v4 - 认证: 复用旧库 admins 的 bcrypt 密码,Auth.js Credentials - 客户管理: 列表(搜索/报单区间/分页)、增改删、Excel 导入导出 - 生日提醒: 阴阳历(lunar-typescript),口径对齐旧 overtrue 库 - RBAC: 管理员/角色/权限(菜单树) 完整 CRUD + 分配 - 控制台: 统计卡 + 月度新增报单柱状图 - 个人中心: 改昵称/改密码 - 现代 CMS 界面 + 联动支付品牌(logo/登录/底部/icon) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { birthdayMatchLists } from "@/lib/lunar";
|
||||
import { fmtDate } from "@/lib/utils";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { BirthdayControl } from "./birthday-control";
|
||||
|
||||
type Row = {
|
||||
id: number;
|
||||
customerName: string | null;
|
||||
contacts: string | null;
|
||||
phone: string | null;
|
||||
salesman: string | null;
|
||||
reportDate: Date | null;
|
||||
birthday: Date | null;
|
||||
birthdayType: number | null;
|
||||
remark: string | null;
|
||||
};
|
||||
|
||||
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<Row[]>(Prisma.sql`
|
||||
SELECT
|
||||
id,
|
||||
customer_name AS customerName,
|
||||
contacts,
|
||||
phone,
|
||||
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-wrap items-center justify-between gap-3 p-3">
|
||||
<BirthdayControl mode={mode} date={dateStr} />
|
||||
<div className="pr-1 text-sm text-[var(--color-muted-foreground)]">
|
||||
命中 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位客户
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>客户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>电话</TH>
|
||||
<TH>业务员</TH>
|
||||
<TH>生日</TH>
|
||||
<TH>历法</TH>
|
||||
</tr>
|
||||
</THead>
|
||||
<tbody>
|
||||
{rows.length === 0 && (
|
||||
<tr>
|
||||
<TD colSpan={6} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||
该时段暂无生日客户
|
||||
</TD>
|
||||
</tr>
|
||||
)}
|
||||
{rows.map((c) => (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD className="tabular-nums">{c.phone}</TD>
|
||||
<TD>{c.salesman}</TD>
|
||||
<TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
|
||||
<TD>
|
||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"}>
|
||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
||||
</Badge>
|
||||
</TD>
|
||||
</TR>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user