更新
This commit is contained in:
@@ -48,6 +48,7 @@ class RoleLogic extends BaseLogic
|
||||
'name' => $params['name'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'data_scope' => self::normalizeDataScope($params['data_scope'] ?? null),
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
@@ -90,6 +91,7 @@ class RoleLogic extends BaseLogic
|
||||
'name' => $params['name'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'data_scope' => self::normalizeDataScope($params['data_scope'] ?? null),
|
||||
]);
|
||||
|
||||
if (!empty($menuId)) {
|
||||
@@ -142,13 +144,26 @@ class RoleLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail(int $id): array
|
||||
{
|
||||
$detail = SystemRole::field('id,name,desc,sort')->find($id);
|
||||
$detail = SystemRole::field('id,name,desc,sort,data_scope')->find($id);
|
||||
$authList = $detail->roleMenuIndex()->select()->toArray();
|
||||
$menuId = array_column($authList, 'menu_id');
|
||||
$detail['menu_id'] = $menuId;
|
||||
return $detail->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化 data_scope:合法值 1-4,非法或缺省统一回退为 1(全部),保持与历史默认一致不增加风险。
|
||||
*/
|
||||
private static function normalizeDataScope($value): int
|
||||
{
|
||||
$v = (int) $value;
|
||||
if ($v >= 1 && $v <= 4) {
|
||||
return $v;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 角色数据
|
||||
|
||||
@@ -730,7 +730,7 @@ class OrderLogic
|
||||
* @param array $params order_type(-1全部已支付类型合计,0退款,1挂号费,2问诊费,3药品费用,4首付,5尾款,6其他), days(0今天,7,30)
|
||||
* @return array
|
||||
*/
|
||||
public static function orderStats(array $params = [])
|
||||
public static function orderStats(array $params = [], int $adminId = 0, ?array $adminInfo = null)
|
||||
{
|
||||
$allPaidOrderTypes = [1, 2, 3, 4, 5, 6];
|
||||
$orderType = array_key_exists('order_type', $params) ? (int) $params['order_type'] : 1;
|
||||
@@ -740,6 +740,11 @@ class OrderLogic
|
||||
$orderTypeName = $orderType === -1 ? '全部(已支付)' : self::$orderTypeNames[$orderType];
|
||||
$days = isset($params['days']) ? (int)$params['days'] : 7;
|
||||
|
||||
// 数据范围:当前用户可见 admin id 集合;null 表示全部
|
||||
$visibleAdminIds = ($adminInfo !== null && $adminId > 0)
|
||||
? \app\common\service\DataScope\DataScopeService::getVisibleAdminIds($adminId, $adminInfo)
|
||||
: null;
|
||||
|
||||
$endTime = !empty($params['end_time']) ? strtotime($params['end_time']) : time();
|
||||
if ($days === 0) {
|
||||
$startTime = strtotime(date('Y-m-d'));
|
||||
@@ -764,6 +769,13 @@ class OrderLogic
|
||||
} else {
|
||||
$query->where('order_type', $orderType)->where('status', 2);
|
||||
}
|
||||
if ($visibleAdminIds !== null) {
|
||||
if ($visibleAdminIds === []) {
|
||||
$query->whereRaw('0 = 1');
|
||||
} else {
|
||||
$query->whereIn('creator_id', $visibleAdminIds);
|
||||
}
|
||||
}
|
||||
$orderRows = $query
|
||||
->field('creator_id, count(*) as cnt, sum(amount) as total_amount')
|
||||
->group('creator_id')
|
||||
@@ -822,6 +834,13 @@ class OrderLogic
|
||||
} else {
|
||||
$todayQuery->where('order_type', $orderType)->where('status', 2);
|
||||
}
|
||||
if ($visibleAdminIds !== null) {
|
||||
if ($visibleAdminIds === []) {
|
||||
$todayQuery->whereRaw('0 = 1');
|
||||
} else {
|
||||
$todayQuery->whereIn('creator_id', $visibleAdminIds);
|
||||
}
|
||||
}
|
||||
$todayRows = $todayQuery
|
||||
->field('creator_id, count(*) as cnt, sum(amount) as total_amount')
|
||||
->group('creator_id')
|
||||
@@ -850,6 +869,9 @@ class OrderLogic
|
||||
}
|
||||
usort($todayRanking, fn($a, $b) => $b['count'] <=> $a['count']);
|
||||
|
||||
// 数据范围启用时(非 root/全部范围),无可见成员的部门不渲染
|
||||
$hideEmptyDept = $visibleAdminIds !== null;
|
||||
|
||||
$deptData = [];
|
||||
$assignedIds = [];
|
||||
foreach ($depts as $deptId => $deptName) {
|
||||
@@ -866,6 +888,9 @@ class OrderLogic
|
||||
'amount' => number_format((float)($amounts[$adminId] ?? 0), 2, '.', ''),
|
||||
];
|
||||
}
|
||||
if ($hideEmptyDept && $members === []) {
|
||||
continue;
|
||||
}
|
||||
$deptTotal = array_sum(array_column($members, 'count'));
|
||||
$deptAmount = array_sum(array_map(fn($m) => (float)$m['amount'], $members));
|
||||
$deptData[] = [
|
||||
|
||||
@@ -2115,19 +2115,34 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
/**
|
||||
* @notes 获取医助列表
|
||||
* @param int $adminId 当前管理员 id(用于数据范围;0 表示不过滤)
|
||||
* @param array|null $adminInfo 当前管理员信息(用于数据范围;null 表示不过滤)
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssistants()
|
||||
public static function getAssistants(int $adminId = 0, ?array $adminInfo = null)
|
||||
{
|
||||
try {
|
||||
// 这里不要用 Admin 模型查询,否则会触发其 append(role_id/dept_id/jobs_id)
|
||||
// 每行再发多次查询,形成严重 N+1,统计页会被拖慢到十几秒。
|
||||
$assistants = \think\facade\Db::name('admin')
|
||||
$query = \think\facade\Db::name('admin')
|
||||
->alias('a')
|
||||
->join('admin_role ar', 'a.id = ar.admin_id')
|
||||
->where('ar.role_id', 2)
|
||||
->where('a.disable', 0)
|
||||
->whereNull('a.delete_time')
|
||||
->whereNull('a.delete_time');
|
||||
|
||||
// 数据范围:仅展示当前管理员可见的医助;null = 全部不过滤
|
||||
if ($adminInfo !== null && $adminId > 0) {
|
||||
$visibleIds = \app\common\service\DataScope\DataScopeService::getVisibleAdminIds($adminId, $adminInfo);
|
||||
if ($visibleIds !== null) {
|
||||
if ($visibleIds === []) {
|
||||
return [];
|
||||
}
|
||||
$query->whereIn('a.id', $visibleIds);
|
||||
}
|
||||
}
|
||||
|
||||
$assistants = $query
|
||||
->field(['a.id', 'a.name', 'a.account'])
|
||||
->order('a.id', 'asc')
|
||||
->distinct(true)
|
||||
@@ -3105,10 +3120,15 @@ class DiagnosisLogic extends BaseLogic
|
||||
* @param array $params start_time, end_time, days(可选,默认7)
|
||||
* @return array
|
||||
*/
|
||||
public static function assistantDiagnosisStats(array $params = [])
|
||||
public static function assistantDiagnosisStats(array $params = [], int $adminId = 0, ?array $adminInfo = null)
|
||||
{
|
||||
$days = isset($params['days']) ? (int)$params['days'] : 7;
|
||||
|
||||
// 数据范围:当前用户可见 admin id 集合;null 表示全部
|
||||
$visibleAdminIds = ($adminInfo !== null && $adminId > 0)
|
||||
? \app\common\service\DataScope\DataScopeService::getVisibleAdminIds($adminId, $adminInfo)
|
||||
: null;
|
||||
|
||||
$endTime = !empty($params['end_time']) ? strtotime($params['end_time']) : time();
|
||||
if ($days === 0) {
|
||||
$startTime = strtotime(date('Y-m-d'));
|
||||
@@ -3127,6 +3147,13 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
$assistantIds = \app\common\model\auth\AdminRole::where('role_id', 2)
|
||||
->column('admin_id');
|
||||
// 数据范围交集:仅展示「医助 ∩ 当前用户可见」
|
||||
if ($visibleAdminIds !== null) {
|
||||
$assistantIds = array_values(array_intersect(
|
||||
array_map('intval', $assistantIds),
|
||||
array_map('intval', $visibleAdminIds)
|
||||
));
|
||||
}
|
||||
if (empty($assistantIds)) {
|
||||
return [
|
||||
'date_range' => [date('Y-m-d', $startTime), date('Y-m-d', $endTime)],
|
||||
@@ -3192,6 +3219,9 @@ class DiagnosisLogic extends BaseLogic
|
||||
usort($todayRanking, fn($a, $b) => $b['count'] <=> $a['count']);
|
||||
$todayRanking = array_values(array_filter($todayRanking, fn($a) => $a['count'] > 0));
|
||||
|
||||
// 数据范围启用时(非 root/全部范围),无可见成员的部门不渲染
|
||||
$hideEmptyDept = $visibleAdminIds !== null;
|
||||
|
||||
$deptData = [];
|
||||
$assignedAdminIds = [];
|
||||
foreach ($depts as $deptId => $deptName) {
|
||||
@@ -3208,6 +3238,9 @@ class DiagnosisLogic extends BaseLogic
|
||||
'count' => $cnt,
|
||||
];
|
||||
}
|
||||
if ($hideEmptyDept && $assistants === []) {
|
||||
continue;
|
||||
}
|
||||
$deptData[] = [
|
||||
'dept_id' => (int)$deptId,
|
||||
'dept_name' => $deptName,
|
||||
|
||||
Reference in New Issue
Block a user