增加业务强制绑定提醒

This commit is contained in:
mzl
2025-10-13 13:25:19 +08:00
parent 1b14d5450d
commit 04d7d73c45
6 changed files with 136 additions and 12 deletions
+34 -3
View File
@@ -3,8 +3,11 @@
namespace app\common\logic;
use app\common\model\User;
use app\common\model\UserGroupMembers;
use app\common\traits\crud\CrudLogicTrait;
use support\exception\BusinessException;
use support\Request;
use app\common\model\UserRoles;
class UserLogic
{
@@ -20,7 +23,7 @@ class UserLogic
*/
public function userInfo(int $uid)
{
$user = User::find($uid);
$user = User::with('reportToInfo')->find($uid);
if (!$user) {
throw new BusinessException('账户不存在', 404);
@@ -38,6 +41,7 @@ class UserLogic
*/
public function edit(int $uid, array $data)
{
//
$user = User::find($uid);
if (!$user) {
@@ -47,6 +51,26 @@ class UserLogic
$user->fill($data);
$user->save();
// 绑定内勤 10.13 add
if (isset($data['office_clerk_id']) && $data['office_clerk_id'] > 0) {
$ug = UserGroupMembers::where('user_id', $uid)->where('status', 1)->first();
if ($ug) {
$ug->delete();
}
$group = UserGroupMembers::where('user_id', $data['office_clerk_id'])->where('is_leader', 1)->where('status', 1)->first();
if (!$group) {
throw new BusinessException('该内勤还未创建分组', 404);
}
UserGroupMembers::create([
'user_id' => $uid,
'group_id' => $group->group_id,
'is_leader' => 0,
'status' => 1
]);
}
return $user;
}
@@ -64,9 +88,16 @@ class UserLogic
/**
* 获取用户列表
*/
public function getList()
public function getList(Request $request)
{
$list = User::where('status', 1)->orderBy('id', 'desc')->get();
$p = $request->all();
$user = User::where('status', 1);
if (isset($p['role_id']) && $p['role_id'] > 0) {
$userIds = UserRoles::where('role_id', $p['role_id'])->pluck('user_id');
$user->whereIn('id', $userIds);
}
$list = $user->orderBy('id', 'desc')->get();
$arr = [];
foreach ($list->toArray() as $item) {
$arr[] = [