From 5f55223cd5db861f36fdb6547612741cf06f5940 Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Wed, 4 Jun 2025 17:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=EF=BC=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E9=97=A8=E5=BA=97=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/merchantAdmin/v1/merchantAdmin.go | 1 + api/store/v1/store.go | 11 +++ .../{merchant_admin.go => merchantAdmin.go} | 0 internal/consts/storeAdmin.go | 7 ++ .../controller/admin/admin_v1_admin_info.go | 2 +- .../controller/auth/auth_v1_store_login.go | 13 ++- .../controller/merchant/merchant_v1_audit.go | 2 +- .../controller/merchant/merchant_v1_create.go | 1 + .../controller/merchant/merchant_v1_update.go | 1 + .../merchantAdmin_v1_merchant_admin_info.go | 13 ++- internal/logic/logic.go | 2 + internal/logic/merchantAdmin/merchantAdmin.go | 16 +++- internal/logic/store/store.go | 1 + internal/logic/storeAdmin/storeAdmin.go | 93 +++++++++++++++++++ .../{merchant_admin.go => merchantAdmin.go} | 2 +- internal/model/store.go | 26 ++++++ internal/model/storeAdmin.go | 18 ++++ internal/service/store.go | 8 ++ internal/service/store_admin.go | 33 +++++++ 19 files changed, 237 insertions(+), 13 deletions(-) rename internal/consts/{merchant_admin.go => merchantAdmin.go} (100%) create mode 100644 internal/consts/storeAdmin.go create mode 100644 internal/logic/store/store.go create mode 100644 internal/logic/storeAdmin/storeAdmin.go rename internal/model/{merchant_admin.go => merchantAdmin.go} (98%) create mode 100644 internal/model/store.go create mode 100644 internal/model/storeAdmin.go create mode 100644 internal/service/store.go create mode 100644 internal/service/store_admin.go diff --git a/api/merchantAdmin/v1/merchantAdmin.go b/api/merchantAdmin/v1/merchantAdmin.go index 3a24027..f150513 100644 --- a/api/merchantAdmin/v1/merchantAdmin.go +++ b/api/merchantAdmin/v1/merchantAdmin.go @@ -8,4 +8,5 @@ type MerchantAdminInfoReq struct { g.Meta `path:"/merchant/info" method:"get" tags:"MerchantAdmin" summary:"(商户管理员)获取商户管理员信息"` } type MerchantAdminInfoRes struct { + Name string } diff --git a/api/store/v1/store.go b/api/store/v1/store.go index f303695..4278a3a 100644 --- a/api/store/v1/store.go +++ b/api/store/v1/store.go @@ -35,3 +35,14 @@ type UpdateReq struct { type UpdateRes struct { Success bool `json:"success" dc:"是否成功"` } +type DeleteReq struct { + g.Meta `path:"/store" method:"delete" tags:"Store" summary:"(商户管理员)删除门店"` + Id int64 `json:"id" v:"required" dc:"门店ID"` +} +type DeleteRes struct { + Success bool `json:"success" dc:"是否成功"` +} +type BatchDeleteReq struct { + g.Meta `path:"/store/batch" method:"delete" tags:"Store" summary:"(商户管理员)批量删除门店"` + Ids []int `json:"ids" v:"required" dc:"门店ID"` +} diff --git a/internal/consts/merchant_admin.go b/internal/consts/merchantAdmin.go similarity index 100% rename from internal/consts/merchant_admin.go rename to internal/consts/merchantAdmin.go diff --git a/internal/consts/storeAdmin.go b/internal/consts/storeAdmin.go new file mode 100644 index 0000000..52300ae --- /dev/null +++ b/internal/consts/storeAdmin.go @@ -0,0 +1,7 @@ +package consts + +// 门店管理员状态 +const ( + StoreAdminEnable = iota + 1 + StoreAdminDisable +) diff --git a/internal/controller/admin/admin_v1_admin_info.go b/internal/controller/admin/admin_v1_admin_info.go index 3c61443..b8d8679 100644 --- a/internal/controller/admin/admin_v1_admin_info.go +++ b/internal/controller/admin/admin_v1_admin_info.go @@ -11,7 +11,7 @@ import ( ) func (c *ControllerV1) AdminInfo(ctx context.Context, req *v1.AdminInfoReq) (res *v1.AdminInfoRes, err error) { - userId := g.RequestFromCtx(ctx).GetCtxVar("userId").Int64() + userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64() out, err := service.Admin().Info(ctx, &model.AdminInfoIn{Id: userId}) if err != nil { return nil, err diff --git a/internal/controller/auth/auth_v1_store_login.go b/internal/controller/auth/auth_v1_store_login.go index f64162d..8f60c5c 100644 --- a/internal/controller/auth/auth_v1_store_login.go +++ b/internal/controller/auth/auth_v1_store_login.go @@ -3,12 +3,15 @@ package auth import ( "context" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - - "server/api/auth/v1" + v1 "server/api/auth/v1" + "server/internal/model" + "server/internal/service" ) func (c *ControllerV1) StoreLogin(ctx context.Context, req *v1.StoreLoginReq) (res *v1.StoreLoginRes, err error) { - return nil, gerror.NewCode(gcode.CodeNotImplemented) + out, err := service.StoreAdmin().Login(ctx, &model.StoreAdminLoginIn{Username: req.Username, Password: req.Password}) + if err != nil { + return nil, err + } + return &v1.StoreLoginRes{Token: out.Token}, nil } diff --git a/internal/controller/merchant/merchant_v1_audit.go b/internal/controller/merchant/merchant_v1_audit.go index 18f6b92..6fed20b 100644 --- a/internal/controller/merchant/merchant_v1_audit.go +++ b/internal/controller/merchant/merchant_v1_audit.go @@ -10,7 +10,7 @@ import ( ) func (c *ControllerV1) Audit(ctx context.Context, req *v1.AuditReq) (res *v1.AuditRes, err error) { - adminId := g.RequestFromCtx(ctx).GetCtxVar("adminId").Int64() + adminId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64() _, err = service.Merchant().Audit(ctx, &model.MerchantAuditIn{Id: req.Id, AuditStatus: req.AuditStatus, AuditRemark: req.AuditRemark, AdminId: adminId, RejectReason: req.RejectReason}) if err != nil { return nil, err diff --git a/internal/controller/merchant/merchant_v1_create.go b/internal/controller/merchant/merchant_v1_create.go index ed52cd0..473c9c3 100644 --- a/internal/controller/merchant/merchant_v1_create.go +++ b/internal/controller/merchant/merchant_v1_create.go @@ -10,5 +10,6 @@ import ( ) func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { + // TODO return nil, gerror.NewCode(gcode.CodeNotImplemented) } diff --git a/internal/controller/merchant/merchant_v1_update.go b/internal/controller/merchant/merchant_v1_update.go index 5265c58..9be33e8 100644 --- a/internal/controller/merchant/merchant_v1_update.go +++ b/internal/controller/merchant/merchant_v1_update.go @@ -10,5 +10,6 @@ import ( ) func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) { + // TODO return nil, gerror.NewCode(gcode.CodeNotImplemented) } diff --git a/internal/controller/merchantAdmin/merchantAdmin_v1_merchant_admin_info.go b/internal/controller/merchantAdmin/merchantAdmin_v1_merchant_admin_info.go index 9874cf7..2f74869 100644 --- a/internal/controller/merchantAdmin/merchantAdmin_v1_merchant_admin_info.go +++ b/internal/controller/merchantAdmin/merchantAdmin_v1_merchant_admin_info.go @@ -2,13 +2,18 @@ package merchantAdmin import ( "context" - - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" + "server/internal/model" + "server/internal/service" "server/api/merchantAdmin/v1" ) func (c *ControllerV1) MerchantAdminInfo(ctx context.Context, req *v1.MerchantAdminInfoReq) (res *v1.MerchantAdminInfoRes, err error) { - return nil, gerror.NewCode(gcode.CodeNotImplemented) + merchantAdminId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64() + info, err := service.MerchantAdmin().Info(ctx, &model.MerchantAdminInfoIn{MerchantAdminId: merchantAdminId}) + if err != nil { + return nil, err + } + return &v1.MerchantAdminInfoRes{Name: info.Name}, nil } diff --git a/internal/logic/logic.go b/internal/logic/logic.go index 4785ed4..024e05f 100644 --- a/internal/logic/logic.go +++ b/internal/logic/logic.go @@ -10,5 +10,7 @@ import ( _ "server/internal/logic/merchant" _ "server/internal/logic/merchantAdmin" _ "server/internal/logic/role" + _ "server/internal/logic/store" + _ "server/internal/logic/storeAdmin" _ "server/internal/logic/user" ) diff --git a/internal/logic/merchantAdmin/merchantAdmin.go b/internal/logic/merchantAdmin/merchantAdmin.go index 16a9794..0a3d5af 100644 --- a/internal/logic/merchantAdmin/merchantAdmin.go +++ b/internal/logic/merchantAdmin/merchantAdmin.go @@ -12,6 +12,7 @@ import ( "server/internal/dao" "server/internal/model" "server/internal/model/do" + "server/internal/model/entity" "server/internal/service" "server/utility/ecode" utility "server/utility/encrypt" @@ -88,7 +89,20 @@ func (s *sMerchantAdmin) Login(ctx context.Context, in *model.MerchantLoginIn) ( return } func (s *sMerchantAdmin) Info(ctx context.Context, in *model.MerchantAdminInfoIn) (out *model.MerchantAdminInfoOut, err error) { - return + one, err := dao.MerchantAdmins.Ctx(ctx).WherePri(in.MerchantAdminId).One() + if err != nil { + return nil, ecode.Fail.Sub("查询商户管理员失败") + } + if one.IsEmpty() { + return nil, ecode.Params.Sub("商户管理员不存在") + } + var admin entity.MerchantAdmins + if err = one.Struct(&admin); err != nil { + return nil, ecode.Fail.Sub("查询商户管理员失败") + } + return &model.MerchantAdminInfoOut{ + Name: admin.Username, + }, nil } func (s *sMerchantAdmin) Code(ctx context.Context, in *model.MerchantAdminCodeIn) (out *model.MerchantAdminCodeOut, err error) { exist, err := dao.MerchantAdmins.Ctx(ctx).Where(do.MerchantAdmins{Phone: in.Phone}).Exist() diff --git a/internal/logic/store/store.go b/internal/logic/store/store.go new file mode 100644 index 0000000..72440ea --- /dev/null +++ b/internal/logic/store/store.go @@ -0,0 +1 @@ +package store diff --git a/internal/logic/storeAdmin/storeAdmin.go b/internal/logic/storeAdmin/storeAdmin.go new file mode 100644 index 0000000..51e6429 --- /dev/null +++ b/internal/logic/storeAdmin/storeAdmin.go @@ -0,0 +1,93 @@ +package storeAdmin + +import ( + "context" + "server/internal/consts" + "server/internal/dao" + "server/internal/model" + "server/internal/model/do" + "server/internal/model/entity" + "server/internal/service" + "server/utility/ecode" + utility "server/utility/encrypt" + "server/utility/jwt" +) + +type sStoreAdmin struct { +} + +func New() service.IStoreAdmin { + return &sStoreAdmin{} +} + +func init() { + service.RegisterStoreAdmin(New()) + go checkStoreAdminRole() +} + +func checkStoreAdminRole() { + ctx := context.Background() + exist, err := dao.Roles.Ctx(ctx).Where(do.Roles{Code: consts.StoreRoleCode}).Exist() + if err != nil { + return + } + if !exist { + _, err = dao.Roles.Ctx(ctx).Insert(do.Roles{ + Name: "门店管理员", + Code: consts.StoreRoleCode, + Description: "门店管理员角色", + Status: consts.StoreAdminEnable, + IsDeletable: false, + }) + if err != nil { + return + } + } +} + +func (s *sStoreAdmin) Login(ctx context.Context, in *model.StoreAdminLoginIn) (out *model.StoreAdminLoginOut, err error) { + one, err := dao.StoreAdmins.Ctx(ctx).Where(do.StoreAdmins{Username: in.Username}).One() + if err != nil { + return nil, ecode.Fail.Sub("查询商户管理员失败") + } + if one.IsEmpty() { + return nil, ecode.Params.Sub("该用户不存在") + } + if one[dao.StoreAdmins.Columns().Status].Int() == consts.StoreAdminDisable { + return nil, ecode.Params.Sub("该用户已被禁用") + } + if !utility.ComparePassword(one[dao.StoreAdmins.Columns().PasswordHash].String(), in.Password) { + return nil, ecode.Params.Sub("密码错误") + } + value, err := dao.Roles.Ctx(ctx).WherePri(one[dao.StoreAdmins.Columns().RoleId].Int()).Fields(dao.Roles.Columns().Code).Value() + if err != nil { + return nil, ecode.Fail.Sub("查询角色失败") + } + + token, err := jwt.GenerateToken(&jwt.TokenIn{UserId: one[dao.StoreAdmins.Columns().Id].Int64(), Role: value.String()}) + if err != nil { + return nil, ecode.Fail.Sub("生成token失败") + } + out = &model.StoreAdminLoginOut{ + Token: token, + } + return +} +func (s *sStoreAdmin) Info(ctx context.Context, in *model.StoreAdminInfoIn) (out *model.StoreAdminInfoOut, err error) { + exist, err := dao.StoreAdmins.Ctx(ctx).WherePri(in.StoreAdminId).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查询门店管理员失败") + } + if !exist { + return nil, ecode.Params.Sub("该用户不存在") + } + var storeAdmin entity.StoreAdmins + err = dao.StoreAdmins.Ctx(ctx).WherePri(in.StoreAdminId).Scan(&storeAdmin) + if err != nil { + return nil, ecode.Fail.Sub("查询门店管理员失败") + } + out = &model.StoreAdminInfoOut{ + Username: storeAdmin.Username, + } + return +} diff --git a/internal/model/merchant_admin.go b/internal/model/merchantAdmin.go similarity index 98% rename from internal/model/merchant_admin.go rename to internal/model/merchantAdmin.go index 6dca47a..c1ee535 100644 --- a/internal/model/merchant_admin.go +++ b/internal/model/merchantAdmin.go @@ -19,7 +19,7 @@ type MerchantAdminInfoIn struct { MerchantAdminId int64 } type MerchantAdminInfoOut struct { - *MerchantAdmin + Name string } type MerchantAdminCodeIn struct { Phone string diff --git a/internal/model/store.go b/internal/model/store.go new file mode 100644 index 0000000..7207b73 --- /dev/null +++ b/internal/model/store.go @@ -0,0 +1,26 @@ +package model + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +type Store struct { + g.Meta `orm:"table:stores"` // 绑定表名 + Id int64 `json:"id" orm:"id,primary" dc:"门店ID"` + MerchantId int64 `json:"merchantId" orm:"merchant_id,not null" dc:"所属商户ID"` + Name string `json:"name" orm:"name,not null" dc:"门店名称"` + StoreCode string `json:"storeCode" orm:"store_code,unique" dc:"门店编号"` + Address string `json:"address" orm:"address" dc:"门店地址"` + ContactName string `json:"contactName" orm:"contact_name" dc:"联系人姓名"` + ContactPhone string `json:"contactPhone" orm:"contact_phone" dc:"联系人电话"` + Status int `json:"status" orm:"status,default:1" dc:"状态:1=正常营业,2=暂停营业,3=已关闭"` +} + +type CreateIn struct { + Name string `json:"name" v:"required" dc:"门店名称"` +} + +type UpdateIn struct { + Id int + Name string +} diff --git a/internal/model/storeAdmin.go b/internal/model/storeAdmin.go new file mode 100644 index 0000000..73314df --- /dev/null +++ b/internal/model/storeAdmin.go @@ -0,0 +1,18 @@ +package model + +type StoreAdminInfoIn struct { + StoreAdminId int64 +} + +type StoreAdminInfoOut struct { + Username string +} + +type StoreAdminLoginIn struct { + Username string + Password string +} + +type StoreAdminLoginOut struct { + Token string +} diff --git a/internal/service/store.go b/internal/service/store.go new file mode 100644 index 0000000..3d70438 --- /dev/null +++ b/internal/service/store.go @@ -0,0 +1,8 @@ +// ================================================================================ +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// You can delete these comments if you wish manually maintain this interface file. +// ================================================================================ + +package service + +type () diff --git a/internal/service/store_admin.go b/internal/service/store_admin.go new file mode 100644 index 0000000..982cef5 --- /dev/null +++ b/internal/service/store_admin.go @@ -0,0 +1,33 @@ +// ================================================================================ +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// You can delete these comments if you wish manually maintain this interface file. +// ================================================================================ + +package service + +import ( + "context" + "server/internal/model" +) + +type ( + IStoreAdmin interface { + Login(ctx context.Context, in *model.StoreAdminLoginIn) (out *model.StoreAdminLoginOut, err error) + Info(ctx context.Context, in *model.StoreAdminInfoIn) (out *model.StoreAdminInfoOut, err error) + } +) + +var ( + localStoreAdmin IStoreAdmin +) + +func StoreAdmin() IStoreAdmin { + if localStoreAdmin == nil { + panic("implement not found for interface IStoreAdmin, forgot register?") + } + return localStoreAdmin +} + +func RegisterStoreAdmin(i IStoreAdmin) { + localStoreAdmin = i +}