1.通过两张表employees用户表,split_account_config分账配置表,通过userlist返回关联的信息。

2.通过use_id,product_id 返回仓库里同一商品总和信息。
3.about_id,phone,from,last_login_ip,code,expire_time
 /api/userList 这个接口增加返回字段
This commit is contained in:
Administrator 2026-06-16 16:39:11 +08:00
parent 7923a99c77
commit 4d4efd79e1
3 changed files with 104 additions and 2 deletions

View File

@ -18,7 +18,7 @@ type Employee struct {
From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"` From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"`
TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"` TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"`
LastLoginAt int64 `json:"last_login_at" 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:创建时间"` CreatedAt int64 `json:"created_at" gorm:"not null;default:0;comment:创建时间"`
UpdatedAt int64 `json:"updated_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:删除时间"` DeletedAt int64 `json:"deleted_at" gorm:"not null;default:0;comment:删除时间"`

View File

@ -111,6 +111,12 @@ type UserListItem struct {
Status int8 `json:"status"` Status int8 `json:"status"`
SplitAccountConfigId int64 `json:"split_account_config_id"` SplitAccountConfigId int64 `json:"split_account_config_id"`
SplitAccountConfig *SplitAccountConfigInfo `json:"split_account_config,omitempty"` // 分账配置详情 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 用户列表响应 // GetUserListResponse 用户列表响应

View File

@ -889,7 +889,7 @@ func (s *EmployeeService) createEmployeeLevelLog(empId int64, operationType int8
}, nil }, 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 { if req.Page < 1 {
req.Page = 1 req.Page = 1
} }
@ -971,6 +971,102 @@ func (s *EmployeeService) GetUserList(req systemReq.GetUserListRequest) (*system
items = append(items, item) 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{ return &systemRes.GetUserListResponse{
List: items, List: items,
Total: total, Total: total,