# Conflicts: # docs/docs.go # docs/swagger.json # docs/swagger.yaml # go.modmaster
@@ -0,0 +1,19 @@ | |||
package enum | |||
type RoleState int32 | |||
const ( | |||
RoleStateForNormal = 1 | |||
RoleStateForFreeze = 2 | |||
) | |||
func (gt RoleState) String() string { | |||
switch gt { | |||
case RoleStateForNormal: | |||
return "正常" | |||
case RoleStateForFreeze: | |||
return "冻结" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -17,11 +17,21 @@ import ( | |||
"strings" | |||
) | |||
// MenuList | |||
// @Summary 通用请求-权限列表-菜单栏列表(获取) | |||
// @Tags 权限列表 | |||
// @Description 菜单栏列表(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Success 200 {object} map[string]interface{} "具体路由" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/comm/getMenuList [POST] | |||
func MenuList(c *gin.Context) { | |||
engine := db.Db | |||
admin := svc.GetUser(c) | |||
qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine) | |||
groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2() | |||
groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
@@ -146,7 +146,8 @@ func GetGrowData(c *gin.Context) { | |||
return | |||
} | |||
kind := req.Kind | |||
var yData []interface{} | |||
var xData []interface{} | |||
now := time.Now() | |||
dataDb := implement.NewPlatformGrowDataDb(db.Db) | |||
m, has, err := dataDb.PlatformGrowDataGetLastOne() | |||
@@ -155,11 +156,14 @@ func GetGrowData(c *gin.Context) { | |||
return | |||
} | |||
if !has { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到数据") | |||
resp := md.GetPriceCurveResp{ | |||
XData: xData, | |||
YData: yData, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
return | |||
} | |||
var yData []interface{} | |||
var xData []interface{} | |||
switch kind { | |||
case "1": | |||
// 日 | |||
@@ -0,0 +1,652 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/lib/validate" | |||
"applet/app/md" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
// PermissionGroupList | |||
// @Summary 权限组列表 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-权限组列表 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @param adm_id query string true "管理员id" | |||
// @Success 200 {string} "具体看返回内容" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/permissionGroupList [GET] | |||
func PermissionGroupList(c *gin.Context) { | |||
roleId := c.DefaultQuery("role_id", "") | |||
engine := db.Db | |||
qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine) | |||
groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
roleDb := implement.NewRoleDb(engine, utils.StrToInt(roleId)) | |||
list, _, err := roleDb.FindPermissionGroupByRole(utils.StrToInt(roleId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var isHasPermissionGroupId []string | |||
for _, v := range list { | |||
isHasPermissionGroupId = append(isHasPermissionGroupId, utils.IntToStr(v.PermissionGroup.Id)) | |||
} | |||
var tempRespMap = map[string]*md.PermissionGroupListResp{} | |||
var tempRespMapKeys []string | |||
for _, v := range *groupList { | |||
isCheck := false | |||
if utils.InArr(utils.IntToStr(v.Id), isHasPermissionGroupId) { | |||
isCheck = true | |||
} | |||
tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{ | |||
Id: v.Id, | |||
Name: v.Name, | |||
Key: v.Key, | |||
State: v.State, | |||
ParentId: v.ParentId, | |||
CreateAt: v.CreateAt, | |||
UpdateAt: v.UpdateAt, | |||
IsCheck: isCheck, | |||
} | |||
tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id)) | |||
} | |||
for _, v := range tempRespMap { | |||
if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 { | |||
tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v) | |||
} | |||
} | |||
for _, v := range tempRespMap { | |||
if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 { | |||
tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v) | |||
} | |||
} | |||
var resp []*md.PermissionGroupListResp | |||
for _, v := range tempRespMapKeys { | |||
if tempRespMap[v].ParentId == 0 { | |||
resp = append(resp, tempRespMap[v]) | |||
} | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": resp, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(), | |||
"value": enum.PermissionGroupStateForNormal, | |||
}, | |||
{ | |||
"name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(), | |||
"value": enum.PermissionGroupStateForDiscard, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
// RoleList | |||
// @Summary 角色列表 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-角色列表 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Success 200 {string} "具体看返回内容" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/roleList [GET] | |||
func RoleList(c *gin.Context) { | |||
engine := db.Db | |||
roleDb := implement.NewRoleDb(engine, 0) | |||
roleList, err := roleDb.FindRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
adminRoleDb := implement.NewAdminRoleDb(engine) | |||
adminDb := implement.NewAdminDb(engine) | |||
var result []*md.RoleListResp | |||
for _, v := range *roleList { | |||
var temp md.RoleListResp | |||
temp.Data = v | |||
adminRoles, err1 := adminRoleDb.FindAdminRoleByRoleId(v.Id) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
for _, adminRole := range *adminRoles { | |||
admin, err2 := adminDb.GetAdmin(adminRole.AdmId) | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
temp.AdminList = append(temp.AdminList, struct { | |||
Name string `json:"name"` | |||
}{ | |||
Name: admin.Username, | |||
}) | |||
} | |||
result = append(result, &temp) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": result, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
// AddRole | |||
// @Summary 添加角色 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-添加角色 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.AddRoleReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/addRole [POST] | |||
func AddRole(c *gin.Context) { | |||
var req md.AddRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
roleDb := implement.NewRoleDb(engine, 0) | |||
now := time.Now() | |||
_, err = roleDb.RoleInsert(&model.Role{ | |||
Name: req.Name, | |||
State: enum.RoleStateForNormal, | |||
Memo: req.Memo, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// UpdateRole | |||
// @Summary 修改角色 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-修改角色 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.UpdateRoleReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/updateRole [POST] | |||
func UpdateRole(c *gin.Context) { | |||
var req md.UpdateRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
roleDb := implement.NewRoleDb(engine, req.RoleId) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
role.Name = req.Name | |||
role.Memo = req.Memo | |||
_, err = roleDb.UpdateRole(role, "name", "memo") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// RoleBindPermissionGroup | |||
// @Summary 角色绑定权限组 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-角色绑定权限组 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.RoleBindPermissionGroupReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/roleBindPermissionGroup [POST] | |||
func RoleBindPermissionGroup(c *gin.Context) { | |||
var req md.RoleBindPermissionGroupReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.RoleBindPermissionGroup(req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// UpdateRoleState | |||
// @Summary 修改角色状态 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-修改角色状态 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.UpdateRoleStateReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/updateRoleState [POST] | |||
func UpdateRoleState(c *gin.Context) { | |||
var req md.UpdateRoleStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
roleDb := implement.NewRoleDb(engine, req.RoleId) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
role.State = req.State | |||
_, err = roleDb.UpdateRole(role, "state") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// DeleteRole | |||
// @Summary 删除角色 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-删除角色 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.UpdateRoleStateReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/deleteRole/{$id} [DELETE] | |||
func DeleteRole(c *gin.Context) { | |||
id := c.Param("id") | |||
engine := db.Db | |||
roleDb := implement.NewRoleDb(engine, utils.StrToInt(id)) | |||
role, err := roleDb.GetRole() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if role == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
err = svc.DeleteRole(c, utils.StrToInt(id)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// AdminList | |||
// @Summary 管理员列表 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-管理员列表 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.AdminListReq true "请求参数" | |||
// @Success 200 {string} "具体看返回内容" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/adminList [POST] | |||
func AdminList(c *gin.Context) { | |||
var req md.AdminListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
if req.Limit == 0 { | |||
req.Limit = 10 | |||
} | |||
if req.Page == 0 { | |||
req.Page = 10 | |||
} | |||
engine := db.Db | |||
adminDb := implement.NewAdminDb(engine) | |||
adminList, total, err := adminDb.FindAdmin(req.UserName, req.State, req.Page, req.Limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var result []md.AdminListResp | |||
for _, v := range adminList { | |||
permissionGroupList, _, err1 := adminDb.FindAdminRolePermissionGroup(v.AdmId) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
var roleList []string | |||
for _, v1 := range permissionGroupList { | |||
roleList = append(roleList, v1.Role.Name) | |||
} | |||
result = append(result, md.AdminListResp{ | |||
AdmId: v.AdmId, | |||
Username: v.Username, | |||
State: v.State, | |||
IsSuperAdministrator: v.IsSuperAdministrator, | |||
Memo: v.Memo, | |||
CreateAt: v.CreateAt, | |||
UpdateAt: v.UpdateAt, | |||
RoleList: roleList, | |||
}) | |||
} | |||
e.OutSuc(c, map[string]interface{}{ | |||
"list": result, | |||
"total": total, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} | |||
// UpdateAdminState | |||
// @Summary 修改管理员状态 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-修改管理员状态 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.UpdateAdminStateReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/updateAdminState [POST] | |||
func UpdateAdminState(c *gin.Context) { | |||
var req md.UpdateAdminStateReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
admDb := implement.NewAdminDb(engine) | |||
admin, err := admDb.GetAdmin(req.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if admin == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
admin.State = req.State | |||
_, err = admDb.UpdateAdmin(admin, "state") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// UpdateAdmin | |||
// @Summary 修改管理员信息 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-修改管理员信息 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.UpdateAdminReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/updateAdmin [POST] | |||
func UpdateAdmin(c *gin.Context) { | |||
var req md.UpdateAdminReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
admDb := implement.NewAdminDb(engine) | |||
admin, err := admDb.GetAdmin(req.AdmId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if admin == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") | |||
return | |||
} | |||
admin.Username = req.Username | |||
admin.Memo = req.Memo | |||
if req.Password != "" { | |||
admin.Password = utils.Md5(req.Password) | |||
} | |||
_, err = admDb.UpdateAdmin(admin, "username", "memo", "password", "show_time") | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// AddAdmin | |||
// @Summary 新增管理员 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-新增管理员 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.AddAdminReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/addAdmin [POST] | |||
func AddAdmin(c *gin.Context) { | |||
var req md.AddAdminReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
engine := db.Db | |||
admDb := implement.NewAdminDb(engine) | |||
isHasAdmin, err := admDb.GetAdminByUserName(req.Username) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if isHasAdmin != nil { | |||
e.OutErr(c, e.ERR, "当前用户名已存在,请勿重复添加") | |||
return | |||
} | |||
admId, err := admDb.CreateAdminId() | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
admin := model.Admin{ | |||
AdmId: admId, | |||
Username: req.Username, | |||
Password: utils.Md5(req.Password), | |||
State: enum.AdminStateForNormal, | |||
IsSuperAdministrator: 0, | |||
Memo: req.Memo, | |||
CreateAt: time.Now().Format("2006-01-02 15:04:05"), | |||
UpdateAt: time.Now().Format("2006-01-02 15:04:05"), | |||
} | |||
_, err = admDb.AdminInsert(&admin) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// DeleteAdmin | |||
// @Summary 删除管理员 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-删除管理员 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/deleteAdmin/{$adm_id} [DELETE] | |||
func DeleteAdmin(c *gin.Context) { | |||
admId := c.Param("adm_id") | |||
err := svc.AdminDelete([]int{utils.StrToInt(admId)}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// BindAdminRole | |||
// @Summary 管理员绑定角色 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-管理员绑定角色 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @Param args body md.BindAdminRoleReq true "请求参数" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/bindAdminRole [POST] | |||
func BindAdminRole(c *gin.Context) { | |||
var req md.BindAdminRoleReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
err = svc.BindAdminRole(c, req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// AdminInfo | |||
// @Summary 管理员信息 | |||
// @Tags 权限管理 | |||
// @Description 权限管理-管理员信息 | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Accept json | |||
// @Produce json | |||
// @param adm_id query string true "管理员id" | |||
// @Success 200 {string} "具体看返回内容" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/role/adminInfo [GET] | |||
func AdminInfo(c *gin.Context) { | |||
admId := c.DefaultQuery("adm_id", "") | |||
engine := db.Db | |||
admDb := implement.NewAdminDb(engine) | |||
admin, err := admDb.GetAdmin(utils.StrToInt(admId)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
admin.Password = "" | |||
e.OutSuc(c, map[string]interface{}{ | |||
"info": admin, | |||
"state": []map[string]interface{}{ | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForNormal).String(), | |||
"value": enum.RoleStateForNormal, | |||
}, | |||
{ | |||
"name": enum.RoleState(enum.RoleStateForFreeze).String(), | |||
"value": enum.RoleStateForFreeze, | |||
}, | |||
}, | |||
}, nil) | |||
return | |||
} |
@@ -30,34 +30,11 @@ func GetLevelList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level" | |||
results, err := db.QueryNativeString(db.Db, sql) | |||
list, total, err := svc.LevelManagementGetLevelList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var countMap = map[int]string{} | |||
for _, res := range results { | |||
countMap[utils.StrToInt(res["level"])] = res["total"] | |||
} | |||
list := make([]md2.LevelListNode, len(levels)) | |||
for i, level := range levels { | |||
list[i].LevelWeight = level.LevelWeight | |||
list[i].LevelID = level.Id | |||
list[i].LevelName = level.LevelName | |||
list[i].Count = countMap[level.Id] | |||
list[i].CreateAt = level.CreateAt | |||
list[i].IsUse = level.IsUse | |||
list[i].Memo = level.Memo | |||
} | |||
resp := md2.GetLevelListResp{ | |||
List: list, | |||
@@ -165,6 +142,21 @@ func UpdateLevel(c *gin.Context) { | |||
forceColumns = append(forceColumns, "level_weight") | |||
} | |||
if req.IsUse == "0" || req.IsUse == "1" { | |||
// 判断当前该等级有没有被使用 | |||
userDb := implement.NewUserDb(db.Db) | |||
has, err := userDb.UserExistByParams(map[string]interface{}{ | |||
"key": "level", | |||
"value": req.IsUse, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if has { | |||
e.OutErr(c, e.ERR, errors.New("该等级下存在会员,无法关闭该会员等级,请移除对应等级下会员或将会员移动到其他等级").Error()) | |||
return | |||
} | |||
level.LevelWeight = utils.StrToInt(req.IsUse) | |||
forceColumns = append(forceColumns, "is_use") | |||
} | |||
@@ -201,10 +193,12 @@ func UpdateLevel(c *gin.Context) { | |||
} | |||
// 2.2 添加更新后的任务 | |||
err = svc.BatchAddLevelTask(session, req.UserLevelTasks, utils.StrToInt(req.LevelID)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
if len(req.UserLevelTasks) > 0 { | |||
err = svc.BatchAddLevelTask(session, req.UserLevelTasks, utils.StrToInt(req.LevelID)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
} | |||
err = session.Commit() | |||
@@ -262,10 +256,12 @@ func AddLevel(c *gin.Context) { | |||
} | |||
// 2. 创建任务信息 | |||
err = svc.BatchAddLevelTask(session, req.UserLevelTasks, id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
if len(req.UserLevelTasks) > 0 { | |||
err = svc.BatchAddLevelTask(session, req.UserLevelTasks, id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
} | |||
err = session.Commit() | |||
@@ -4,9 +4,11 @@ import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
md2 "applet/app/md/member_center" | |||
svc "applet/app/svc/member_center" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
"errors" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
@@ -27,34 +29,12 @@ func GetTagList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
sql := "SElECT count(distinct uid) as total, tag_id FROM `user_tag_records` GROUP BY tag_id" | |||
results, err := db.QueryNativeString(db.Db, sql) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var countMap = map[int64]string{} | |||
for _, res := range results { | |||
countMap[utils.StrToInt64(res["tag_id"])] = res["total"] | |||
} | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
tags, total, err := tagDb.UserTagAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit)) | |||
list, total, err := svc.TagManagementGetList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
list := make([]md2.TagListNode, len(*tags)) | |||
for i, tag := range *tags { | |||
list[i].Name = tag.TagName | |||
list[i].Count = countMap[int64(tag.Id)] | |||
list[i].CreateAt = tag.CreateAt | |||
list[i].Memo = tag.Memo | |||
list[i].TagID = utils.IntToStr(tag.Id) | |||
list[i].IsPunish = tag.IsPunish | |||
} | |||
resp := md2.GetTagListResp{ | |||
List: list, | |||
Paginate: md2.Paginate{ | |||
@@ -119,16 +99,43 @@ func UpdateTag(c *gin.Context) { | |||
return | |||
} | |||
tagID := utils.StrToInt(req.TagID) | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
oldTag, err := tagDb.UserTagGetOneByParams(map[string]interface{}{"key": "id", "value": tagID}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if oldTag == nil { | |||
e.OutErr(c, e.ERR_NO_DATA, errors.New("标签不存在").Error()) | |||
return | |||
} | |||
if req.IsPunish != "" && oldTag.IsPunish != utils.StrToInt(req.IsPunish) { | |||
// 标签在被使用情况下不允许修改是否为处罚标签 | |||
recordsDb := implement.NewUserTagRecordsDb(db.Db) | |||
exist, err := recordsDb.UserTagRecordsExist(0, tagID) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if exist { | |||
e.OutErr(c, e.ERR, errors.New("该标签已被使用,无法修改是否为处罚标签").Error()) | |||
return | |||
} | |||
} | |||
tag := &model.UserTag{ | |||
Id: tagID, | |||
TagName: req.Name, | |||
Memo: req.Memo, | |||
Id: tagID, | |||
} | |||
if req.Name != "" { | |||
tag.TagName = req.Name | |||
} | |||
if req.Memo != "" { | |||
tag.Memo = req.Memo | |||
} | |||
forceColumns := []string{"tag_name", "memo", "is_punish"} | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
affected, err := tagDb.UserTagUpdate(tagID, tag, forceColumns...) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
@@ -160,7 +167,17 @@ func DeleteTag(c *gin.Context) { | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
_, err := tagDb.UserTagDeleteBySession(session, req.TagID) | |||
isUsed, err := recordsDb.UserTagRecordsIsUsedBySession(session, utils.StrToInt(req.TagID)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if isUsed { | |||
e.OutErr(c, e.ERR, errors.New("该标签已被使用,无法删除").Error()) | |||
return | |||
} | |||
_, err = tagDb.UserTagDeleteBySession(session, req.TagID) | |||
if err != nil { | |||
session.Rollback() | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
@@ -75,13 +75,13 @@ func UserManagementGetUserList(c *gin.Context) { | |||
}, | |||
} | |||
users, total, err3 := svc.UserManagementGetUsers(db.Db, req) | |||
users, total, err3 := svc.UserManagementGetUsers(req) | |||
if err3 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) | |||
return | |||
} | |||
userIDs := make([]int64, len(*users)) | |||
for i, user := range *users { | |||
userIDs := make([]int64, len(users)) | |||
for i, user := range users { | |||
userIDs[i] = user.Id | |||
} | |||
@@ -102,9 +102,9 @@ func UserManagementGetUserList(c *gin.Context) { | |||
return | |||
} | |||
userMap := make(map[int64]int, len(*users)) | |||
list := make([]md.UserManagementGetUserListNode, len(*users)) | |||
for i, user := range *users { | |||
userMap := make(map[int64]int, len(users)) | |||
list := make([]md.UserManagementGetUserListNode, len(users)) | |||
for i, user := range users { | |||
list[i] = md.UserManagementGetUserListNode{ | |||
ID: user.Id, | |||
Sex: user.Sex, | |||
@@ -1,7 +1,14 @@ | |||
package notice | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/md" | |||
svc2 "applet/app/svc" | |||
svc "applet/app/svc/member_center" | |||
"applet/app/svc/notice" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"github.com/gin-gonic/gin" | |||
) | |||
@@ -124,3 +131,210 @@ func AliyunSmsPushList(c *gin.Context) { | |||
func AliyunSmsPushSave(c *gin.Context) { | |||
notice.AliyunSmsPushSave(c) | |||
} | |||
// AliyunSmsGetUserList | |||
// @Summary 消息中心-短信推送记录-获取用户信息 | |||
// @Tags 消息中心 | |||
// @Description 获取用户信息 | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param req body md.JPushGetUserListReq true "(分页信息必填)" | |||
// @Success 200 {Object} md.JPushGetUserListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/aliyunSms/getUserList [post] | |||
func AliyunSmsGetUserList(c *gin.Context) { | |||
var req *md.AliyunSmsUserListReq | |||
if err := c.ShouldBindJSON(&req); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) | |||
return | |||
} | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
levels, err1 := levelDb.UserLevelAllByAsc() | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
levelsList := make([]map[string]interface{}, 0) | |||
levelsMap := make(map[int]string) | |||
for _, level := range levels { | |||
levelsList = append(levelsList, map[string]interface{}{ | |||
"id": level.Id, | |||
"name": level.LevelName, | |||
}) | |||
levelsMap[level.Id] = level.LevelName | |||
} | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
tags, err2 := tagDb.UserTagAllByAsc() | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
tagsList := make([]map[string]interface{}, 0) | |||
tagsMap := make(map[int]string) | |||
for _, tag := range tags { | |||
tagsList = append(tagsList, map[string]interface{}{ | |||
"id": tag.Id, | |||
"name": tag.TagName, | |||
}) | |||
tagsMap[tag.Id] = tag.TagName | |||
} | |||
stateList := []map[string]interface{}{ | |||
{ | |||
"name": "正常", | |||
"value": "1", | |||
}, | |||
{ | |||
"name": "冻结", | |||
"value": "2", | |||
}, | |||
} | |||
userMemberRequest := req.ToUserMemberRequest() | |||
users, total, err3 := svc.UserManagementGetUsers(userMemberRequest) | |||
if err3 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) | |||
return | |||
} | |||
userIDs := make([]int64, len(users)) | |||
for i, user := range users { | |||
userIDs[i] = user.Id | |||
} | |||
recordsDb := implement.NewUserTagRecordsDb(db.Db) | |||
records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{ | |||
"key": "uid", | |||
"value": userIDs, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var levelCounts []md.LevelCount | |||
err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts) | |||
if err4 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err4.Error()) | |||
return | |||
} | |||
userMap := make(map[int64]int, len(users)) | |||
list := make([]md.GetUserListNode, len(users)) | |||
for i, user := range users { | |||
list[i] = md.GetUserListNode{ | |||
ID: user.Id, | |||
Sex: user.Sex, | |||
Avatar: svc2.GetOssUrl(user.Avatar), | |||
Nickname: user.Nickname, | |||
Phone: user.Phone, | |||
IsRealName: user.IsRealName, | |||
InviteCode: user.SystemInviteCode, | |||
ParentID: user.ParentUid, | |||
ParentInviteCode: user.ParentSystemInviteCode, | |||
ParentPhone: user.Phone, | |||
RegisterTime: user.CreateAt, | |||
Memo: user.Memo, | |||
Wechat: user.UnionId, | |||
RegisterType: user.RegisterType, | |||
State: user.State, | |||
LastLoginAt: user.UpdateAt, | |||
} | |||
var tempTagList []md.TagNode | |||
list[i].Tag = tempTagList | |||
userMap[user.Id] = i | |||
level, ok := levelsMap[user.Level] | |||
if ok { | |||
list[i].LevelName = level | |||
} | |||
} | |||
for _, record := range *records { | |||
tempTagNode := md.TagNode{ | |||
TagID: record.TagId, | |||
TagName: tagsMap[record.TagId], | |||
} | |||
list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode) | |||
} | |||
resp := md.AliyunSmsGetUserListResp{ | |||
LevelsList: levelsList, | |||
TagsList: tagsList, | |||
StateList: stateList, | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: req.Limit, | |||
Page: req.Page, | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// AliyunSmsTagList | |||
// @Summary 消息中心-短信推送记录-标签管理(获取) | |||
// @Tags 消息中心 | |||
// @Description 标签管理(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param limit query int true "每页大小" | |||
// @Param page query int true "页数" | |||
// @Success 200 {object} md.AliyunSmsGetTagListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/aliyunSms/getTagList [get] | |||
func AliyunSmsTagList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
list, total, err := svc.TagManagementGetList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
resp := md.AliyunSmsGetTagListResp{ | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: utils.StrToInt(limit), | |||
Page: utils.StrToInt(page), | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// AliyunSmsGetLevelList | |||
// @Summary 消息中心-短信推送记录-等级管理(获取) | |||
// @Tags 消息中心 | |||
// @Description 等级管理(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param limit query int true "每页大小" | |||
// @Param page query int true "页数" | |||
// @Success 200 {object} md.AliyunSmsGetLevelListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/aliyunSms/getLevelList [get] | |||
func AliyunSmsGetLevelList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
list, total, err := svc.LevelManagementGetLevelList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
resp := md.AliyunSmsGetLevelListResp{ | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: utils.StrToInt(limit), | |||
Page: utils.StrToInt(page), | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} |
@@ -1,7 +1,14 @@ | |||
package notice | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/md" | |||
svc2 "applet/app/svc" | |||
svc "applet/app/svc/member_center" | |||
"applet/app/svc/notice" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"github.com/gin-gonic/gin" | |||
) | |||
@@ -79,3 +86,210 @@ func PushList(c *gin.Context) { | |||
func PushSave(c *gin.Context) { | |||
notice.PushSave(c) | |||
} | |||
// JPushGetUserList | |||
// @Summary 消息中心-基本配置-获取用户信息 | |||
// @Tags 消息中心 | |||
// @Description 获取用户信息 | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param req body md.JPushGetUserListReq true "(分页信息必填)" | |||
// @Success 200 {Object} md.JPushGetUserListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/jPush/getUserList [post] | |||
func JPushGetUserList(c *gin.Context) { | |||
var req *md.JPushGetUserListReq | |||
if err := c.ShouldBindJSON(&req); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) | |||
return | |||
} | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
levels, err1 := levelDb.UserLevelAllByAsc() | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
levelsList := make([]map[string]interface{}, 0) | |||
levelsMap := make(map[int]string) | |||
for _, level := range levels { | |||
levelsList = append(levelsList, map[string]interface{}{ | |||
"id": level.Id, | |||
"name": level.LevelName, | |||
}) | |||
levelsMap[level.Id] = level.LevelName | |||
} | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
tags, err2 := tagDb.UserTagAllByAsc() | |||
if err2 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err2.Error()) | |||
return | |||
} | |||
tagsList := make([]map[string]interface{}, 0) | |||
tagsMap := make(map[int]string) | |||
for _, tag := range tags { | |||
tagsList = append(tagsList, map[string]interface{}{ | |||
"id": tag.Id, | |||
"name": tag.TagName, | |||
}) | |||
tagsMap[tag.Id] = tag.TagName | |||
} | |||
stateList := []map[string]interface{}{ | |||
{ | |||
"name": "正常", | |||
"value": "1", | |||
}, | |||
{ | |||
"name": "冻结", | |||
"value": "2", | |||
}, | |||
} | |||
userMemberRequest := req.ToUserMemberRequest() | |||
users, total, err3 := svc.UserManagementGetUsers(userMemberRequest) | |||
if err3 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err3.Error()) | |||
return | |||
} | |||
userIDs := make([]int64, len(users)) | |||
for i, user := range users { | |||
userIDs[i] = user.Id | |||
} | |||
recordsDb := implement.NewUserTagRecordsDb(db.Db) | |||
records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{ | |||
"key": "uid", | |||
"value": userIDs, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var levelCounts []md.LevelCount | |||
err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts) | |||
if err4 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err4.Error()) | |||
return | |||
} | |||
userMap := make(map[int64]int, len(users)) | |||
list := make([]md.GetUserListNode, len(users)) | |||
for i, user := range users { | |||
list[i] = md.GetUserListNode{ | |||
ID: user.Id, | |||
Sex: user.Sex, | |||
Avatar: svc2.GetOssUrl(user.Avatar), | |||
Nickname: user.Nickname, | |||
Phone: user.Phone, | |||
IsRealName: user.IsRealName, | |||
InviteCode: user.SystemInviteCode, | |||
ParentID: user.ParentUid, | |||
ParentInviteCode: user.ParentSystemInviteCode, | |||
ParentPhone: user.Phone, | |||
RegisterTime: user.CreateAt, | |||
Memo: user.Memo, | |||
Wechat: user.UnionId, | |||
RegisterType: user.RegisterType, | |||
State: user.State, | |||
LastLoginAt: user.UpdateAt, | |||
} | |||
var tempTagList []md.TagNode | |||
list[i].Tag = tempTagList | |||
userMap[user.Id] = i | |||
level, ok := levelsMap[user.Level] | |||
if ok { | |||
list[i].LevelName = level | |||
} | |||
} | |||
for _, record := range *records { | |||
tempTagNode := md.TagNode{ | |||
TagID: record.TagId, | |||
TagName: tagsMap[record.TagId], | |||
} | |||
list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode) | |||
} | |||
resp := md.JPushGetUserListResp{ | |||
LevelsList: levelsList, | |||
TagsList: tagsList, | |||
StateList: stateList, | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: req.Limit, | |||
Page: req.Page, | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// JPushGetTagList | |||
// @Summary 消息中心-基本配置-标签管理(获取) | |||
// @Tags 消息中心 | |||
// @Description 标签管理(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param limit query int true "每页大小" | |||
// @Param page query int true "页数" | |||
// @Success 200 {object} md.JPushGetTagListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/jPush/getTagList [get] | |||
func JPushGetTagList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
list, total, err := svc.TagManagementGetList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
resp := md.JPushGetTagListResp{ | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: utils.StrToInt(limit), | |||
Page: utils.StrToInt(page), | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// JPushGetLevelList | |||
// @Summary 消息中心-基本配置-等级管理(获取) | |||
// @Tags 消息中心 | |||
// @Description 等级管理(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param limit query int true "每页大小" | |||
// @Param page query int true "页数" | |||
// @Success 200 {object} md.JPushGetLevelListResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/notice/jPush/getLevelList [get] | |||
func JPushGetLevelList(c *gin.Context) { | |||
page := c.DefaultQuery("page", "1") | |||
limit := c.DefaultQuery("limit", "10") | |||
list, total, err := svc.LevelManagementGetLevelList(page, limit) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
resp := md.JPushGetLevelListResp{ | |||
List: list, | |||
Paginate: md.Paginate{ | |||
Limit: utils.StrToInt(limit), | |||
Page: utils.StrToInt(page), | |||
Total: total, | |||
}, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} |
@@ -1,5 +1,10 @@ | |||
package md | |||
import ( | |||
md "applet/app/md/member_center" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
) | |||
type NoticeListReq struct { | |||
Page string `json:"page,required"` // 页数 | |||
Limit string `json:"limit,required"` // 每页大小 | |||
@@ -118,3 +123,187 @@ type NoticeAliyunSmsPushSaveReq struct { | |||
TagList []string `json:"tag_list"` | |||
Level []string `json:"level"` | |||
} | |||
type Paginate struct { | |||
Limit int `json:"limit"` // 每页大小 | |||
Page int `json:"page"` // 页数 | |||
Total int64 `json:"total"` // 总数据量 | |||
} | |||
type JPushGetUserListResp struct { | |||
LevelsList []map[string]interface{} `json:"levels_list"` // 等级列表 | |||
TagsList []map[string]interface{} `json:"tags_list"` // 标签列表 | |||
StateList []map[string]interface{} `json:"state_list"` // 状态列表 | |||
List []GetUserListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` // 分页信息 | |||
} | |||
type TagNode struct { | |||
TagID int `json:"tag_id"` // 标签 ID | |||
TagName string `json:"tag_name"` // 标签名称 | |||
} | |||
type LevelCount struct { | |||
Level int `xorm:"level"` | |||
Count int `xorm:"count"` | |||
} | |||
type GetUserListNode struct { | |||
ID int64 `json:"id"` // 会员 ID | |||
Tag []TagNode `json:"tag"` // 会员标签 | |||
Sex int `json:"sex"` // 性别(0:未知 1:男 2:女) | |||
Avatar string `json:"avatar"` // 头像 | |||
Nickname string `json:"nickname"` // 昵称 | |||
Phone string `json:"phone"` // 手机号 | |||
IsRealName int `json:"is_real_name"` // 是否实名 0.未实名,1.已实名 | |||
LevelName string `json:"level_name"` // 会员等级 | |||
InviteCode string `json:"invite_code" example:"会员邀请码"` | |||
ParentID int64 `json:"parent_id"` // 推荐人 ID | |||
ParentInviteCode string `json:"parent_invite_code" example:"推荐人邀请码"` | |||
ParentPhone string `json:"parent_phone" example:"推荐人手机号"` | |||
RegisterTime string `json:"register_time"` // 注册时间 | |||
Memo string `json:"memo"` // 备注 | |||
Wechat string `json:"wechat"` // 微信号 | |||
RegisterType int `json:"register_type"` // 注册类型 | |||
State int `json:"state"` // 状态 | |||
LastLoginAt string `json:"last_login_at"` // 最后登录时间 | |||
} | |||
type JPushGetUserListReq struct { | |||
ID int64 `json:"id"` // 会员 ID | |||
Nickname string `json:"nickname" example:"会员昵称"` | |||
RecommendID int64 `json:"recommend_id"` // 推荐人 ID | |||
Tag int `json:"tag"` // 标签 id | |||
Phone string `json:"phone" example:"会员手机号"` | |||
InviteCode string `json:"invite_code" example:"会员邀请码"` | |||
ParentInviteCode string `json:"parent_invite_code" example:"上级邀请码"` | |||
ParentPhone string `json:"parent_phone" example:"上级手机号"` | |||
Sex int `json:"sex"` // 性别(0:未知 1:男 2:女) | |||
UnionId string `json:"union_id" example:"微信号"` | |||
Level int `json:"level"` // 会员等级 | |||
RegisterType int `json:"register_type"` // 注册类型(1:APP注册、2:H5注册) | |||
State int `json:"state"` // 状态 | |||
Effective int `json:"effective"` // 有效会员 | |||
IsRealName int `json:"is_real_name"` // 是否实名 0.未实名,1.已实名 | |||
Memo string `json:"memo"` // 备注 | |||
RegisterBefore string `json:"register_before"` // 注册时间起点 | |||
RegisterAfter string `json:"register_after"` // 注册时间终点 | |||
LoginBefore string `json:"login_before"` // 最近登录开始时间 | |||
LoginAfter string `json:"login_after"` // 最近登录结束时间 | |||
Page int `json:"page,required"` | |||
Limit int `json:"limit,required"` | |||
} | |||
type UserInfo struct { | |||
model.User `xorm:"extends"` | |||
TagID int `xorm:"tag_id"` | |||
ParentPhone string `xorm:"parent_phone"` | |||
ParentSystemInviteCode string `xorm:"parent_system_invite_code"` | |||
ParentCustomInviteCode string `xorm:"parent_custom_invite_code"` | |||
} | |||
type JPushGetTagListResp struct { | |||
List []md.TagListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` | |||
} | |||
type JPushGetLevelListResp struct { | |||
List []md.LevelListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` | |||
} | |||
type AliyunSmsGetUserListResp struct { | |||
LevelsList []map[string]interface{} `json:"levels_list"` // 等级列表 | |||
TagsList []map[string]interface{} `json:"tags_list"` // 标签列表 | |||
StateList []map[string]interface{} `json:"state_list"` // 状态列表 | |||
List []GetUserListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` // 分页信息 | |||
} | |||
type AliyunSmsUserListReq struct { | |||
ID int64 `json:"id"` // 会员 ID | |||
Nickname string `json:"nickname" example:"会员昵称"` | |||
RecommendID int64 `json:"recommend_id"` // 推荐人 ID | |||
Tag int `json:"tag"` // 标签 id | |||
Phone string `json:"phone" example:"会员手机号"` | |||
InviteCode string `json:"invite_code" example:"会员邀请码"` | |||
ParentInviteCode string `json:"parent_invite_code" example:"上级邀请码"` | |||
ParentPhone string `json:"parent_phone" example:"上级手机号"` | |||
Sex int `json:"sex"` // 性别(0:未知 1:男 2:女) | |||
UnionId string `json:"union_id" example:"微信号"` | |||
Level int `json:"level"` // 会员等级 | |||
RegisterType int `json:"register_type"` // 注册类型(1:APP注册、2:H5注册) | |||
State int `json:"state"` // 状态 | |||
Effective int `json:"effective"` // 有效会员 | |||
IsRealName int `json:"is_real_name"` // 是否实名 0.未实名,1.已实名 | |||
Memo string `json:"memo"` // 备注 | |||
RegisterBefore string `json:"register_before"` // 注册时间起点 | |||
RegisterAfter string `json:"register_after"` // 注册时间终点 | |||
LoginBefore string `json:"login_before"` // 最近登录开始时间 | |||
LoginAfter string `json:"login_after"` // 最近登录结束时间 | |||
Page int `json:"page,required"` | |||
Limit int `json:"limit,required"` | |||
} | |||
type AliyunSmsGetTagListResp struct { | |||
List []md.TagListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` | |||
} | |||
type AliyunSmsGetLevelListResp struct { | |||
List []md.LevelListNode `json:"list"` | |||
Paginate Paginate `json:"paginate"` | |||
} | |||
func (req JPushGetUserListReq) ToUserMemberRequest() *md.UserManagementGetUserListReq { | |||
return &md.UserManagementGetUserListReq{ | |||
ID: req.ID, | |||
Nickname: req.Nickname, | |||
RecommendID: req.RecommendID, | |||
Tag: req.Tag, | |||
Phone: req.Phone, | |||
InviteCode: req.InviteCode, | |||
ParentInviteCode: req.ParentInviteCode, | |||
ParentPhone: req.ParentPhone, | |||
Sex: req.Sex, | |||
UnionId: req.UnionId, | |||
Level: req.Level, | |||
RegisterType: req.RegisterType, | |||
State: req.State, | |||
Effective: req.Effective, | |||
IsRealName: req.IsRealName, | |||
Memo: req.Memo, | |||
RegisterBefore: req.RegisterBefore, | |||
RegisterAfter: req.RegisterAfter, | |||
LoginBefore: req.LoginBefore, | |||
LoginAfter: req.LoginAfter, | |||
Page: req.Page, | |||
Limit: req.Limit, | |||
} | |||
} | |||
func (req AliyunSmsUserListReq) ToUserMemberRequest() *md.UserManagementGetUserListReq { | |||
return &md.UserManagementGetUserListReq{ | |||
ID: req.ID, | |||
Nickname: req.Nickname, | |||
RecommendID: req.RecommendID, | |||
Tag: req.Tag, | |||
Phone: req.Phone, | |||
InviteCode: req.InviteCode, | |||
ParentInviteCode: req.ParentInviteCode, | |||
ParentPhone: req.ParentPhone, | |||
Sex: req.Sex, | |||
UnionId: req.UnionId, | |||
Level: req.Level, | |||
RegisterType: req.RegisterType, | |||
State: req.State, | |||
Effective: req.Effective, | |||
IsRealName: req.IsRealName, | |||
Memo: req.Memo, | |||
RegisterBefore: req.RegisterBefore, | |||
RegisterAfter: req.RegisterAfter, | |||
LoginBefore: req.LoginBefore, | |||
LoginAfter: req.LoginAfter, | |||
Page: req.Page, | |||
Limit: req.Limit, | |||
} | |||
} |
@@ -17,22 +17,14 @@ type UpdateRoleStateReq struct { | |||
} | |||
type AddRoleReq struct { | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
Logo string `json:"logo" label:"左边图标"` | |||
Label string `json:"label" label:"身份标签"` | |||
SeoLogo string `json:"seo_logo" label:"seo"` | |||
SeoTitle string `json:"seo_title" label:"seo"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
} | |||
type UpdateRoleReq struct { | |||
RoleId int `json:"role_id" binding:"required" label:"id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
Logo string `json:"logo" label:"左边图标"` | |||
Label string `json:"label" label:"身份标签"` | |||
SeoLogo string `json:"seo_logo" label:"seo"` | |||
SeoTitle string `json:"seo_title" label:"seo"` | |||
RoleId int `json:"role_id" binding:"required" label:"id"` | |||
Name string `json:"name" binding:"required" label:"名称"` | |||
Memo string `json:"memo" binding:"required" label:"备注"` | |||
} | |||
type RoleBindPermissionGroupReq struct { | |||
@@ -21,9 +21,10 @@ type AddTagReq struct { | |||
} | |||
type UpdateTagReq struct { | |||
TagID string `json:"tag_id,required"` // 标签 ID | |||
Name string `json:"name,required"` // 标签名称 | |||
Memo string `json:"memo,required"` // 备注 | |||
TagID string `json:"tag_id,required"` // 标签 ID | |||
Name string `json:"name,required"` // 标签名称 | |||
Memo string `json:"memo,required"` // 备注 | |||
IsPunish string `json:"is_punish"` // 是否是惩罚标签 | |||
} | |||
type DeleteTagReq struct { | |||
@@ -89,6 +89,7 @@ func route(r *gin.RouterGroup) { | |||
r.GET("/config", hdl.Config) | |||
rIm(r.Group("/im")) | |||
r.Use(mw.CheckPermission) // 检测权限 | |||
rRole(r.Group("/role")) | |||
rInstitutionalManagement(r.Group("/institutionalManagement")) | |||
rMarketingApplications(r.Group("/marketingApplications")) | |||
rMemberCenter(r.Group("/memberCenter")) | |||
@@ -147,17 +148,17 @@ func rNotice(r *gin.RouterGroup) { | |||
rJpush := r.Group("/jPush") //极光 | |||
{ | |||
rJpush.POST("/push/list", notice.PushList) | |||
rJpush.POST("/getUserList", member_center.UserManagementGetUserList) | |||
rJpush.GET("/getTagList", member_center.GetTagList) | |||
rJpush.GET("/getLevelList", member_center.GetLevelList) | |||
rJpush.POST("/getUserList", notice.JPushGetUserList) | |||
rJpush.GET("/getTagList", notice.JPushGetTagList) | |||
rJpush.GET("/getLevelList", notice.JPushGetLevelList) | |||
rJpush.POST("/push/save", notice.PushSave) | |||
} | |||
rAliyunSms := r.Group("/aliyunSms") //阿里云短信 | |||
{ | |||
rAliyunSms.POST("/file/phone", notice.AliyunSmsFilePhone) | |||
rAliyunSms.POST("/getUserList", member_center.UserManagementGetUserList) | |||
rAliyunSms.GET("/getTagList", member_center.GetTagList) | |||
rAliyunSms.GET("/getLevelList", member_center.GetLevelList) | |||
rAliyunSms.POST("/getUserList", notice.AliyunSmsGetUserList) | |||
rAliyunSms.GET("/getTagList", notice.AliyunSmsTagList) | |||
rAliyunSms.GET("/getLevelList", notice.AliyunSmsGetLevelList) | |||
rAliyunSms.GET("/sale/base", notice.AliyunSmsSaleBase) | |||
rAliyunSms.POST("/sale/save", notice.AliyunSmsSaleSave) | |||
rAliyunSms.POST("/push/list", notice.AliyunSmsPushList) | |||
@@ -410,6 +411,23 @@ func rFriendCircleSettings(r *gin.RouterGroup) { | |||
} | |||
} | |||
func rRole(r *gin.RouterGroup) { | |||
r.GET("/roleList", hdl.RoleList) // 角色列表 | |||
r.POST("/addRole", hdl.AddRole) // 角色添加 | |||
r.POST("/roleBindPermissionGroup", hdl.RoleBindPermissionGroup) // 角色绑定权限组 | |||
r.POST("/updateRoleState", hdl.UpdateRoleState) // 修改角色状态 | |||
r.POST("/updateRole", hdl.UpdateRole) // 修改角色状态 | |||
r.DELETE("/deleteRole/:id", hdl.DeleteRole) // 删除角色 | |||
r.GET("/permissionGroupList", hdl.PermissionGroupList) // 权限组列表 | |||
r.POST("/adminList", hdl.AdminList) // 管理员列表 | |||
r.POST("/updateAdminState", hdl.UpdateAdminState) // 修改管理员状态 | |||
r.POST("/updateAdmin", hdl.UpdateAdmin) // 修改管理员信息 | |||
r.POST("/addAdmin", hdl.AddAdmin) // 新增管理员 | |||
r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) // 删除管理员 | |||
r.GET("/adminInfo", hdl.AdminInfo) // 获取管理员信息 | |||
r.POST("/bindAdminRole", hdl.BindAdminRole) // 绑定角色 | |||
} | |||
func rComm(r *gin.RouterGroup) { | |||
r.POST("/getMenuList", comm.MenuList) // 获取菜单栏列表 | |||
r.POST("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL | |||
@@ -45,3 +45,34 @@ func BatchAddLevelTask(session *xorm.Session, tasks []md.LevelTaskNode, levelId | |||
return nil | |||
} | |||
func LevelManagementGetLevelList(page, limit string) ([]md.LevelListNode, int64, error) { | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit)) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level" | |||
results, err := db.QueryNativeString(db.Db, sql) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
var countMap = map[int]string{} | |||
for _, res := range results { | |||
countMap[utils.StrToInt(res["level"])] = res["total"] | |||
} | |||
list := make([]md.LevelListNode, len(levels)) | |||
for i, level := range levels { | |||
list[i].LevelWeight = level.LevelWeight | |||
list[i].LevelID = level.Id | |||
list[i].LevelName = level.LevelName | |||
list[i].Count = countMap[level.Id] | |||
list[i].CreateAt = level.CreateAt | |||
list[i].IsUse = level.IsUse | |||
list[i].Memo = level.Memo | |||
} | |||
return list, total, nil | |||
} |
@@ -0,0 +1,38 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
md "applet/app/md/member_center" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
) | |||
func TagManagementGetList(page, limit string) ([]md.TagListNode, int64, error) { | |||
sql := "SElECT count(distinct uid) as total, tag_id FROM `user_tag_records` GROUP BY tag_id" | |||
results, err := db.QueryNativeString(db.Db, sql) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
var countMap = map[int64]string{} | |||
for _, res := range results { | |||
countMap[utils.StrToInt64(res["tag_id"])] = res["total"] | |||
} | |||
tagDb := implement.NewUserTagDb(db.Db) | |||
tags, total, err := tagDb.UserTagAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit)) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
list := make([]md.TagListNode, len(*tags)) | |||
for i, tag := range *tags { | |||
list[i].Name = tag.TagName | |||
list[i].Count = countMap[int64(tag.Id)] | |||
list[i].CreateAt = tag.CreateAt | |||
list[i].Memo = tag.Memo | |||
list[i].TagID = utils.IntToStr(tag.Id) | |||
list[i].IsPunish = tag.IsPunish | |||
} | |||
return list, total, nil | |||
} |
@@ -6,14 +6,31 @@ import ( | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
"fmt" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func UserManagementGetUsers(engine *xorm.Engine, req *md.UserManagementGetUserListReq) (*[]md.UserInfo, int64, error) { | |||
users := make([]md.UserInfo, 0) | |||
session := engine.Table("user").Alias("a").Distinct("a.id"). | |||
func UserManagementGetUsers(req *md.UserManagementGetUserListReq) ([]*md.UserInfo, int64, error) { | |||
users := make([]*md.UserInfo, 0) | |||
pageSess := userManagementGetUsersBindQuery(db.Db, req) | |||
countSess := userManagementGetUsersBindQuery(db.Db, req) | |||
total, err := countSess.Distinct("a.id").Count(&md.UserInfo{}) | |||
if err != nil { | |||
fmt.Println(err.Error()) | |||
return nil, 0, err | |||
} | |||
err = pageSess.Distinct("a.*").Limit(req.Limit, (req.Page-1)*req.Limit).Asc("a.id").Find(&users) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
return users, total, nil | |||
} | |||
func userManagementGetUsersBindQuery(engine *xorm.Engine, req *md.UserManagementGetUserListReq) *xorm.Session { | |||
session := engine.Table("user").Alias("a"). | |||
Join("LEFT OUTER", []string{"user", "b"}, "a.parent_uid = b.id"). | |||
Join("LEFT OUTER", "user_tag_records", "user_tag_records.uid = a.id") | |||
if req.ID != 0 { | |||
@@ -67,13 +84,8 @@ func UserManagementGetUsers(engine *xorm.Engine, req *md.UserManagementGetUserLi | |||
if req.LoginBefore != "" && req.LoginAfter != "" { | |||
session = session.Where("a.update_at > ? and a.update_at < ?", req.LoginBefore, req.LoginAfter) | |||
} | |||
total, err := session.Limit(req.Limit, (req.Page-1)*req.Limit).Asc("a.id").FindAndCount(&users) | |||
if err != nil { | |||
return nil, 0, err | |||
} | |||
return &users, total, nil | |||
return session | |||
} | |||
func UserManagementUpdateUserInfo(engine *xorm.Engine, req *md.UserManagementUpdateUserInfoReq) (int64, error) { | |||
session := engine.NewSession() | |||
defer session.Close() | |||
@@ -101,7 +101,7 @@ func DeleteRole(c *gin.Context, roleId int) (err error) { | |||
return session.Commit() | |||
} | |||
func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) (err error) { | |||
func RoleBindPermissionGroup(req md.RoleBindPermissionGroupReq) (err error) { | |||
engine := db.Db | |||
session := engine.NewSession() | |||
defer session.Close() | |||
@@ -194,3 +194,27 @@ func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { | |||
return session.Commit() | |||
} | |||
func AdminDelete(admIds []int) (err error) { | |||
engine := db.Db | |||
session := engine.NewSession() | |||
defer session.Close() | |||
session.Begin() | |||
//1、删除 `admin` | |||
adminDb := implement.NewAdminDb(engine) | |||
_, err = adminDb.AdminDeleteBySession(session, admIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
//2、删除 `admin_role` | |||
adminRoleDb := implement.NewAdminRoleDb(engine) | |||
_, err = adminRoleDb.AdminDeleteBySessionForAdmId(session, admIds) | |||
if err != nil { | |||
_ = session.Rollback() | |||
return | |||
} | |||
return session.Commit() | |||
} |
@@ -33,7 +33,7 @@ require ( | |||
) | |||
require ( | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241210110912-1a6913ffbbc5 | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241210101917-218ac8890613 | |||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205075006-9c0bf995c788 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | |||