更新
This commit is contained in:
@@ -5,13 +5,34 @@ declare(strict_types=1);
|
||||
namespace app\adminapi\logic\tcm;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\tcm\PrescriptionLibrary;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 处方库逻辑层
|
||||
*/
|
||||
class PrescriptionLibraryLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 是否可管理全部处方(超级管理员 或 配置中的管理员角色)
|
||||
*/
|
||||
public static function canManageAllPrescriptions(int $adminId, array $adminInfo): bool
|
||||
{
|
||||
if (!empty($adminInfo['root']) && (int) $adminInfo['root'] === 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$allowRoles = Config::get('project.prescription_library_manage_all_roles', []);
|
||||
if ($allowRoles === [] || $allowRoles === null) {
|
||||
$allowRoles = Config::get('project.order_edit_all_roles', [0, 3]);
|
||||
}
|
||||
|
||||
$myRoles = AdminRole::where('admin_id', $adminId)->column('role_id');
|
||||
|
||||
return count(array_intersect($myRoles, $allowRoles)) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加处方库
|
||||
*/
|
||||
@@ -24,7 +45,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
}
|
||||
|
||||
$model = PrescriptionLibrary::create($params);
|
||||
return $model->id;
|
||||
return (int) $model->id;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return null;
|
||||
@@ -34,7 +55,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
/**
|
||||
* @notes 编辑处方库
|
||||
*/
|
||||
public static function edit(array $params, int $adminId): bool
|
||||
public static function edit(array $params, int $adminId, bool $canManageAll = false): bool
|
||||
{
|
||||
try {
|
||||
$model = PrescriptionLibrary::findOrEmpty($params['id']);
|
||||
@@ -43,8 +64,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
// 权限检查:只有创建者或公开的处方才能编辑
|
||||
if ($model->creator_id != $adminId && $model->is_public != 1) {
|
||||
if (!$canManageAll && (int) $model->creator_id !== $adminId) {
|
||||
self::setError('无权限编辑此处方');
|
||||
return false;
|
||||
}
|
||||
@@ -65,7 +85,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
/**
|
||||
* @notes 删除处方库
|
||||
*/
|
||||
public static function delete(int $id, int $adminId): bool
|
||||
public static function delete(int $id, int $adminId, bool $canManageAll = false): bool
|
||||
{
|
||||
try {
|
||||
$model = PrescriptionLibrary::findOrEmpty($id);
|
||||
@@ -74,8 +94,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
// 权限检查:只有创建者才能删除
|
||||
if ($model->creator_id != $adminId) {
|
||||
if (!$canManageAll && (int) $model->creator_id !== $adminId) {
|
||||
self::setError('无权限删除此处方');
|
||||
return false;
|
||||
}
|
||||
@@ -91,7 +110,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
/**
|
||||
* @notes 处方库详情
|
||||
*/
|
||||
public static function detail(int $id, int $adminId): ?array
|
||||
public static function detail(int $id, int $adminId, bool $canManageAll = false): ?array
|
||||
{
|
||||
try {
|
||||
$model = PrescriptionLibrary::findOrEmpty($id);
|
||||
@@ -99,8 +118,7 @@ class PrescriptionLibraryLogic extends BaseLogic
|
||||
return null;
|
||||
}
|
||||
|
||||
// 权限检查:只有创建者或公开的处方才能查看
|
||||
if ($model->creator_id != $adminId && $model->is_public != 1) {
|
||||
if (!$canManageAll && (int) $model->creator_id !== $adminId && (int) $model->is_public !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user