提交
This commit is contained in:
@@ -20,7 +20,7 @@ const db = {
|
||||
// 获取代理列表和统计信息
|
||||
router.get('/', authenticateAdmin, async (req, res) => {
|
||||
try {
|
||||
const { page = 1, limit = 20, status, city, search } = req.query;
|
||||
const { page = 1, limit = 20, status, city, search,district } = req.query;
|
||||
const pageNum = parseInt(page) || 1;
|
||||
const limitNum = parseInt(limit) || 20;
|
||||
const offset = (pageNum - 1) * limitNum;
|
||||
@@ -34,13 +34,13 @@ router.get('/', authenticateAdmin, async (req, res) => {
|
||||
queryParams.push(status);
|
||||
}
|
||||
|
||||
if (city) {
|
||||
whereConditions.push('zr.city_name = ?');
|
||||
queryParams.push(city);
|
||||
if (district) {
|
||||
whereConditions.push('zr.name = ?');
|
||||
queryParams.push(district);
|
||||
}
|
||||
|
||||
if (search) {
|
||||
whereConditions.push('(ra.real_name LIKE ? OR ra.phone LIKE ?)');
|
||||
whereConditions.push('(u.real_name LIKE ? OR u.phone LIKE ?)');
|
||||
queryParams.push(`%${search}%`, `%${search}%`);
|
||||
}
|
||||
|
||||
@@ -48,37 +48,33 @@ router.get('/', authenticateAdmin, async (req, res) => {
|
||||
|
||||
// 查询代理列表
|
||||
const agentsQuery = `
|
||||
SELECT
|
||||
ra.*,
|
||||
u.real_name,
|
||||
u.phone,
|
||||
u.id_card,
|
||||
zr.city_name,
|
||||
zr.district_name,
|
||||
(
|
||||
SELECT COUNT(DISTINCT merchant_id)
|
||||
FROM agent_merchants
|
||||
WHERE agent_id = ra.id
|
||||
) as merchant_count,
|
||||
(
|
||||
SELECT CAST(COALESCE(SUM(commission_amount), 0) AS DECIMAL(10,2))
|
||||
FROM agent_commission_records
|
||||
WHERE agent_id = ra.id
|
||||
) as total_commission,
|
||||
0 as paid_commission,
|
||||
(
|
||||
SELECT CAST(COALESCE(SUM(commission_amount), 0) AS DECIMAL(10,2))
|
||||
FROM agent_commission_records
|
||||
WHERE agent_id = ra.id
|
||||
) as pending_commission
|
||||
FROM regional_agents ra
|
||||
LEFT JOIN users u ON ra.user_id = u.id
|
||||
LEFT JOIN zhejiang_regions zr ON ra.region_id = zr.id
|
||||
${whereClause}
|
||||
ORDER BY ra.created_at DESC
|
||||
LIMIT ${limitNum} OFFSET ${offset}
|
||||
`;
|
||||
|
||||
SELECT ra.*,
|
||||
u.real_name,
|
||||
u.phone,
|
||||
u.id_card,
|
||||
province.name AS province_name,
|
||||
city.name AS city_name,
|
||||
zr.name AS district_name,
|
||||
(SELECT COUNT(DISTINCT merchant_id)
|
||||
FROM agent_merchants
|
||||
WHERE agent_id = ra.id) as merchant_count,
|
||||
(SELECT CAST(COALESCE(SUM(commission_amount), 0) AS DECIMAL(10, 2))
|
||||
FROM agent_commission_records
|
||||
WHERE agent_id = ra.id) as total_commission,
|
||||
0 as paid_commission,
|
||||
(SELECT CAST(COALESCE(SUM(commission_amount), 0) AS DECIMAL(10, 2))
|
||||
FROM agent_commission_records
|
||||
WHERE agent_id = ra.id) as pending_commission
|
||||
FROM regional_agents ra
|
||||
LEFT JOIN users u ON ra.user_id = u.id
|
||||
LEFT JOIN china_regions zr ON ra.region_id = zr.code -- 区
|
||||
LEFT JOIN china_regions city ON zr.parent_code = city.code -- 市
|
||||
LEFT JOIN china_regions province ON city.parent_code = province.code -- 省
|
||||
${whereClause}
|
||||
ORDER BY ra.created_at
|
||||
DESC
|
||||
LIMIT ${limitNum} OFFSET ${offset};`;
|
||||
console.log(agentsQuery,queryParams)
|
||||
const agents = await db.query(agentsQuery, queryParams);
|
||||
|
||||
// 查询总数
|
||||
@@ -86,7 +82,7 @@ router.get('/', authenticateAdmin, async (req, res) => {
|
||||
SELECT COUNT(DISTINCT ra.id) as total
|
||||
FROM regional_agents ra
|
||||
LEFT JOIN users u ON ra.user_id = u.id
|
||||
LEFT JOIN zhejiang_regions zr ON ra.region_id = zr.id
|
||||
LEFT JOIN china_regions zr ON ra.region_id = zr.code
|
||||
${whereClause}
|
||||
`;
|
||||
|
||||
@@ -377,7 +373,6 @@ router.get('/:id/merchants', authenticateAdmin, async (req, res) => {
|
||||
if (!agentResult || agentResult.length === 0) {
|
||||
return res.status(404).json({ success: false, message: '代理不存在' });
|
||||
}
|
||||
const agent = agentResult[0];
|
||||
|
||||
// 查询代理的商户列表
|
||||
const merchantsQuery = `
|
||||
|
||||
Reference in New Issue
Block a user