From 0c5afe65246c50e75d54772a27b1196eba7f603c Mon Sep 17 00:00:00 2001 From: limu Date: Mon, 25 Dec 2023 10:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/user/User.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controller/admin/user/User.php b/app/controller/admin/user/User.php index fc934a7..cd31bdb 100644 --- a/app/controller/admin/user/User.php +++ b/app/controller/admin/user/User.php @@ -616,10 +616,19 @@ class User extends BaseController $id = (int)$this->request->param('uid', ''); if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); + $is_cf = false; foreach ($partner_id as $k => $value) { + $count = array_count_values($partner_id); // 统计每个元素的出现次数 + if (isset($count[$value]) && $count[$value] > 1) { + $is_cf = true; + } $partner_ids[$k] = (int)$value; - if (!$partnerRepository->exists((int)$value)) + if (!$partnerRepository->exists((int)$value)) { return app('json')->fail('所选合作人角色不存在'); + } + } + if($is_cf){ + return app('json')->fail('请勿给用户设置重复的角色'); } foreach ($user_role_id as $k => $value) { $user_role_ids[$k] = (int)$value;