将分配列表和用户关联起来

This commit is contained in:
Administrator 2026-06-15 17:51:03 +08:00
parent 1ed91f6f9a
commit 0eb07eec03
9 changed files with 133 additions and 29 deletions

View File

@ -306,3 +306,24 @@ func (r *EmployeeApi) SaveEmployeeSettings(c *gin.Context) {
systemRes.OkWithMessage("保存成功", c) 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,
})
}

View File

@ -6,7 +6,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"net/http" "net/http"
"psi/constant" "psi/constant"
"psi/database"
systemReq "psi/models/request" systemReq "psi/models/request"
systemRes "psi/models/response" systemRes "psi/models/response"
"psi/service" "psi/service"
@ -25,8 +24,8 @@ func (r *SplitAccountConfigApi) GetSplitAccountConfigList(c *gin.Context) {
ValidAndFail(constant.LoggerChannelRequest, "分账配置列表请求参数异常", "参数错误: "+err.Error(), c, err) ValidAndFail(constant.LoggerChannelRequest, "分账配置列表请求参数异常", "参数错误: "+err.Error(), c, err)
return return
} }
result, err := splitAccountConfigService.GetSplitAccountConfigList(req)
result, err := splitAccountConfigService.GetSplitAccountConfigList(req, database.GetDB(c)) //result, err := splitAccountConfigService.GetSplitAccountConfigList(req, database.GetDB(c))
if err != nil { if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置列表异常", err, c, req) utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置列表异常", err, c, req)
return return
@ -61,7 +60,8 @@ func (r *SplitAccountConfigApi) GetSplitAccountConfigDetail(c *gin.Context) {
return 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 { if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置详情异常", err, c, gin.H{"id": id}) utils.FailWithRequestLog(constant.LoggerChannelWork, "分账配置详情异常", err, c, gin.H{"id": id})
return return
@ -80,7 +80,8 @@ func (r *SplitAccountConfigApi) CreateSplitAccountConfig(c *gin.Context) {
} }
userInfo := utils.GetUserInfo(c) 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 { if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "创建分账配置异常", err, c, req) utils.FailWithRequestLog(constant.LoggerChannelWork, "创建分账配置异常", err, c, req)
return return
@ -98,7 +99,8 @@ func (r *SplitAccountConfigApi) UpdateSplitAccountConfig(c *gin.Context) {
} }
userInfo := utils.GetUserInfo(c) 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 { if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "更新分账配置异常", err, c, req) utils.FailWithRequestLog(constant.LoggerChannelWork, "更新分账配置异常", err, c, req)
return return
@ -117,7 +119,8 @@ func (r *SplitAccountConfigApi) DeleteSplitAccountConfig(c *gin.Context) {
} }
userInfo := utils.GetUserInfo(c) 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 { if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "删除分账配置异常", err, c, req) utils.FailWithRequestLog(constant.LoggerChannelWork, "删除分账配置异常", err, c, req)
return return

View File

@ -2,26 +2,27 @@ package models
// Employee 员工 // Employee 员工
type Employee struct { type Employee struct {
ID int64 `json:"id" gorm:"primarykey;comment:自增ID"` ID int64 `json:"id" gorm:"primarykey;comment:自增ID"`
EmployeeIDStr string `json:"employee_id_str" gorm:"size:10;not null;uniqueIndex"` // 工号 EmployeeIDStr string `json:"employee_id_str" gorm:"size:10;not null;uniqueIndex"` // 工号
Fid int64 `json:"fid" gorm:"not null;default:0;comment:父级id"` Fid int64 `json:"fid" gorm:"not null;default:0;comment:父级id"`
AboutId int64 `json:"about_id" 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:机械码"` Code string `json:"code" gorm:"size:64;not null;default:'';comment:机械码"`
Username string `json:"username" gorm:"size:50;not null;default:'';comment:登录账号 (init_工号)"` Username string `json:"username" gorm:"size:50;not null;default:'';comment:登录账号 (init_工号)"`
Password string `json:"password" gorm:"size:100;not null;default:'';comment:密码"` Password string `json:"password" gorm:"size:100;not null;default:'';comment:密码"`
Name string `json:"name" gorm:"size:50;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:手机号"` Phone string `json:"phone" gorm:"size:11;not null;default:'';comment:手机号"`
Role int64 `json:"role" gorm:"not null;default:0;comment:权限"` Role int64 `json:"role" gorm:"not null;default:0;comment:权限"`
Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1正常 0禁用"` Status int8 `json:"status" gorm:"not null;default:1;comment:状态 1正常 0禁用"`
Score int64 `json:"score" gorm:"not null;default:0;comment:积分"` Score int64 `json:"score" gorm:"not null;default:0;comment:积分"`
From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"` SplitAccountConfigId int64 `json:"split_account_config_id" gorm:"not null;default:0;comment:分账配置ID"`
TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"` From string `json:"from" gorm:"size:50;not null;default:'';comment:来源"`
LastLoginAt int64 `json:"last_login_at" gorm:"not null;default:0;comment:最后登录时间"` TypeId int8 `json:"type_id" gorm:"not null;default:0;comment:关联类型"`
LastLoginIP string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"` LastLoginAt int64 `json:"last_login_at" gorm:"not null;default:0;comment:最后登录时间"`
CreatedAt int64 `json:"created_at" gorm:"not null;default:0;comment:创建时间"` LastLoginIP string `json:"last_login_ip" gorm:"size:20;not null;default:'';comment:最后登录ip"`
UpdatedAt int64 `json:"updated_at" gorm:"not null;default:0;comment:更新时间"` CreatedAt int64 `json:"created_at" gorm:"not null;default:0;comment:创建时间"`
DeletedAt int64 `json:"deleted_at" gorm:"not null;default:0;comment:删除时间"` UpdatedAt int64 `json:"updated_at" gorm:"not null;default:0;comment:更新时间"`
ExpireTime int64 `json:"expire_time" 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 { func (Employee) TableName() string {

View File

@ -62,3 +62,11 @@ type SetEmployeeLevelRequest struct {
OperationType int8 `form:"operation_type" binding:"required,oneof=1 2 3"` // 操作类型(1:开通,2:升级,3:续费) OperationType int8 `form:"operation_type" binding:"required,oneof=1 2 3"` // 操作类型(1:开通,2:升级,3:续费)
Duration int64 `form:"duration" binding:"required,min=1"` // 时长(月数)按30天/月计算 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"`
}

View File

@ -99,3 +99,22 @@ type EmployeeLevelConfigResponse struct {
Price int64 `json:"price"` // 价格(单位:分) Price int64 `json:"price"` // 价格(单位:分)
LevelName string `json:"level_name"` // 等级名称 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"`
}

View File

@ -6,7 +6,7 @@ import "gorm.io/datatypes"
type SplitAccountConfig struct { type SplitAccountConfig struct {
ID int64 `json:"id" gorm:"primarykey;comment:主键ID"` ID int64 `json:"id" gorm:"primarykey;comment:主键ID"`
RuleName string `json:"rule_name" gorm:"size:200;not null;default:'';comment:分账规则配置名称"` 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-启用"` Status int8 `json:"status" gorm:"type:tinyint(1);default:1;comment:状态0-禁用1-启用"`
Description string `json:"description" gorm:"size:500;comment:配置描述"` Description string `json:"description" gorm:"size:500;comment:配置描述"`
CreatedBy string `json:"created_by" gorm:"size:100;comment:创建人"` CreatedBy string `json:"created_by" gorm:"size:100;comment:创建人"`

View File

@ -8,7 +8,7 @@ type SplitAccountDeductionLog struct {
BusinessNo string `json:"business_no" gorm:"size:64;not null;default:'';comment:订单号"` BusinessNo string `json:"business_no" gorm:"size:64;not null;default:'';comment:订单号"`
ConfigID int64 `json:"config_id" gorm:"not null;default:0;comment:分账配置ID"` ConfigID int64 `json:"config_id" gorm:"not null;default:0;comment:分账配置ID"`
ConfigName string `json:"config_name" gorm:"size:200;not null;default:'';comment:分账配置名称"` 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:总金额(分账前)"` 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:扣款总金额"` 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:剩余金额(分账后)"` RemainingAmount float64 `json:"remaining_amount" gorm:"type:decimal(15,2);not null;default:0.00;comment:剩余金额(分账后)"`

View File

@ -98,6 +98,7 @@ func initRouter() (r *gin.Engine) {
// 管理员 // 管理员
auth.GET("/user/current", employeeApi.GetCurrentUser) // 获取当前用户信息 auth.GET("/user/current", employeeApi.GetCurrentUser) // 获取当前用户信息
auth.POST("/logout", employeeApi.Logout) // 登出 auth.POST("/logout", employeeApi.Logout) // 登出
auth.POST("/userList", employeeApi.GetUserList) // 获取用户列表
// 配置管理 // 配置管理
auth.GET("/config/list", configApi.GetConfigList) // 获取配置列表 auth.GET("/config/list", configApi.GetConfigList) // 获取配置列表
auth.GET("/config/detail/:id", configApi.GetConfigDetail) // 获取配置详情 auth.GET("/config/detail/:id", configApi.GetConfigDetail) // 获取配置详情

View File

@ -837,3 +837,54 @@ func (s *EmployeeService) createEmployeeLevelLog(empId int64, operationType int8
return nil 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
}