This commit is contained in:
Your Name
2026-04-30 14:04:12 +08:00
parent eb782305e6
commit d3003ce0ac
19 changed files with 1560 additions and 313 deletions
@@ -14,7 +14,7 @@ use think\facade\Db;
* · 与 qywx.customer/todayArrival、客户列表同源事件表;选定渠道时客户须带对应企微标签(contact_tag);**二中心展示部门在选定渠道下计 0**
* - 接诊诊单 = 已完成挂号 status=3,医助 role_id=2;按 TIMESTAMP(appointment_date, appointment_time) 落入统计区间(挂号条数,非订单)。
* - {渠道}成交单 = 选定渠道时与 {渠道}业绩同源:区间内 **非取消业务订单条数**(仅剔除 fulfillment_status=4NULL 与其它状态计入,按 create_time 归日);dict(channels) 与 tag/creator 两套口径均按订单计,非挂号条数。
* - 合计业绩 = 区间内 zyt_tcm_prescription_order.amount 求和(排除已取消(4) 与软删),按 creator_id 归属到「中心」展示部门;
* - 合计业绩 = 区间内 zyt_tcm_prescription_order.amount 求和(排除已取消(4) 与软删),按 dg.assistant_id 归属到「中心」展示部门;
* 无法归属到任一展示部门的金额单列「未归属中心」行;合计行 = 与列表同条件的全表 SUM(不限部门)
* · 时间窗与业绩条件与列表 stats_order_amount_performance 一致;列表若另有患者/单号等筛选或账号数据域收窄,金额可能仍不同
* · 选定渠道时「{渠道}业绩」列仍按比例展示;合计列全量与渠道列含未归属补差;**名称含「二中心」的展示部门不参与该渠道进线/业绩/成交单/ROI 分子**
@@ -348,7 +348,7 @@ class YejiStatsLogic
/**
* 医助排行榜:按展示部门分表,每表内按诊金降序排名。
* 诊金口径与 overview 部门表一致(无渠道=合计业绩/creator;有渠道={渠道}业绩/dict 诊单医助或 tag/creator;二中心在选渠道下注 0
* 诊金口径:无渠道=诊单 dg.assistant_id 业绩(与列表 assistant_id 筛选一致);有渠道={渠道}业绩/dict 诊单医助;二中心在选渠道下注 0。
* 接诊率 = 排行用诊金 ÷ 进线条数(元/进线,1 位小数;进线为 0 时为 0)。
*
* @param array{start_date?:string,end_date?:string,dept_ids?:int[]|string,channel_code?:string,tag_id?:string} $params
@@ -431,7 +431,7 @@ class YejiStatsLogic
$rangeNote = $channelFilterActive
? ('排行诊金 = 选定渠道「' . $channelName . '」业绩口径(与部门表该渠道业绩列一致)。接诊率 = 诊金 ÷ 进线(元/进线)。'
. '「二中心」医助在该渠道下诊金与进线计 0。')
: '排行诊金 = 合计业绩口径(creator,与部门表「合计业绩」一致)。接诊率 = 诊金 ÷ 进线(元/进线;进线为 0 时为 0)。';
: '排行诊金 = 处方订单列表 assistant_id 口径(诊单医助业绩,与列表按医助筛选一致)。接诊率 = 诊金 ÷ 进线(元/进线;进线为 0 时为 0)。';
$leaderboards = [];
foreach ($primaryDeptIds as $deptId) {
@@ -1084,7 +1084,7 @@ class YejiStatsLogic
}
/**
* 业绩按 creator_id 聚合到 admin(与 aggregatePerformance 同源 WHERE)。
* 业绩按 dg.assistant_id 聚合到 admin(与处方订单列表 assistant_id 筛选口径一致)。
*
* @return array<int, float>
*/
@@ -1100,19 +1100,23 @@ class YejiStatsLogic
if ($tagAssistantIds !== null && $tagAssistantIds === []) {
return [];
}
$diagTable = self::tableWithPrefix('tcm_diagnosis');
$query = Db::name('tcm_prescription_order')
->alias('o')
->join("{$diagTable} dg", 'dg.id = o.diagnosis_id AND dg.delete_time IS NULL', 'INNER')
->whereNull('o.delete_time')
->where('o.create_time', 'between', [$startTs, $endTs]);
->where('o.create_time', 'between', [$startTs, $endTs])
->where('o.diagnosis_id', '>', 0)
->where('dg.assistant_id', '>', 0);
self::applyPrescriptionOrderNotCancelledForPerformance($query);
$query->field(['o.creator_id', 'SUM(o.amount) AS amt'])
->group('o.creator_id');
$query->field(['dg.assistant_id', 'SUM(o.amount) AS amt'])
->group('dg.assistant_id');
if ($tagDiagIds !== null) {
$query->whereIn('o.diagnosis_id', $tagDiagIds);
}
if ($tagAssistantIds !== null) {
$query->whereIn('o.creator_id', array_keys($tagAssistantIds));
$query->whereIn('dg.assistant_id', array_keys($tagAssistantIds));
}
$rows = $query->select()->toArray();
@@ -1121,11 +1125,11 @@ class YejiStatsLogic
}
$byAdmin = [];
foreach ($rows as $r) {
$cid = (int) ($r['creator_id'] ?? 0);
if ($cid <= 0) {
$aid = (int) ($r['assistant_id'] ?? 0);
if ($aid <= 0) {
continue;
}
$byAdmin[$cid] = ($byAdmin[$cid] ?? 0) + (float) $r['amt'];
$byAdmin[$aid] = ($byAdmin[$aid] ?? 0) + (float) $r['amt'];
}
return $byAdmin;