From 4d4efd79e1756784b9a88ba76baae8b1f7698574 Mon Sep 17 00:00:00 2001 From: Administrator <1269936630@qq.com> Date: Tue, 16 Jun 2026 16:39:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=80=9A=E8=BF=87=E4=B8=A4=E5=BC=A0=E8=A1=A8?= =?UTF-8?q?employees=E7=94=A8=E6=88=B7=E8=A1=A8,split=5Faccount=5Fconfig?= =?UTF-8?q?=E5=88=86=E8=B4=A6=E9=85=8D=E7=BD=AE=E8=A1=A8,=E9=80=9A?= =?UTF-8?q?=E8=BF=87userlist=E8=BF=94=E5=9B=9E=E5=85=B3=E8=81=94=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E3=80=82=202.=E9=80=9A=E8=BF=87use=5Fid,prod?= =?UTF-8?q?uct=5Fid=20=E8=BF=94=E5=9B=9E=E4=BB=93=E5=BA=93=E9=87=8C?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E5=95=86=E5=93=81=E6=80=BB=E5=92=8C=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E3=80=82=203.about=5Fid,phone,from,last=5Flogin=5Fip,?= =?UTF-8?q?code,expire=5Ftime=20=20/api/userList=20=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/employee.go | 2 +- models/response/Employee.go | 6 +++ service/employee.go | 98 ++++++++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/models/employee.go b/models/employee.go index 1ae1670..91ae62d 100644 --- a/models/employee.go +++ b/models/employee.go @@ -18,7 +18,7 @@ type Employee struct { From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"` TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"` LastLoginAt int64 `json:"last_login_at" gorm:"not null;default:0;comment:最后登录时间"` - LastLoginIP string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"` + LastLoginIp string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"` CreatedAt int64 `json:"created_at" gorm:"not null;default:0;comment:创建时间"` UpdatedAt int64 `json:"updated_at" gorm:"not null;default:0;comment:更新时间"` DeletedAt int64 `json:"deleted_at" gorm:"not null;default:0;comment:删除时间"` diff --git a/models/response/Employee.go b/models/response/Employee.go index b294987..9efb8c0 100644 --- a/models/response/Employee.go +++ b/models/response/Employee.go @@ -111,6 +111,12 @@ type UserListItem struct { Status int8 `json:"status"` SplitAccountConfigId int64 `json:"split_account_config_id"` SplitAccountConfig *SplitAccountConfigInfo `json:"split_account_config,omitempty"` // 分账配置详情 + AboutId int64 `json:"about_id"` // 租户ID + Phone string `json:"phone"` // 手机号 + From string `json:"from"` // 来源 + LastLoginIp string `json:"last_login_ip"` // 最后登录IP + Code string `json:"code"` // 机械码 + ExpireTime int64 `json:"expire_time"` // 到期时间 } // GetUserListResponse 用户列表响应 diff --git a/service/employee.go b/service/employee.go index 1885a9f..a45d604 100644 --- a/service/employee.go +++ b/service/employee.go @@ -889,7 +889,7 @@ func (s *EmployeeService) createEmployeeLevelLog(empId int64, operationType int8 }, nil } */ -func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { +/*func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { if req.Page < 1 { req.Page = 1 } @@ -971,6 +971,102 @@ func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*system items = append(items, item) } + return &systemRes.GetUserListResponse{ + List: items, + Total: total, + Page: req.Page, + PageSize: req.PageSize, + }, nil +}*/ + +func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*systemRes.GetUserListResponse, error) { + if req.Page < 1 { + req.Page = 1 + } + if req.PageSize < 1 || req.PageSize > 100 { + req.PageSize = 20 + } + + query := database.DB.Model(&models.Employee{}).Where("deleted_at = ?", 0) + + if req.Status != "" { + query = query.Where("status = ?", req.Status) + } + if req.Username != "" { + query = query.Where("username LIKE ?", "%"+req.Username+"%") + } + if req.Tel != "" { + query = query.Where("phone LIKE ?", "%"+req.Tel+"%") + } + + var total int64 + if err := query.Count(&total).Error; err != nil { + return nil, utils.NewError("查询总数失败") + } + + var employees []models.Employee + offset := (req.Page - 1) * req.PageSize + if err := query.Order("created_at DESC").Offset(offset).Limit(req.PageSize).Find(&employees).Error; err != nil { + return nil, utils.NewError("查询用户列表失败") + } + + // 收集所有需要查询的分账配置ID + splitConfigIDs := make([]int64, 0) + for _, emp := range employees { + if emp.SplitAccountConfigId > 0 { + splitConfigIDs = append(splitConfigIDs, emp.SplitAccountConfigId) + } + } + + // 批量查询分账配置 + splitConfigMap := make(map[int64]*systemRes.SplitAccountConfigInfo) + if len(splitConfigIDs) > 0 { + var splitConfigs []models.SplitAccountConfig + database.DB.Where("id IN ? AND deleted_at = ?", splitConfigIDs, 0).Find(&splitConfigs) + + for _, config := range splitConfigs { + splitConfigMap[config.ID] = &systemRes.SplitAccountConfigInfo{ + ID: config.ID, + RuleName: config.RuleName, + RuleValue: json.RawMessage(config.RuleValue), + Status: config.Status, + Description: config.Description, + CreatedBy: config.CreatedBy, + UpdatedBy: config.UpdatedBy, + CreatedAt: config.CreatedAt, + UpdatedAt: config.UpdatedAt, + } + } + } + + var items []systemRes.UserListItem + for _, emp := range employees { + item := systemRes.UserListItem{ + ID: emp.ID, + EmployeeIDStr: emp.EmployeeIDStr, + Username: emp.Username, + Name: emp.Name, + Role: emp.Role, + Status: emp.Status, + SplitAccountConfigId: emp.SplitAccountConfigId, + AboutId: emp.AboutId, + Phone: emp.Phone, + From: emp.From, + LastLoginIp: emp.LastLoginIp, + Code: emp.Code, + ExpireTime: emp.ExpireTime, + } + + // 如果有关联的分账配置,添加详情 + if emp.SplitAccountConfigId > 0 { + if config, exists := splitConfigMap[emp.SplitAccountConfigId]; exists { + item.SplitAccountConfig = config + } + } + + items = append(items, item) + } + return &systemRes.GetUserListResponse{ List: items, Total: total,