|
|
@ -607,37 +607,15 @@ class User extends BaseController |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!$this->repository->exists($id)) |
|
|
|
if (!$this->repository->exists($id)) |
|
|
|
return app('json')->fail('数据不存在'); |
|
|
|
return app('json')->fail('数据不存在'); |
|
|
|
return app('json')->success(formToData($partnerRepository->changePartnerForm($id))); |
|
|
|
return app('json')->success($partnerRepository->changePartnerForm($id)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function changePartner(PartnerRepository $partnerRepository, UserPartnerRepository $userPartnerRepository) |
|
|
|
public function changePartner(PartnerRepository $partnerRepository, UserPartnerRepository $userPartnerRepository) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$partner_id = (array)$this->request->param('partner_id', []); |
|
|
|
|
|
|
|
$user_role_id = (array)$this->request->param('user_role_id', []); |
|
|
|
$user_role_id = (array)$this->request->param('user_role_id', []); |
|
|
|
$partner_ids = $user_role_ids = []; |
|
|
|
|
|
|
|
$id = (int)$this->request->param('uid', ''); |
|
|
|
$id = (int)$this->request->param('uid', ''); |
|
|
|
if (!$this->repository->exists($id)) |
|
|
|
if (!$this->repository->exists($id)) |
|
|
|
return app('json')->fail('数据不存在'); |
|
|
|
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)) { |
|
|
|
|
|
|
|
return app('json')->fail('所选合作人角色不存在'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$role_info = Partner::getDB()->where('id',$value)->find(); |
|
|
|
|
|
|
|
$role_count = UserPartner::getDB()->where('partner_id',$value)->count() ?? 0; |
|
|
|
|
|
|
|
if($role_info->max_role_num <= $role_count){ |
|
|
|
|
|
|
|
return app('json')->fail('角色分配以到上限'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if($is_cf){ |
|
|
|
|
|
|
|
return app('json')->fail('请勿给用户设置重复的角色'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach ($user_role_id as $k => $value) { |
|
|
|
foreach ($user_role_id as $k => $value) { |
|
|
|
$user_role_ids[$k] = (int)$value; |
|
|
|
$user_role_ids[$k] = (int)$value; |
|
|
|
if (!$partnerRepository->roleExists((int)$value)) |
|
|
|
if (!$partnerRepository->roleExists((int)$value)) |
|
|
|