From 9d20953377e8c3c6d209fb69703fb3dd2efa077a Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Thu, 5 Jun 2025 11:43:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E7=9A=84=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/consts/redis.go | 13 +++ internal/dao/internal/feedbacks.go | 6 +- internal/dao/internal/store_admins.go | 4 +- internal/dao/internal/stores.go | 2 +- internal/logic/store/store.go | 114 ++++++++++++++++++++------ internal/logic/user/user.go | 5 ++ internal/model/do/feedbacks.go | 4 +- internal/model/do/store_admins.go | 2 +- internal/model/do/stores.go | 2 +- internal/model/entity/feedbacks.go | 4 +- internal/model/entity/store_admins.go | 28 +++---- internal/model/entity/stores.go | 22 ++--- internal/model/store.go | 17 +++- internal/model/user.go | 8 ++ 14 files changed, 167 insertions(+), 64 deletions(-) create mode 100644 internal/consts/redis.go diff --git a/internal/consts/redis.go b/internal/consts/redis.go new file mode 100644 index 0000000..e8564c6 --- /dev/null +++ b/internal/consts/redis.go @@ -0,0 +1,13 @@ +package consts + +// Redis key 前缀 +const ( + // 用户相关 + UserCode = "user:code:" // 用户验证码 + UserToken = "user:token:" // 用户token + UserInfo = "user:info:" // 用户信息 + + // 系统相关 + SystemConfig = "system:config" // 系统配置 + SystemCache = "system:cache:" // 系统缓存 +) diff --git a/internal/dao/internal/feedbacks.go b/internal/dao/internal/feedbacks.go index 60773b2..f633096 100644 --- a/internal/dao/internal/feedbacks.go +++ b/internal/dao/internal/feedbacks.go @@ -25,11 +25,13 @@ type FeedbacksColumns struct { Title string // 反馈标题 Content string // 反馈内容 FeedbackType string // 反馈类型:1=BUG,2=建议,3=投诉,4=其他 - Status string // 处理状态:0=待处理,1=处理中,2=已处理,3=已驳回 + Status string // 处理状态:1=待处理,2=处理中,3=已处理,4=已驳回 Reply string // 管理员回复内容 CreatedAt string // 反馈提交时间 UpdatedAt string // 反馈更新时间 DeletedAt string // 软删除时间戳 + StoreId string // 门店唯一 id + MerchatId string // 商户唯一 id } // feedbacksColumns holds the columns for the table feedbacks. @@ -44,6 +46,8 @@ var feedbacksColumns = FeedbacksColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", + StoreId: "store_id", + MerchatId: "merchat_id", } // NewFeedbacksDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/store_admins.go b/internal/dao/internal/store_admins.go index 730a2a5..7ab00ec 100644 --- a/internal/dao/internal/store_admins.go +++ b/internal/dao/internal/store_admins.go @@ -27,7 +27,7 @@ type StoreAdminsColumns struct { RealName string // 真实姓名 Phone string // 手机号 Email string // 邮箱 - Role string // 角色:1=店长,2=收银员,3=网管 + IsPrimary string // 是否为主账号(1=是,0=否) Status string // 状态:1=正常,2=禁用 LastLoginAt string // 最后登录时间 CreatedAt string // 创建时间 @@ -45,7 +45,7 @@ var storeAdminsColumns = StoreAdminsColumns{ RealName: "real_name", Phone: "phone", Email: "email", - Role: "role", + IsPrimary: "is_primary", Status: "status", LastLoginAt: "last_login_at", CreatedAt: "created_at", diff --git a/internal/dao/internal/stores.go b/internal/dao/internal/stores.go index d64c8d8..b97c4c8 100644 --- a/internal/dao/internal/stores.go +++ b/internal/dao/internal/stores.go @@ -27,7 +27,7 @@ type StoresColumns struct { Address string // 门店地址 ContactName string // 联系人姓名 ContactPhone string // 联系人电话 - Status string // 状态:1=正常营业,2=暂停营业,3=已关闭 + Status string // 状态:1=正常营业,2=暂停营业 CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 软删除时间戳 diff --git a/internal/logic/store/store.go b/internal/logic/store/store.go index 84471c3..4ef5490 100644 --- a/internal/logic/store/store.go +++ b/internal/logic/store/store.go @@ -2,13 +2,13 @@ package store import ( "context" + "github.com/gogf/gf/v2/database/gdb" + "server/internal/consts" "server/internal/dao" "server/internal/model" "server/internal/model/do" "server/internal/service" "server/utility/ecode" - - "github.com/gogf/gf/v2/database/gdb" ) type sStore struct { @@ -26,6 +26,7 @@ func (s *sStore) List(ctx context.Context, in *model.StoreListIn) (out *model.St } func (s *sStore) Create(ctx context.Context, in *model.StoreCreateIn) (out *model.CreateOut, err error) { + out = &model.CreateOut{} // 1. 检查门店名称是否重复 exist, err := dao.Stores.Ctx(ctx).Where(do.Stores{Name: in.Name}).Exist() if err != nil { @@ -36,11 +37,31 @@ func (s *sStore) Create(ctx context.Context, in *model.StoreCreateIn) (out *mode } // 2. 使用事务处理数据插入 - if err = dao.Stores.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { - // 2.1 生成唯一的门店编号 - // 2.2 插入门店基本信息 - // 2.3 创建门店管理员账号 - // 2.4 初始化门店配置 + if err = dao.Stores.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + // 2.1 根据商户 id 获取所属的商户 + value, err := dao.MerchantAdmins.Ctx(ctx).WherePri(in.MerchantAdminId).Fields(dao.MerchantAdmins.Columns().MerchantId).Value() + if err != nil { + return ecode.Fail.Sub("获取商户ID出现异常") + } + // 2,2 生成门店的相关信息 + + // 2.3 插入门店数据 + id, err := tx.Model(dao.Stores.Table()).Data(do.Stores{ + MerchantId: value.Int64(), + }).InsertAndGetId() + if err != nil { + return ecode.Fail.Sub("新增门店出现异常") + } + + //2.4 生成门店主管理账号 + + // 2.5 插入门店管理员数据 + _, err = tx.Model(dao.StoreAdmins.Table()).Data(do.StoreAdmins{ + StoreId: id, + }).Insert() + if err != nil { + return ecode.Fail.Sub("新增门店管理员出现异常") + } return nil }); err != nil { return nil, err @@ -48,30 +69,69 @@ func (s *sStore) Create(ctx context.Context, in *model.StoreCreateIn) (out *mode return } + func (s *sStore) Update(ctx context.Context, in *model.StoreUpdateIn) (out *model.UpdateOut, err error) { - // 1. 验证门店是否存在 - // 2. 验证操作权限(商户管理员或门店管理员) - // 3. 检查更新后的门店名称是否重复 - // 4. 使用事务更新门店信息 - // 5. 记录操作日志 - return + exist, err := dao.Stores.Ctx(ctx).WherePri(in.Id).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查询门店出现异常") + } + if !exist { + return nil, ecode.Params.Sub("门店不存在") + } + + if in.OperatorId == 0 || (in.OperatorRole != consts.MerchantRoleCode && in.OperatorRole != consts.StoreRoleCode) { + return nil, ecode.InvalidOperation.Sub("无权限操作") + } + + if in.Name != "" { + exist, err = dao.Stores.Ctx(ctx).Where(dao.Stores.Columns().Name, in.Name).WhereNot(dao.Stores.Columns().Id, in.Id).Exist() + if err != nil { + return nil, ecode.Fail.Sub("检查门店名称出现异常") + } + if exist { + return nil, ecode.Params.Sub("门店名称已存在") + } + } + + _, err = dao.Stores.Ctx(ctx).WherePri(in.Id).Data(do.Stores{ + Name: in.Name, + Address: in.Address, + ContactName: in.ContactName, + ContactPhone: in.ContactPhone, // TODO:暂定可以直接修改,后续可能需要验证手机号 + Status: in.Status, + }).Update() + if err != nil { + return nil, ecode.Fail.Sub("更新门店出现异常") + } + return &model.UpdateOut{Success: true}, nil } + func (s *sStore) Delete(ctx context.Context, in *model.StoreDeleteIn) (out *model.DeleteOut, err error) { - // 1. 验证门店是否存在 - // 2. 验证操作权限(仅允许商户管理员) - // 3. 检查门店状态(是否有关联数据) - // 4. 使用事务处理删除操作 - // 5. 清理相关数据 - // 6. 记录操作日志 - return + exist, err := dao.Stores.Ctx(ctx).WherePri(in.Id).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查询门店出现异常") + } + if !exist { + return nil, ecode.Params.Sub("门店不存在") + } + + if in.OperatorId == 0 || (in.OperatorRole != consts.MerchantRoleCode) { + return nil, ecode.InvalidOperation.Sub("无权限操作") + } + // TODO: 是否需要检查门店下存在未发放奖励等 + + return &model.DeleteOut{Success: true}, nil } + func (s *sStore) Info(ctx context.Context, in *model.StoreInfoIn) (out *model.StoreInfoOut, err error) { - // 1. 验证门店是否存在 - // 2. 验证访问权限 - // 3. 获取门店基本信息 - // 4. 获取门店配置信息 - // 5. 获取门店管理员信息 - // 6. 获取门店统计信息 - // 7. 处理敏感信息 + exist, err := dao.Stores.Ctx(ctx).Where(do.Stores{Id: in.Id}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查询门店出现异常") + } + if !exist { + return nil, ecode.Params.Sub("门店不存在") + } + + // TODO 获取门店信息等相关信息 return } diff --git a/internal/logic/user/user.go b/internal/logic/user/user.go index 78c1d1f..393a927 100644 --- a/internal/logic/user/user.go +++ b/internal/logic/user/user.go @@ -117,14 +117,19 @@ func (s *sUser) Info(ctx context.Context, in *model.UserInfoIn) (out *model.User return } +func (s *sUser) Code(ctx context.Context, in *model.UserCodeIn) (out *model.UserCodeOut, err error) { + return +} func (s *sUser) Update(ctx context.Context, in *model.UserUpdateIn) (out *model.UpdateOut, err error) { return } func (s *sUser) BindPhone(ctx context.Context, in *model.UserBindPhoneIn) (out *model.UpdateOut, err error) { + // 绑定手机号,需要验证入参和缓存中的验证码时候相同 return } func (s *sUser) List(ctx context.Context, in *model.UserListIn) (out *model.UserListOut, err error) { + // 用于系统管理员、商户、门店查看用户列表, 展示用户最近的相关信息 return } diff --git a/internal/model/do/feedbacks.go b/internal/model/do/feedbacks.go index ada2cd5..835c321 100644 --- a/internal/model/do/feedbacks.go +++ b/internal/model/do/feedbacks.go @@ -17,9 +17,11 @@ type Feedbacks struct { Title interface{} // 反馈标题 Content interface{} // 反馈内容 FeedbackType interface{} // 反馈类型:1=BUG,2=建议,3=投诉,4=其他 - Status interface{} // 处理状态:0=待处理,1=处理中,2=已处理,3=已驳回 + Status interface{} // 处理状态:1=待处理,2=处理中,3=已处理,4=已驳回 Reply interface{} // 管理员回复内容 CreatedAt *gtime.Time // 反馈提交时间 UpdatedAt *gtime.Time // 反馈更新时间 DeletedAt *gtime.Time // 软删除时间戳 + StoreId interface{} // 门店唯一 id + MerchatId interface{} // 商户唯一 id } diff --git a/internal/model/do/store_admins.go b/internal/model/do/store_admins.go index 6de570a..e1e78d6 100644 --- a/internal/model/do/store_admins.go +++ b/internal/model/do/store_admins.go @@ -19,7 +19,7 @@ type StoreAdmins struct { RealName interface{} // 真实姓名 Phone interface{} // 手机号 Email interface{} // 邮箱 - Role interface{} // 角色:1=店长,2=收银员,3=网管 + IsPrimary interface{} // 是否为主账号(1=是,0=否) Status interface{} // 状态:1=正常,2=禁用 LastLoginAt *gtime.Time // 最后登录时间 CreatedAt *gtime.Time // 创建时间 diff --git a/internal/model/do/stores.go b/internal/model/do/stores.go index 654ef99..613724c 100644 --- a/internal/model/do/stores.go +++ b/internal/model/do/stores.go @@ -19,7 +19,7 @@ type Stores struct { Address interface{} // 门店地址 ContactName interface{} // 联系人姓名 ContactPhone interface{} // 联系人电话 - Status interface{} // 状态:1=正常营业,2=暂停营业,3=已关闭 + Status interface{} // 状态:1=正常营业,2=暂停营业 CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 软删除时间戳 diff --git a/internal/model/entity/feedbacks.go b/internal/model/entity/feedbacks.go index cab8cbe..ac25a32 100644 --- a/internal/model/entity/feedbacks.go +++ b/internal/model/entity/feedbacks.go @@ -15,9 +15,11 @@ type Feedbacks struct { Title string `json:"title" orm:"title" description:"反馈标题"` // 反馈标题 Content string `json:"content" orm:"content" description:"反馈内容"` // 反馈内容 FeedbackType int `json:"feedbackType" orm:"feedback_type" description:"反馈类型:1=BUG,2=建议,3=投诉,4=其他"` // 反馈类型:1=BUG,2=建议,3=投诉,4=其他 - Status int `json:"status" orm:"status" description:"处理状态:0=待处理,1=处理中,2=已处理,3=已驳回"` // 处理状态:0=待处理,1=处理中,2=已处理,3=已驳回 + Status int `json:"status" orm:"status" description:"处理状态:1=待处理,2=处理中,3=已处理,4=已驳回"` // 处理状态:1=待处理,2=处理中,3=已处理,4=已驳回 Reply string `json:"reply" orm:"reply" description:"管理员回复内容"` // 管理员回复内容 CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"反馈提交时间"` // 反馈提交时间 UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"反馈更新时间"` // 反馈更新时间 DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 + StoreId int64 `json:"storeId" orm:"store_id" description:"门店唯一 id"` // 门店唯一 id + MerchatId int64 `json:"merchatId" orm:"merchat_id" description:"商户唯一 id"` // 商户唯一 id } diff --git a/internal/model/entity/store_admins.go b/internal/model/entity/store_admins.go index 80edc92..f05dfe3 100644 --- a/internal/model/entity/store_admins.go +++ b/internal/model/entity/store_admins.go @@ -10,18 +10,18 @@ import ( // StoreAdmins is the golang structure for table store_admins. type StoreAdmins struct { - Id int64 `json:"id" orm:"id" description:"门店管理员ID"` // 门店管理员ID - StoreId int64 `json:"storeId" orm:"store_id" description:"所属门店ID"` // 所属门店ID - Username string `json:"username" orm:"username" description:"用户名"` // 用户名 - PasswordHash string `json:"passwordHash" orm:"password_hash" description:"密码哈希"` // 密码哈希 - RealName string `json:"realName" orm:"real_name" description:"真实姓名"` // 真实姓名 - Phone string `json:"phone" orm:"phone" description:"手机号"` // 手机号 - Email string `json:"email" orm:"email" description:"邮箱"` // 邮箱 - Role int `json:"role" orm:"role" description:"角色:1=店长,2=收银员,3=网管"` // 角色:1=店长,2=收银员,3=网管 - Status int `json:"status" orm:"status" description:"状态:1=正常,2=禁用"` // 状态:1=正常,2=禁用 - LastLoginAt *gtime.Time `json:"lastLoginAt" orm:"last_login_at" description:"最后登录时间"` // 最后登录时间 - CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间 - UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间 - DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 - RoleId int64 `json:"roleId" orm:"role_id" description:"角色ID"` // 角色ID + Id int64 `json:"id" orm:"id" description:"门店管理员ID"` // 门店管理员ID + StoreId int64 `json:"storeId" orm:"store_id" description:"所属门店ID"` // 所属门店ID + Username string `json:"username" orm:"username" description:"用户名"` // 用户名 + PasswordHash string `json:"passwordHash" orm:"password_hash" description:"密码哈希"` // 密码哈希 + RealName string `json:"realName" orm:"real_name" description:"真实姓名"` // 真实姓名 + Phone string `json:"phone" orm:"phone" description:"手机号"` // 手机号 + Email string `json:"email" orm:"email" description:"邮箱"` // 邮箱 + IsPrimary bool `json:"isPrimary" orm:"is_primary" description:"是否为主账号(1=是,0=否)"` // 是否为主账号(1=是,0=否) + Status int `json:"status" orm:"status" description:"状态:1=正常,2=禁用"` // 状态:1=正常,2=禁用 + LastLoginAt *gtime.Time `json:"lastLoginAt" orm:"last_login_at" description:"最后登录时间"` // 最后登录时间 + CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间 + UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间 + DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 + RoleId int64 `json:"roleId" orm:"role_id" description:"角色ID"` // 角色ID } diff --git a/internal/model/entity/stores.go b/internal/model/entity/stores.go index fa0bbf8..6a1c985 100644 --- a/internal/model/entity/stores.go +++ b/internal/model/entity/stores.go @@ -10,15 +10,15 @@ import ( // Stores is the golang structure for table stores. type Stores struct { - Id int64 `json:"id" orm:"id" description:"门店ID"` // 门店ID - MerchantId int64 `json:"merchantId" orm:"merchant_id" description:"所属商户ID"` // 所属商户ID - Name string `json:"name" orm:"name" description:"门店名称"` // 门店名称 - StoreCode string `json:"storeCode" orm:"store_code" description:"门店编号"` // 门店编号 - Address string `json:"address" orm:"address" description:"门店地址"` // 门店地址 - ContactName string `json:"contactName" orm:"contact_name" description:"联系人姓名"` // 联系人姓名 - ContactPhone string `json:"contactPhone" orm:"contact_phone" description:"联系人电话"` // 联系人电话 - Status int `json:"status" orm:"status" description:"状态:1=正常营业,2=暂停营业,3=已关闭"` // 状态:1=正常营业,2=暂停营业,3=已关闭 - CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间 - UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间 - DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 + Id int64 `json:"id" orm:"id" description:"门店ID"` // 门店ID + MerchantId int64 `json:"merchantId" orm:"merchant_id" description:"所属商户ID"` // 所属商户ID + Name string `json:"name" orm:"name" description:"门店名称"` // 门店名称 + StoreCode string `json:"storeCode" orm:"store_code" description:"门店编号"` // 门店编号 + Address string `json:"address" orm:"address" description:"门店地址"` // 门店地址 + ContactName string `json:"contactName" orm:"contact_name" description:"联系人姓名"` // 联系人姓名 + ContactPhone string `json:"contactPhone" orm:"contact_phone" description:"联系人电话"` // 联系人电话 + Status int `json:"status" orm:"status" description:"状态:1=正常营业,2=暂停营业"` // 状态:1=正常营业,2=暂停营业 + CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间 + UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间 + DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 } diff --git a/internal/model/store.go b/internal/model/store.go index e28d6dc..555416f 100644 --- a/internal/model/store.go +++ b/internal/model/store.go @@ -17,12 +17,19 @@ type Store struct { } type StoreCreateIn struct { - Name string + MerchantAdminId int64 + Name string } type StoreUpdateIn struct { - Id int - Name string + OperatorId int64 + OperatorRole string + Id int + Name string + Address string + ContactPhone string + ContactName string + Status int } type StoreListIn struct { @@ -43,5 +50,7 @@ type StoreInfoOut struct { } type StoreDeleteIn struct { - Id int + Id int + OperatorId int + OperatorRole string } diff --git a/internal/model/user.go b/internal/model/user.go index 9cc46a9..5a03eca 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -84,3 +84,11 @@ type UserListOut struct { List []User Total int } + +type UserCodeIn struct { + UserId int // 绑定手机号时需要使用该字段 + Phone string +} + +type UserCodeOut struct { +}