diff --git a/src/controller/admin/patient.js b/src/controller/admin/patient.js index 17090d3..0d96aca 100644 --- a/src/controller/admin/patient.js +++ b/src/controller/admin/patient.js @@ -54,7 +54,7 @@ module.exports = class extends Base { item.region_name = [pName, cName, dName].filter(Boolean).join(' '); }); - const counts = await model.getStatusCounts(); + const counts = await model.getStatusCounts({ keyword, tag, startDate, endDate, province_code, city_code, district_code }); return this.success({ ...list, counts }); } diff --git a/src/model/patient.js b/src/model/patient.js index 1e2f06c..c8853d7 100644 --- a/src/model/patient.js +++ b/src/model/patient.js @@ -147,17 +147,17 @@ module.exports = class extends think.Model { } /** - * 获取各状态数量(单次查询) + * 获取各状态数量(支持筛选条件,排除 status) */ - async getStatusCounts() { - const sql = `SELECT - COUNT(*) AS \`all\`, - SUM(status = -1) AS draft, - SUM(status = 0) AS pending, - SUM(status = 1) AS approved, - SUM(status = 2) AS rejected - FROM patient WHERE is_deleted = 0`; - const rows = await this.query(sql); + async getStatusCounts(filters = {}) { + // 复用 _buildWhere,但排除 status + const { status, ...rest } = filters; + const where = this._buildWhere(rest); + // 删掉 status 条件(_buildWhere 不会加,但保险起见) + delete where.status; + const rows = await this.where(where) + .field('COUNT(*) AS `all`, SUM(status = -1) AS draft, SUM(status = 0) AS pending, SUM(status = 1) AS approved, SUM(status = 2) AS rejected') + .select(); const row = rows[0] || {}; return { all: parseInt(row.all, 10) || 0, diff --git a/view/admin/patient_index.html b/view/admin/patient_index.html index 7b9e6cf..8c10272 100644 --- a/view/admin/patient_index.html +++ b/view/admin/patient_index.html @@ -98,10 +98,12 @@