更新
This commit is contained in:
@@ -19,6 +19,7 @@ use app\common\model\auth\Admin;
|
||||
use app\common\service\DataScope\DataScopeService;
|
||||
use app\common\service\ExpressTrackService;
|
||||
use app\common\service\gancao\GancaoScmRecipelService;
|
||||
use think\db\Query;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
@@ -268,6 +269,166 @@ class PrescriptionOrderLogic
|
||||
return self::roleIntersect($adminInfo, $allow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 与业务订单列表金额统计一致:命中「统计医助」角色且非农单支付审核档时,业务侧按「仅限本人关联诊单的业绩域」收口。
|
||||
* 提成结算等对业绩归因 SQL 收窄时需与之对齐。
|
||||
*/
|
||||
public static function statsRestrictedToOwnAssistantPerformanceDomain(array $adminInfo): bool
|
||||
{
|
||||
if (!empty($adminInfo['root']) && (int) $adminInfo['root'] === 1) {
|
||||
return false;
|
||||
}
|
||||
if (self::canViewOrderListStatsAllScope($adminInfo)) {
|
||||
return false;
|
||||
}
|
||||
$assistantRid = (int) Config::get('project.prescription_order_stats_assistant_role_id', 2);
|
||||
|
||||
return $assistantRid > 0 && self::roleIntersect($adminInfo, [$assistantRid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提成结算等与列表对齐:按开方医生 / 诊单医助 ∪ 订单创建人 筛选(与 PrescriptionOrderLists::applyDoctorAssistantFilters 在非业绩抽屉场景一致)。
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
public static function applyCommissionOrderDoctorAssistantFilters(Query $query, string $alias, array $params): void
|
||||
{
|
||||
if (isset($params['doctor_id']) && (int) $params['doctor_id'] > 0) {
|
||||
$doctorId = (int) $params['doctor_id'];
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
$query->whereExists(
|
||||
"SELECT 1 FROM `{$rxTbl}` rx WHERE rx.`id` = `{$alias}`.`prescription_id` "
|
||||
. "AND rx.`delete_time` IS NULL AND rx.`creator_id` = {$doctorId}"
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['assistant_id']) && (int) $params['assistant_id'] > 0) {
|
||||
$assistantId = (int) $params['assistant_id'];
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->where(function ($q) use ($alias, $diagTbl, $assistantId): void {
|
||||
$q->where("{$alias}.creator_id", $assistantId);
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$alias}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$assistantId})"
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 与处方订单列表 HasDataScopeFilter + applyCreatorOrOwnPrescriptionVisibility 等价;主业务订单别名 $alias。
|
||||
*
|
||||
* @param array<string, mixed> $params 可含 assistant_id(显式收窄时校验数据域)
|
||||
*/
|
||||
public static function applyPrescriptionOrderListAccessForCommissionQuery(
|
||||
Query $query,
|
||||
string $alias,
|
||||
int $viewerAdminId,
|
||||
array $viewerAdminInfo,
|
||||
array $params = []
|
||||
): void {
|
||||
if ($viewerAdminId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::applyCommissionOrderDoctorAssistantFilters($query, $alias, $params);
|
||||
|
||||
if (self::canSeeAllPrescriptionOrders($viewerAdminInfo)) {
|
||||
self::applyCommissionOrderDataScope($query, $alias, $viewerAdminId, $viewerAdminInfo);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
|
||||
$explicitAssistant = (int) ($params['assistant_id'] ?? 0);
|
||||
$allowExplicitAssistantVisibility = false;
|
||||
if ($explicitAssistant > 0) {
|
||||
if (!DataScopeService::isEnabled()) {
|
||||
$allowExplicitAssistantVisibility = true;
|
||||
} else {
|
||||
$visibleIds = DataScopeService::getVisibleAdminIds($viewerAdminId, $viewerAdminInfo);
|
||||
if ($visibleIds === null || in_array($explicitAssistant, $visibleIds, true)) {
|
||||
$allowExplicitAssistantVisibility = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query->where(function ($q) use (
|
||||
$alias,
|
||||
$rxTbl,
|
||||
$diagTbl,
|
||||
$viewerAdminId,
|
||||
$explicitAssistant,
|
||||
$allowExplicitAssistantVisibility,
|
||||
$viewerAdminInfo
|
||||
): void {
|
||||
if (self::canViewOrdersForOwnPrescription($viewerAdminInfo)) {
|
||||
$q->where(function ($qq) use ($alias, $rxTbl, $diagTbl, $viewerAdminId): void {
|
||||
$qq->where("{$alias}.creator_id", $viewerAdminId);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$rxTbl}` rx WHERE rx.`id` = `{$alias}`.`prescription_id`"
|
||||
. " AND rx.`delete_time` IS NULL AND rx.`creator_id` = {$viewerAdminId})"
|
||||
);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$alias}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$viewerAdminId})"
|
||||
);
|
||||
});
|
||||
} else {
|
||||
$q->where(function ($qq) use ($alias, $diagTbl, $viewerAdminId): void {
|
||||
$qq->where("{$alias}.creator_id", $viewerAdminId);
|
||||
$qq->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$alias}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$viewerAdminId})"
|
||||
);
|
||||
});
|
||||
}
|
||||
if ($allowExplicitAssistantVisibility) {
|
||||
$q->whereOr("{$alias}.creator_id", $explicitAssistant);
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$alias}`.`diagnosis_id`"
|
||||
. " AND dg.`delete_time` IS NULL AND dg.`assistant_id` = {$explicitAssistant})"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
self::applyCommissionOrderDataScope($query, $alias, $viewerAdminId, $viewerAdminInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表数据域:创建人 ∈ 可见 或 诊单医助 ∈ 可见。
|
||||
*/
|
||||
private static function applyCommissionOrderDataScope(
|
||||
Query $query,
|
||||
string $alias,
|
||||
int $viewerAdminId,
|
||||
array $viewerAdminInfo
|
||||
): void {
|
||||
if (!DataScopeService::isEnabled()) {
|
||||
return;
|
||||
}
|
||||
$ids = DataScopeService::getVisibleAdminIds($viewerAdminId, $viewerAdminInfo);
|
||||
if ($ids === null) {
|
||||
return;
|
||||
}
|
||||
if ($ids === []) {
|
||||
$query->whereRaw('0 = 1');
|
||||
|
||||
return;
|
||||
}
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$inList = implode(',', array_map('intval', $ids));
|
||||
$query->where(function ($q) use ($alias, $diagTbl, $inList): void {
|
||||
$q->whereIn("{$alias}.creator_id", explode(',', $inList));
|
||||
$q->whereOrRaw(
|
||||
"EXISTS (SELECT 1 FROM `{$diagTbl}` dg WHERE dg.`id` = `{$alias}`.`diagnosis_id` "
|
||||
. "AND dg.`delete_time` IS NULL AND dg.`assistant_id` IN ({$inList}))"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $row
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user