更新
This commit is contained in:
@@ -929,8 +929,9 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$inList = implode(',', $deptIds);
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$adTbl = (new AdminDept())->getTable();
|
||||
$poRef = '`' . str_replace('`', '', $poTbl) . '`';
|
||||
$query->whereRaw(
|
||||
YejiStatsLogic::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poTbl, $diagTbl, $adTbl, $inList)
|
||||
YejiStatsLogic::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poRef, $diagTbl, $adTbl, $inList)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3426,7 +3426,6 @@ class YejiStatsLogic
|
||||
return;
|
||||
}
|
||||
$diagTable = self::tableWithPrefix('tcm_diagnosis');
|
||||
$adTable = self::tableWithPrefix('admin_dept');
|
||||
if ($hasDept) {
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $expandedDeptIds), static function (int $x): bool {
|
||||
return $x > 0;
|
||||
@@ -3437,16 +3436,9 @@ class YejiStatsLogic
|
||||
return;
|
||||
}
|
||||
$inList = implode(',', $ids);
|
||||
$query->where(function ($q) use ($diagTable, $adTable, $inList) {
|
||||
$q->whereExists(
|
||||
"SELECT 1 FROM {$adTable} ad INNER JOIN {$diagTable} dg ON ad.admin_id = dg.assistant_id AND dg.delete_time IS NULL "
|
||||
. "WHERE dg.id = o.diagnosis_id AND ad.dept_id IN ({$inList})"
|
||||
);
|
||||
$q->whereExists(
|
||||
"SELECT 1 FROM {$adTable} adc WHERE adc.admin_id = o.creator_id AND adc.dept_id IN ({$inList})",
|
||||
'OR'
|
||||
);
|
||||
});
|
||||
$diagTb = (new Diagnosis())->getTable();
|
||||
$adTb = (new AdminDept())->getTable();
|
||||
$query->whereRaw(self::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst('`o`', $diagTb, $adTb, $inList));
|
||||
}
|
||||
if ($hasVis) {
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $visibleAdminIds), static function (int $x): bool {
|
||||
@@ -4926,22 +4918,23 @@ class YejiStatsLogic
|
||||
* {@see aggregateListAlignedOrderMetricsByDept} 及
|
||||
* {@see PrescriptionOrderLists::applyDoctorAssistantFilters} 中 assistant_dept_id 一致)。
|
||||
*
|
||||
* @param string $orderRefBackticked 主查询里业务订单表标识,须已加反引号:列表/Model 无别名时用 `` `zyt_tcm_prescription_order` ``;Db::name()->alias('o') 时用 `` `o` ``
|
||||
* @param string $inListComma 已净化的 id 列表(仅数字与逗号)
|
||||
*/
|
||||
public static function sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst(
|
||||
string $poTbl,
|
||||
string $orderRefBackticked,
|
||||
string $diagTbl,
|
||||
string $adTbl,
|
||||
string $inListComma
|
||||
): string {
|
||||
$creatorInSubtree = "EXISTS (SELECT 1 FROM `{$adTbl}` adc WHERE adc.`admin_id` = `{$poTbl}`.`creator_id` AND adc.`dept_id` IN ({$inListComma}))";
|
||||
$creatorInSubtree = "EXISTS (SELECT 1 FROM `{$adTbl}` adc WHERE adc.`admin_id` = {$orderRefBackticked}.`creator_id` AND adc.`dept_id` IN ({$inListComma}))";
|
||||
$assistantInSubtree = "EXISTS (SELECT 1 FROM `{$adTbl}` ad INNER JOIN `{$diagTbl}` dg ON ad.admin_id = dg.assistant_id AND dg.delete_time IS NULL "
|
||||
. "WHERE dg.`id` = `{$poTbl}`.`diagnosis_id` AND ad.dept_id IN ({$inListComma}))";
|
||||
. "WHERE dg.`id` = {$orderRefBackticked}.`diagnosis_id` AND ad.dept_id IN ({$inListComma}))";
|
||||
|
||||
return '('
|
||||
. '((IFNULL(`' . $poTbl . '`.`creator_id`,0) > 0) AND (' . $creatorInSubtree . '))'
|
||||
. '((IFNULL(' . $orderRefBackticked . '.`creator_id`,0) > 0) AND (' . $creatorInSubtree . '))'
|
||||
. ' OR '
|
||||
. '((IFNULL(`' . $poTbl . '`.`creator_id`,0) <= 0) AND (' . $assistantInSubtree . '))'
|
||||
. '((IFNULL(' . $orderRefBackticked . '.`creator_id`,0) <= 0) AND (' . $assistantInSubtree . '))'
|
||||
. ')';
|
||||
}
|
||||
|
||||
@@ -4994,7 +4987,7 @@ class YejiStatsLogic
|
||||
}
|
||||
}
|
||||
|
||||
$poTbl = (new PrescriptionOrder())->getTable();
|
||||
$poRef = '`' . str_replace('`', '', (new PrescriptionOrder())->getTable()) . '`';
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$adTbl = (new AdminDept())->getTable();
|
||||
|
||||
@@ -5006,7 +4999,7 @@ class YejiStatsLogic
|
||||
return;
|
||||
}
|
||||
$tIn = implode(',', $tSubtree);
|
||||
$clauses = [self::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poTbl, $diagTbl, $adTbl, $tIn)];
|
||||
$clauses = [self::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poRef, $diagTbl, $adTbl, $tIn)];
|
||||
foreach ($beaters as $b) {
|
||||
$bSubtree = DeptLogic::getSelfAndDescendantIds((int) $b);
|
||||
$bSubtree = array_values(array_filter(array_map('intval', $bSubtree), static fn (int $id): bool => $id > 0));
|
||||
@@ -5014,7 +5007,7 @@ class YejiStatsLogic
|
||||
continue;
|
||||
}
|
||||
$bIn = implode(',', $bSubtree);
|
||||
$clauses[] = 'NOT (' . self::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poTbl, $diagTbl, $adTbl, $bIn) . ')';
|
||||
$clauses[] = 'NOT (' . self::sqlPrescriptionOrderListDeptSubtreeMatchCreatorFirst($poRef, $diagTbl, $adTbl, $bIn) . ')';
|
||||
}
|
||||
$query->whereRaw('(' . implode(' AND ', $clauses) . ')');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user