From 0eb07eec03a054ee0f86a181a60a9f91a11ba5d7 Mon Sep 17 00:00:00 2001 From: Administrator <1269936630@qq.com> Date: Mon, 15 Jun 2026 17:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=88=86=E9=85=8D=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E5=85=B3=E8=81=94=E8=B5=B7=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/employee.go | 21 +++++++++++ controllers/split_account_config.go | 17 +++++---- models/employee.go | 41 ++++++++++----------- models/request/Employee.go | 8 +++++ models/response/Employee.go | 19 ++++++++++ models/split_account_config.go | 2 +- models/split_account_deduction_log.go | 2 +- routes/routes.go | 1 + service/employee.go | 51 +++++++++++++++++++++++++++ 9 files changed, 133 insertions(+), 29 deletions(-) diff --git a/controllers/employee.go b/controllers/employee.go index da1a015..5e8f325 100644 --- a/controllers/employee.go +++ b/controllers/employee.go @@ -306,3 +306,24 @@ func (r *EmployeeApi) SaveEmployeeSettings(c *gin.Context) { systemRes.OkWithMessage("保存成功", c) } + +// GetUserList 获取用户列表 +func (r *EmployeeApi) GetUserList(c *gin.Context) { + var req systemReq.GetUserListRequest + + if err := c.ShouldBind(&req); err != nil { + ValidAndFail(constant.LoggerChannelRequest, "获取用户列表请求参数异常", "参数错误: "+err.Error(), c, err) + return + } + + result, err := employeeService.GetUserList(req) + if err != nil { + utils.FailWithRequestLog(constant.LoggerChannelWork, "获取用户列表异常", err, c, req) + return + } + + c.JSON(http.StatusOK, gin.H{ + "code": 200, + "data": result, + }) +} diff --git a/controllers/split_account_config.go b/controllers/split_account_config.go index 56d6902..e8a8be6 100644 --- a/controllers/split_account_config.go +++ b/controllers/split_account_config.go @@ -6,7 +6,6 @@ import ( "github.com/sirupsen/logrus" "net/http" "psi/constant" - "psi/database" systemReq "psi/models/request" systemRes "psi/models/response" "psi/service" @@ -25,8 +24,8 @@ func (r *SplitAccountConfigApi) GetSplitAccountConfigList(c *gin.Context) { ValidAndFail(constant.LoggerChannelRequest, "分账配置列表请求参数异常", "参数错误: "+err.Error(), c, err) return } - - result, err := splitAccountConfigService.GetSplitAccountConfigList(req, database.GetDB(c)) + result, err := splitAccountConfigService.GetSplitAccountConfigList(req) + //result, err := splitAccountConfigService.GetSplitAccountConfigList(req, database.GetDB(c)) if err != nil { utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置列表异常", err, c, req) return @@ -61,7 +60,8 @@ func (r *SplitAccountConfigApi) GetSplitAccountConfigDetail(c *gin.Context) { return } - result, err := splitAccountConfigService.GetSplitAccountConfigDetail(id, database.GetDB(c)) + //result, err := splitAccountConfigService.GetSplitAccountConfigDetail(id, database.GetDB(c)) + result, err := splitAccountConfigService.GetSplitAccountConfigDetail(id) if err != nil { utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置详情异常", err, c, gin.H{"id": id}) return @@ -80,7 +80,8 @@ func (r *SplitAccountConfigApi) CreateSplitAccountConfig(c *gin.Context) { } userInfo := utils.GetUserInfo(c) - id, err := splitAccountConfigService.CreateSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) + id, err := splitAccountConfigService.CreateSplitAccountConfig(req, userInfo.Username) + //id, err := splitAccountConfigService.CreateSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) if err != nil { utils.FailWithRequestLog(constant.LoggerChannelWork, "创建分账配置异常", err, c, req) return @@ -98,7 +99,8 @@ func (r *SplitAccountConfigApi) UpdateSplitAccountConfig(c *gin.Context) { } userInfo := utils.GetUserInfo(c) - err := splitAccountConfigService.UpdateSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) + err := splitAccountConfigService.UpdateSplitAccountConfig(req, userInfo.Username) + //err := splitAccountConfigService.UpdateSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) if err != nil { utils.FailWithRequestLog(constant.LoggerChannelWork, "更新分账配置异常", err, c, req) return @@ -117,7 +119,8 @@ func (r *SplitAccountConfigApi) DeleteSplitAccountConfig(c *gin.Context) { } userInfo := utils.GetUserInfo(c) - err := splitAccountConfigService.DeleteSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) + err := splitAccountConfigService.DeleteSplitAccountConfig(req, userInfo.Username) + //err := splitAccountConfigService.DeleteSplitAccountConfig(req, userInfo.Username, database.GetDB(c)) if err != nil { utils.FailWithRequestLog(constant.LoggerChannelWork, "删除分账配置异常", err, c, req) return diff --git a/models/employee.go b/models/employee.go index 1994fc1..7afd27d 100644 --- a/models/employee.go +++ b/models/employee.go @@ -2,26 +2,27 @@ package models // Employee 员工 type Employee struct { - ID int64 `json:"id" gorm:"primarykey;comment:自增ID"` - EmployeeIDStr string `json:"employee_id_str" gorm:"size:10;not null;uniqueIndex"` // 工号 - Fid int64 `json:"fid" gorm:"not null;default:0;comment:父级id"` - AboutId int64 `json:"about_id" gorm:"not null;default:0;comment:关联id"` - Code string `json:"code" gorm:"size:64;not null;default:'';comment:机械码"` - Username string `json:"username" gorm:"size:50;not null;default:'';comment:登录账号 (init_工号)"` - Password string `json:"password" gorm:"size:100;not null;default:'';comment:密码"` - Name string `json:"name" gorm:"size:50;not null;default:'';comment:姓名"` - Phone string `json:"phone" gorm:"size:11;not null;default:'';comment:手机号"` - Role int64 `json:"role" gorm:"not null;default:0;comment:权限"` - Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1正常 0禁用"` - Score int64 `json:"score" gorm:"not null;default:0;comment:积分"` - 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"` - 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:删除时间"` - ExpireTime int64 `json:"expire_time" gorm:"not null;default:0;comment:过期时间"` + ID int64 `json:"id" gorm:"primarykey;comment:自增ID"` + EmployeeIDStr string `json:"employee_id_str" gorm:"size:10;not null;uniqueIndex"` // 工号 + Fid int64 `json:"fid" gorm:"not null;default:0;comment:父级id"` + AboutId int64 `json:"about_id" gorm:"not null;default:0;comment:关联id"` + Code string `json:"code" gorm:"size:64;not null;default:'';comment:机械码"` + Username string `json:"username" gorm:"size:50;not null;default:'';comment:登录账号 (init_工号)"` + Password string `json:"password" gorm:"size:100;not null;default:'';comment:密码"` + Name string `json:"name" gorm:"size:50;not null;default:'';comment:姓名"` + Phone string `json:"phone" gorm:"size:11;not null;default:'';comment:手机号"` + Role int64 `json:"role" gorm:"not null;default:0;comment:权限"` + Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1正常 0禁用"` + Score int64 `json:"score" gorm:"not null;default:0;comment:积分"` + SplitAccountConfigId int64 `json:"split_account_config_id" gorm:"not null;default:0;comment:分账配置ID"` + 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"` + 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:删除时间"` + ExpireTime int64 `json:"expire_time" gorm:"not null;default:0;comment:过期时间"` } func (Employee) TableName() string { diff --git a/models/request/Employee.go b/models/request/Employee.go index 629116c..daa6607 100644 --- a/models/request/Employee.go +++ b/models/request/Employee.go @@ -62,3 +62,11 @@ type SetEmployeeLevelRequest struct { OperationType int8 `form:"operation_type" binding:"required,oneof=1 2 3"` // 操作类型(1:开通,2:升级,3:续费) Duration int64 `form:"duration" binding:"required,min=1"` // 时长(月数),按30天/月计算 } + +// GetUserListRequest 获取用户列表请求 +type GetUserListRequest struct { + Page int `form:"page"` + PageSize int `form:"page_size"` + Keyword string `form:"keyword"` + Status string `form:"status"` +} diff --git a/models/response/Employee.go b/models/response/Employee.go index 899290a..1c2e1c1 100644 --- a/models/response/Employee.go +++ b/models/response/Employee.go @@ -99,3 +99,22 @@ type EmployeeLevelConfigResponse struct { Price int64 `json:"price"` // 价格(单位:分) LevelName string `json:"level_name"` // 等级名称 } + +// UserListItem 用户列表项 +type UserListItem struct { + ID int64 `json:"id"` + EmployeeIDStr string `json:"employee_id_str"` + Username string `json:"username"` + Name string `json:"name"` + Role int64 `json:"role"` + Status int8 `json:"status"` + SplitAccountConfigId int64 `json:"split_account_config_id"` +} + +// GetUserListResponse 用户列表响应 +type GetUserListResponse struct { + List []UserListItem `json:"list"` + Total int64 `json:"total"` + Page int `json:"page"` + PageSize int `json:"page_size"` +} diff --git a/models/split_account_config.go b/models/split_account_config.go index 6b3aa55..c78b741 100644 --- a/models/split_account_config.go +++ b/models/split_account_config.go @@ -6,7 +6,7 @@ import "gorm.io/datatypes" type SplitAccountConfig struct { ID int64 `json:"id" gorm:"primarykey;comment:主键ID"` RuleName string `json:"rule_name" gorm:"size:200;not null;default:'';comment:分账规则配置名称"` - RuleValue datatypes.JSON `json:"rule_value" gorm:"type:json;not null;comment:分账规则配置(JSON格式)"` + RuleValue datatypes.JSON `json:"rule_value" gorm:"type:json;comment:分账规则配置(JSON格式)"` Status int8 `json:"status" gorm:"type:tinyint(1);default:1;comment:状态:0-禁用,1-启用"` Description string `json:"description" gorm:"size:500;comment:配置描述"` CreatedBy string `json:"created_by" gorm:"size:100;comment:创建人"` diff --git a/models/split_account_deduction_log.go b/models/split_account_deduction_log.go index 081bba9..6326eaa 100644 --- a/models/split_account_deduction_log.go +++ b/models/split_account_deduction_log.go @@ -8,7 +8,7 @@ type SplitAccountDeductionLog struct { BusinessNo string `json:"business_no" gorm:"size:64;not null;default:'';comment:订单号"` ConfigID int64 `json:"config_id" gorm:"not null;default:0;comment:分账配置ID"` ConfigName string `json:"config_name" gorm:"size:200;not null;default:'';comment:分账配置名称"` - DeductionDetails datatypes.JSON `json:"deduction_details" gorm:"type:json;not null;comment:扣款规则(JSON数组)"` + DeductionDetails datatypes.JSON `json:"deduction_details" gorm:"type:json;comment:扣款规则(JSON数组)"` TotalAmount float64 `json:"total_amount" gorm:"type:decimal(15,2);not null;default:0.00;comment:总金额(分账前)"` DeductionAmount float64 `json:"deduction_amount" gorm:"type:decimal(15,2);not null;default:0.00;comment:扣款总金额"` RemainingAmount float64 `json:"remaining_amount" gorm:"type:decimal(15,2);not null;default:0.00;comment:剩余金额(分账后)"` diff --git a/routes/routes.go b/routes/routes.go index 78f29b6..10495ab 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -98,6 +98,7 @@ func initRouter() (r *gin.Engine) { // 管理员 auth.GET("/user/current", employeeApi.GetCurrentUser) // 获取当前用户信息 auth.POST("/logout", employeeApi.Logout) // 登出 + auth.POST("/userList", employeeApi.GetUserList) // 获取用户列表 // 配置管理 auth.GET("/config/list", configApi.GetConfigList) // 获取配置列表 auth.GET("/config/detail/:id", configApi.GetConfigDetail) // 获取配置详情 diff --git a/service/employee.go b/service/employee.go index 25e6f13..fa1d005 100644 --- a/service/employee.go +++ b/service/employee.go @@ -837,3 +837,54 @@ func (s *EmployeeService) createEmployeeLevelLog(empId int64, operationType int8 return nil } + +// GetUserList 获取用户列表(主库) +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.Keyword != "" { + query = query.Where("(employee_id_str = ? OR name LIKE ? OR username LIKE ?)", + req.Keyword, "%"+req.Keyword+"%", "%"+req.Keyword+"%") + } + + 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("查询用户列表失败") + } + + var items []systemRes.UserListItem + for _, emp := range employees { + items = append(items, systemRes.UserListItem{ + ID: emp.ID, + EmployeeIDStr: emp.EmployeeIDStr, + Username: emp.Username, + Name: emp.Name, + Role: emp.Role, + Status: emp.Status, + SplitAccountConfigId: emp.SplitAccountConfigId, + }) + } + + return &systemRes.GetUserListResponse{ + List: items, + Total: total, + Page: req.Page, + PageSize: req.PageSize, + }, nil +}