逻辑调整

main
limu 11 months ago
parent 12127d4c50
commit 7548bdc97a
  1. 25
      app/common/repositories/user/UserPartnerRepository.php
  2. 24
      app/controller/admin/user/User.php

@ -73,22 +73,15 @@ class UserPartnerRepository extends BaseRepository
public function changePartnerForm($uid)
{
/** @var UserLabelRepository $make */
$list = UserPartner::getDB()->where('uid',$uid)->column('id') ?? [];
$data = ['partner_id' => $list, 'uid' => $uid];
$url = 'sys/user/partner/' . $uid;
$res = Elm::createForm($url, [
Elm::input('uid', '用户 ID', '')->disabled(true)->required(true),
Elm::selectMultiple('partner_id', '用户合作人角色')->options(function () {
$data = UserPartner::getDB()->select()->toArray();
foreach ($data as $value => $label) {
$name = (string)$label['id'];
$value = $label['partner_name'];
$options[] = compact('value', 'name');
}
return $options;
}),
])->setTitle('编辑合作人角色')->formData($data);
return $res;
$list = UserPartner::getDB()->where('uid', $uid)->column('id') ?? [];
$data = UserPartner::getDB()->select()->toArray();
foreach ($data as $value => $label) {
$name = (string)$label['id'];
$value = $label['partner_name'];
$options[] = compact('value', 'name');
}
$data = ['partner_id' => $list, 'uid' => $uid, 'option' => $options];
return $data;
}
public function editPartner(int $uid, array $user_role_id = [])

@ -607,37 +607,15 @@ class User extends BaseController
{
if (!$this->repository->exists($id))
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)
{
$partner_id = (array)$this->request->param('partner_id', []);
$user_role_id = (array)$this->request->param('user_role_id', []);
$partner_ids = $user_role_ids = [];
$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)) {
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) {
$user_role_ids[$k] = (int)$value;
if (!$partnerRepository->roleExists((int)$value))

Loading…
Cancel
Save