add admin

This commit is contained in:
2026-08-07 15:40:17 +08:00
parent 10424d23d8
commit 56674a850e
28 changed files with 2066 additions and 569 deletions
+92
View File
@@ -0,0 +1,92 @@
package dao
import "pkg.local/utils"
// Admin 公司内部人员表
type Admin struct {
Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"`
Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"`
Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"`
Password string `gorm:"column:password;type:char(61);comment:密码;NOT NULL" json:"password"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
Salt string `gorm:"column:salt;type:char(5);comment:与密码混合搭配加密;NOT NULL" json:"salt"`
Roles string `gorm:"column:roles;type:varchar(255);comment:角色" json:"roles"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;default:NULL;comment:最后一次登录时间" json:"last_time"`
FailNumber int `gorm:"column:fail_number;type:tinyint(2);default:0;comment:连续登录失败次数" json:"fail_number"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `gorm:"column:admin_id;type:int(11);default:0;comment:操作人;NOT NULL" json:"admin_id"`
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime;default:NULL;comment:添加时间" json:"create_time"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
// AdminPassword 修改管理员密码
type AdminPassword struct {
Id int `json:"id"`
Password string `json:"password"`
Salt string `json:"salt"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
// AdminStatus 修改管理员状态
type AdminStatus struct {
Id int `json:"id"`
Status uint8 `json:"status"`
Reason string `json:"reason"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
// AdminInfo 管理员详情
type AdminInfo struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"`
Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
DepartmentId string `gorm:"column:department_id;type:varchar(255);default:0;comment:部门ID" json:"department_id"`
Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"`
Roles string `gorm:"column:roles;type:varchar(255);comment:角色" json:"roles"`
LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;comment:最后一次登录时间" json:"last_time"`
FailNumber int `gorm:"column:fail_number;type:tinyint(2);default:0;comment:连续登录失败次数" json:"fail_number"`
}
type AdminInfoRet struct {
AdminInfo
Roles []int `json:"roles"`
DepartmentId []int `json:"department_id"`
}
type AdminItemsRet struct {
AdminInfo
RoleInfo []RoleNameItems `json:"role_info"`
}
type AdminItems struct {
Items []AdminItemsRet `json:"items"`
Count int64 `json:"count"`
}
type AdminLastTime struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;default:NULL;comment:最后一次登录时间" json:"last_time"`
FailNumber int `gorm:"column:fail_number;type:tinyint(2);default:0;comment:连续登录失败次数" json:"fail_number"`
}
type AdminFail struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
FailNumber int `gorm:"column:fail_number;type:tinyint(2);default:0;comment:连续登录失败次数" json:"fail_number"`
}
type AdminOutInfo struct {
Id int `json:"id"`
Avatar string `json:"avatar"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
Roles []string `json:"roles"`
}
+160
View File
@@ -0,0 +1,160 @@
package dao
import "pkg.local/utils"
const (
TypeDir = 1
TypeWeb = 2
TypeButton = 3
TypeUrl = 4
TypeData = 5
NoData = "#"
SortTypeUp = 1
SortTypeDown = 2
QuerySortLIstWeb = 1
QuerySortListAll = 2
QuerySortListNotButton = 3
)
// Authority 权限表
type Authority struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:菜单;NOT NULL" json:"name"`
ParentId int `gorm:"column:parent_id;type:int(11);default:0;comment:父级菜单;NOT NULL" json:"parent_id"`
ParentIds string `gorm:"column:parent_ids;type:varchar(255);comment:多级父级菜单;NOT NULL" json:"parent_ids"`
Level uint8 `gorm:"column:level;type:tinyint(2);default:0;comment:级别;NOT NULL" json:"level"`
Type uint8 `gorm:"column:type;type:tinyint(2);comment:类型,1目录,2页面,3按钮;NOT NULL" json:"type"`
ProjectId int `gorm:"column:project_id;type:int(11);comment:项目ID;NOT NULL" json:"project_id"`
Path string `gorm:"column:path;type:varchar(255);comment:页面请求地址;NOT NULL" json:"path"`
Api string `gorm:"column:api;type:varchar(255);comment:接口地址" json:"api"`
ViewPath string `gorm:"column:view_path;type:varchar(255);comment:页面文件路径" json:"view_path"`
Identification string `gorm:"column:identification;type:varchar(255);comment:权限标识" json:"identification"`
Icon string `gorm:"column:icon;type:varchar(255);comment:图标" json:"icon"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
Sort uint8 `gorm:"column:sort;type:smallint(3);default:1;comment:排序" json:"sort"`
JsonDataBase string `gorm:"column:json_data_base;type:text;comment:原始数据" json:"json_data_base"`
JsonTreeData string `gorm:"column:json_tree_data;type:text;comment:数据的树型结构" json:"json_tree_data"`
JsonData string `gorm:"column:json_data;type:text;comment:所有的数据" json:"json_data"`
DataIds string `gorm:"column:data_ids;type:varchar(32);comment:三个数据的IDs" json:"data_ids"`
IsShow uint8 `gorm:"column:is_show;type:tinyint(1);default:1;comment:菜单中是否显示,1为显示,2为不显示;NOT NULL" json:"is_show"`
Remarks string `gorm:"column:remarks;type:varchar(255);comment:备注;NOT NULL" json:"remarks"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `gorm:"column:admin_id;type:int(11);comment:操作人ID" json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
CreateTime utils.CustomTime `gorm:"column:create_time;default:NULL;type:datetime" json:"create_time"`
UpdateTime utils.CustomTime `gorm:"column:update_time;default:NULL;type:datetime" json:"update_time"`
}
// AuthorityStatus 修改状态
type AuthorityStatus struct {
Id int `json:"id"`
Status uint8 `json:"status"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
ProjectId int `gorm:"column:project_id;type:int(11);comment:项目ID;NOT NULL" json:"project_id"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
type AuthorityCheck struct {
Id int `json:"id"`
Api string `json:"api"`
Type uint8 `json:"type"`
}
type AuthorityItems struct {
Id int `json:"id"`
Name string `json:"name"`
ParentId int `json:"parent_id"`
ParentIds string `json:"parent_ids"`
Level uint8 `json:"level"`
Type uint8 `json:"type"`
ProjectId int `json:"project_id"`
Path string `json:"path"`
Api string `json:"api"`
ViewPath string `json:"view_path"`
Identification string `json:"identification"`
Icon string `json:"icon"`
Status uint8 `json:"status"`
Sort uint8 `json:"sort"`
JsonDataBase string `gorm:"column:json_data_base;type:text;comment:原始数据" json:"json_data_base"`
JsonData string `gorm:"column:json_data;type:text;comment:所有的数据" json:"json_data"`
JsonTreeData string `gorm:"column:json_tree_data;type:text;comment:数据的树型结构" json:"json_tree_data"`
DataIds string `json:"data_ids"`
IsShow uint8 `json:"is_show"`
Remarks string `json:"remarks"`
Reason string `json:"reason"`
AdminId int `json:"admin_id"`
AdminName string `json:"admin_name"`
CreateTime utils.CustomTime `json:"create_time"`
UpdateTime utils.CustomTime `json:"update_time"`
IsFirst bool `json:"is_first"` // 是否是同级第一个节点
IsLast bool `json:"is_last"` // 是否是同级最后一个节点
Children []*AuthorityItems `json:"children"`
}
type AuthorityNames struct {
Id int `json:"id"`
Name string `json:"name"`
Level uint8 `json:"level"`
Type uint8 `json:"type"`
ParentId int `json:"parent_id"db:"parent_id"`
}
type AuthorityNamesItems struct {
Id int `json:"value"`
Name string `json:"label"`
Level uint8 `json:"level"`
Type uint8 `json:"type"`
ParentId int `json:"pid"`
Children []AuthorityNamesItems `json:"children"`
}
type AuthorityInfo struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:菜单;NOT NULL" json:"name"`
ParentId int `gorm:"column:parent_id;type:int(11);default:0;comment:父级菜单;NOT NULL" json:"parent_id"`
Type uint8 `gorm:"column:type;type:tinyint(2);comment:类型,1目录,2页面,3按钮;NOT NULL" json:"type"`
Path string `gorm:"column:path;type:varchar(100);comment:页面请求地址;NOT NULL" json:"path"`
Api string `gorm:"column:api;type:varchar(100);comment:接口地址" json:"api"`
ViewPath string `gorm:"column:view_path;type:varchar(255);comment:页面文件路径" json:"view_path"`
Identification string `gorm:"column:identification;type:varchar(255);comment:权限标识" json:"identification"`
Icon string `gorm:"column:icon;type:varchar(30);comment:图标" json:"icon"`
IsShow uint8 `gorm:"column:is_show;type:tinyint(1);default:1;comment:菜单中是否显示,1为显示,2为不显示;NOT NULL" json:"is_show"`
JsonDataBase string `gorm:"column:json_data_base;type:text;comment:原始数据" json:"json_data_base"`
JsonTreeData string `gorm:"column:json_tree_data;type:text;comment:数据的树型结构" json:"json_tree_data"`
JsonData string `gorm:"column:json_data;type:text;comment:所有的数据" json:"json_data"`
DataIds string `gorm:"column:data_ids;type:varchar(32);comment:三个数据的IDs" json:"data_ids"`
Remarks string `gorm:"column:remarks;type:varchar(255);comment:备注;NOT NULL" json:"remarks"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
}
type AuthorityInfoNew struct {
AuthorityInfo
JsonDataDepartment string `json:"json_data_department"`
JsonDataAll string `json:"json_data_all"`
JsonDataOneself string `json:"json_data_oneself"`
}
type AuthoritySort struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
ParentId int `gorm:"column:parent_id;type:int(11);default:0;comment:父级菜单;NOT NULL" json:"parent_id"`
ProjectId int `gorm:"column:project_id;type:int(11);comment:项目ID;NOT NULL" json:"project_id"`
Sort uint8 `gorm:"column:sort;type:smallint(3);default:1;comment:排序" json:"sort"`
AdminId int `gorm:"column:admin_id;type:int(11);comment:操作人ID" json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;default:NULL;type:datetime" json:"update_time"`
}
type AuthorityUpJsonIds struct {
DataIds string `gorm:"column:data_ids;type:varchar(32);comment:三个数据的IDs" json:"data_ids"`
}
type AuthorityGetJsonIds struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
JsonDataBase string `gorm:"column:json_data_base;type:text;comment:原始数据" json:"json_data_base"`
JsonData string `gorm:"column:json_data;type:text;comment:所有的数据" json:"json_data"`
JsonTreeData string `gorm:"column:json_tree_data;type:text;comment:数据的树型结构" json:"json_tree_data"`
DataIds string `gorm:"column:data_ids;type:varchar(32);comment:三个数据的IDs" json:"data_ids"`
}
+68
View File
@@ -0,0 +1,68 @@
package dao
import "pkg.local/utils"
// Role 岗位表
type Role struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:名称;NOT NULL" json:"name"`
ProjectId int `gorm:"column:project_id;type:int(11);comment:项目ID;NOT NULL" json:"project_id"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
Rules string `gorm:"column:rules;type:text;comment:权限内容" json:"rules"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `gorm:"column:admin_id;type:int(11)" json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
CreateTime utils.CustomTime `gorm:"column:create_time;default:NULL;type:datetime" json:"create_time"`
UpdateTime utils.CustomTime `gorm:"column:update_time;default:NULL;type:datetime" json:"update_time"`
}
// RoleStatus 修改状态
type RoleStatus struct {
Id int `json:"id"`
Status uint8 `json:"status"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
// RoleRule 修改状态
type RoleRule struct {
Id int `json:"id"`
Rules string `json:"rules"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime;default:NULL;comment:更新时间" json:"update_time"`
}
type RoleItems struct {
Role
RuleItems []string `json:"rule_items"`
}
type RoleNameItems struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
ProjectId int `json:"project_id"`
}
type RoleProjectNameItems struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
Items []RoleNameItems `json:"items"`
}
type RoleRulesItems struct {
Id int `json:"id"`
Name string `json:"name"`
Rules string `json:"rules"`
}
type RoleInfo struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:名称;NOT NULL" json:"name"`
ProjectId int `gorm:"column:project_id;type:int(11);comment:项目ID;NOT NULL" json:"project_id"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
Rules []int `gorm:"column:rules;type:text;comment:权限内容" json:"rules"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
}
+29
View File
@@ -0,0 +1,29 @@
package dao
type RoutesMenu struct {
Id int `json:"id"`
Name string `json:"name"`
ParentId int `json:"parent_id"`
Level uint8 `json:"level"`
Type uint8 `json:"type"`
Path string `json:"path"`
Api string `json:"api"`
ViewPath string `json:"view_path"`
Identification string `json:"identification"`
Icon string `json:"icon"`
Sort uint8 `json:"sort"`
IsShow uint8 `json:"is_show"`
Remarks string `json:"remarks"`
Children []RoutesMenu `json:"children"`
}
type RoutesAuth struct {
Id int `json:"id"`
Type uint8 `json:"type"`
Identification string `json:"identification"`
}
type Routes struct {
Menu []RoutesMenu `json:"menu"`
Auth []RoutesAuth `json:"auth"`
}
+38
View File
@@ -0,0 +1,38 @@
package dao
import "pkg.local/utils"
// Project 项目表
type Project struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
Remarks string `gorm:"column:remarks;type:varchar(255);default:'';comment:描述;NOT NULL" json:"remarks"`
Logo string `gorm:"column:logo;type:varchar(255);default:'';comment:logo;NOT NULL" json:"logo"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `gorm:"column:admin_id;type:int(11);comment:操作人员ID" json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime" json:"create_time"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"`
}
type ProjectItems struct {
Items []Project `json:"items"`
Count int64 `json:"count"`
}
// ProjectStatus 修改状态
type ProjectStatus struct {
Id int `json:"id"`
Status uint8 `json:"status"`
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
AdminId int `json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"`
}
type ProjectNameItems struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
Logo string `gorm:"column:logo;type:varchar(255);default:'';comment:logo;NOT NULL" json:"logo"`
}
-36
View File
@@ -1,36 +0,0 @@
package logic
import (
"admin/validator"
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"pkg.local/utils"
validateService "pkg.local/validate"
)
type AddLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
return &AddLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AddLogic) Add(in *admin.AddRequest) (*admin.Response, error) {
var req validator.AdminAddValidator
if resp := validateService.ValidateFromProto(in, &req); resp != utils.StringEmpty {
return &admin.Response{Code: utils.Ok.Code, Msg: resp}, nil
}
return &admin.Response{}, nil
}
+125
View File
@@ -0,0 +1,125 @@
package logic
import (
"admin/admin"
"admin/internal/dao"
"admin/internal/model"
"admin/internal/svc"
"admin/validator"
"context"
"fmt"
"strconv"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"pkg.local/modelbase"
"pkg.local/utils"
)
type AdminAddLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewAdminAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminAddLogic {
return &AdminAddLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AdminAddLogic) AdminAdd(in *admin.AdminEditRequest) (*admin.Response, error) {
var v validator.AdminEditValidator
if fail := l.checkParams(in, &v); fail != nil {
return fail, nil
}
encryPhone, cErr := utils.EncryptPhone(in.Phone)
if cErr != nil {
l.Logger.Error(cErr)
return l.fail(utils.ErrorEncryptAesError), nil
}
info, check := l.checkPhone(encryPhone)
if !check {
return l.fail(utils.ErrorEncryptAesError), nil
}
modelObj := model.AdminModel{}.Init()
if in.Id > utils.NumberZero && info.Id < utils.NumberOne {
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
info = dao.Admin{}
err := modelObj.GetOne(w, &info)
if err != nil {
l.Logger.Error(cErr)
return l.fail(utils.Fail), nil
}
if info.Id < utils.NumberZero {
return l.fail(utils.ErrorNotFund), nil
}
}
//编辑
if in.Id > utils.NumberZero {
if info.Id < utils.NumberOne {
return l.fail(utils.ErrorNotFund), nil
}
if info.Id != in.Id {
return l.fail(utils.ErrorExistUser), nil
}
} else {
if len(in.Password) < utils.NumberOne {
return l.out(utils.ErrorParams, "密码不能为空"), nil
}
if info.Id > utils.NumberZero {
return l.fail(utils.ErrorExistUser), nil
}
}
//adminId, _ := c.Get(utils.USERID)
//adminName, _ := c.Get(utils.USERNAME)
var roles []string
if len(in.Roles) > utils.NumberZero {
for _, role := range in.Roles {
roles = append(roles, strconv.Itoa(int(role)))
}
}
info.Name = in.Name
info.Phone = encryPhone
info.Roles = strings.Join(roles, ",")
info.Email = in.Email
info.Avatar = in.Avatar
var err error
if info.Id > utils.NumberZero {
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(info.Id))}}
_, err = modelObj.Edit(w, info)
} else {
salt := utils.GetRandstring(utils.NumberFive)
pwd := fmt.Sprintf("%s%s", salt, in.Password)
pwd, _ = utils.EncryptPassword(pwd)
info.Password = pwd
info.Salt = salt
err = modelObj.Init().Create(&info)
}
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail), nil
}
return l.ok(info.Id), nil
}
func (l *AdminAddLogic) checkPhone(phone string) (dao.Admin, bool) {
w := modelbase.Params{Eq: map[string]string{"phone": phone}}
info := dao.Admin{}
err := model.AdminModel{}.Init().GetOne(w, &info)
if err != nil {
l.Logger.Error(err)
return info, false
}
return info, true
}
@@ -9,24 +9,22 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type EditLogic struct {
type AdminEditLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
return &EditLogic{
func NewAdminEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminEditLogic {
return &AdminEditLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *EditLogic) Edit(in *admin.EditRequest) (*admin.Response, error) {
func (l *AdminEditLogic) AdminEdit(in *admin.AdminEditRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{
Msg: in.Name + " " + in.Pwd,
}, nil
return &admin.Response{}, nil
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AdminInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAdminInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminInfoLogic {
return &AdminInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AdminInfoLogic) AdminInfo(in *admin.AdminInfoRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AdminItemsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAdminItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminItemsLogic {
return &AdminItemsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AdminItemsLogic) AdminItems(in *admin.AdminItemsRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AdminLoginLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAdminLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminLoginLogic {
return &AdminLoginLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AdminLoginLogic) AdminLogin(in *admin.AdminLoginRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type AdminStatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAdminStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminStatusLogic {
return &AdminStatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AdminStatusLogic) AdminStatus(in *admin.StatusRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
+31
View File
@@ -0,0 +1,31 @@
package logic
import (
"admin/admin"
"pkg.local/utils"
validateService "pkg.local/validate"
)
type BaseLogic struct {
}
func (l *BaseLogic) checkParams(in *admin.AdminEditRequest, v validateService.IValidator) *admin.Response {
if resp := validateService.ValidateFromProto(in, v); resp != utils.StringEmpty {
return &admin.Response{Code: utils.ErrorParams.Code, Msg: resp}
}
return nil
}
func (l *AdminAddLogic) fail(status utils.Status) *admin.Response {
return &admin.Response{Code: status.Code, Msg: status.Msg}
}
func (l *AdminAddLogic) out(status utils.Status, msg string) *admin.Response {
return &admin.Response{Code: status.Code, Msg: msg}
}
func (l *AdminAddLogic) ok(data any) *admin.Response {
return &admin.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg}
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type OwnPasswordLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewOwnPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OwnPasswordLogic {
return &OwnPasswordLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *OwnPasswordLogic) OwnPassword(in *admin.OwnPasswordRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
@@ -9,21 +9,21 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
type StatusLogic struct {
type PasswordLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
return &StatusLogic{
func NewPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PasswordLogic {
return &PasswordLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *StatusLogic) Status(in *admin.StatusRequest) (*admin.Response, error) {
func (l *PasswordLogic) Password(in *admin.PasswordRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
+24
View File
@@ -0,0 +1,24 @@
package model
import (
"admin/internal/dao"
"pkg.local/modelbase"
)
type AdminModel struct {
modelbase.Base
}
func (m AdminModel) TableName() string {
return modelbase.Prefix() + "admin"
}
func (m AdminModel) Init() AdminModel {
m.Table = m.TableName()
return m
}
func (m AdminModel) Create(data *dao.Admin) error {
return m.Base.Create(data)
}
+34 -9
View File
@@ -23,17 +23,42 @@ func NewAdminServer(svcCtx *svc.ServiceContext) *AdminServer {
}
}
func (s *AdminServer) Add(ctx context.Context, in *admin.AddRequest) (*admin.Response, error) {
l := logic.NewAddLogic(ctx, s.svcCtx)
return l.Add(in)
func (s *AdminServer) AdminAdd(ctx context.Context, in *admin.AdminEditRequest) (*admin.Response, error) {
l := logic.NewAdminAddLogic(ctx, s.svcCtx)
return l.AdminAdd(in)
}
func (s *AdminServer) Edit(ctx context.Context, in *admin.EditRequest) (*admin.Response, error) {
l := logic.NewEditLogic(ctx, s.svcCtx)
return l.Edit(in)
func (s *AdminServer) AdminEdit(ctx context.Context, in *admin.AdminEditRequest) (*admin.Response, error) {
l := logic.NewAdminEditLogic(ctx, s.svcCtx)
return l.AdminEdit(in)
}
func (s *AdminServer) Status(ctx context.Context, in *admin.StatusRequest) (*admin.Response, error) {
l := logic.NewStatusLogic(ctx, s.svcCtx)
return l.Status(in)
func (s *AdminServer) AdminStatus(ctx context.Context, in *admin.StatusRequest) (*admin.Response, error) {
l := logic.NewAdminStatusLogic(ctx, s.svcCtx)
return l.AdminStatus(in)
}
func (s *AdminServer) Password(ctx context.Context, in *admin.PasswordRequest) (*admin.Response, error) {
l := logic.NewPasswordLogic(ctx, s.svcCtx)
return l.Password(in)
}
func (s *AdminServer) OwnPassword(ctx context.Context, in *admin.OwnPasswordRequest) (*admin.Response, error) {
l := logic.NewOwnPasswordLogic(ctx, s.svcCtx)
return l.OwnPassword(in)
}
func (s *AdminServer) AdminInfo(ctx context.Context, in *admin.AdminInfoRequest) (*admin.Response, error) {
l := logic.NewAdminInfoLogic(ctx, s.svcCtx)
return l.AdminInfo(in)
}
func (s *AdminServer) AdminItems(ctx context.Context, in *admin.AdminItemsRequest) (*admin.Response, error) {
l := logic.NewAdminItemsLogic(ctx, s.svcCtx)
return l.AdminItems(in)
}
func (s *AdminServer) AdminLogin(ctx context.Context, in *admin.AdminLoginRequest) (*admin.Response, error) {
l := logic.NewAdminLoginLogic(ctx, s.svcCtx)
return l.AdminLogin(in)
}