调整商户注册逻辑

This commit is contained in:
2025-06-11 10:24:48 +08:00
parent a3c6b20a04
commit efdbb21261
31 changed files with 310 additions and 302 deletions

View File

@ -7,7 +7,7 @@ type ListReq struct {
Page int `json:"page" dc:"页数"`
Size int `json:"size" dc:"每页数量"`
Status int `json:"status" dc:"状态1=启用2=禁用"`
AuditStatus int `json:"auditStatus" dc:"审核状态:0=待审核,1=审核通过,2=审核拒绝"`
AuditStatus int `json:"auditStatus" dc:"审核状态:1=待审核,2=审核通过,3=审核拒绝"`
}
type ListRes struct {
List interface{} `json:"list" dc:"商户列表"`
@ -31,7 +31,7 @@ type UpdateRes struct {
type AuditReq struct {
g.Meta `path:"/merchant/audit" method:"post" tags:"Merchant" summary:"(系统管理员)商户审核"`
Id int64 `json:"id" v:"required" dc:"商户ID"`
AuditStatus int `json:"auditStatus" v:"required" dc:"审核状态:1=审核通过,2=审核拒绝" `
AuditStatus int `json:"auditStatus" v:"required" dc:"审核状态:2=审核通过,3=审核拒绝" `
AuditRemark string `json:"auditRemark" dc:"审核备注"`
RejectReason string `json:"rejectReason" dc:"拒绝原因"`
}

View File

@ -8,5 +8,7 @@ type MerchantAdminInfoReq struct {
g.Meta `path:"/merchant/info" method:"get" tags:"MerchantAdmin" summary:"(商户管理员)获取商户管理员信息"`
}
type MerchantAdminInfoRes struct {
Name string
MerchantId int64 `json:"merchantId"`
Username string `json:"username"`
StoreId int64 `json:"storeId"` // 下属门店 id
}

View File

@ -4,6 +4,6 @@
gfcli:
gen:
dao:
- link: "mysql:root:MSms0427@tcp(192.168.3.132:3306)/arenax"
- link: "mysql:root:MSms0427@tcp(localhost:3306)/arenax"
descriptionTag: true
tablesEx: "casbin_rule"

View File

@ -10,6 +10,7 @@ import (
"server/internal/controller/feedback"
"server/internal/controller/game"
"server/internal/controller/merchant"
"server/internal/controller/merchantAdmin"
"server/internal/controller/reward"
"server/internal/controller/rewardType"
"server/internal/controller/role"
@ -38,6 +39,7 @@ var (
group.Middleware(middleware.Auth)
group.Middleware(middleware.Casbin)
group.Bind(
merchantAdmin.NewV1(),
upload.NewV1(),
admin.NewV1(),
role.NewV1(),

View File

@ -8,7 +8,7 @@ const (
// 商户审核状态
const (
MerchantPendingReview = iota
MerchantPendingReview = iota + 1
MerchantReviewPassed
MerchantReviewRejected
)

6
internal/consts/store.go Normal file
View File

@ -0,0 +1,6 @@
package consts
const (
StoreEnable = iota + 1
StoreDisable
)

View File

@ -15,5 +15,5 @@ func (c *ControllerV1) MerchantAdminInfo(ctx context.Context, req *v1.MerchantAd
if err != nil {
return nil, err
}
return &v1.MerchantAdminInfoRes{Name: info.Name}, nil
return &v1.MerchantAdminInfoRes{Username: info.Username, MerchantId: info.MerchantId, StoreId: info.StoreId}, nil
}

View File

@ -2,13 +2,23 @@ package user
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/user/v1"
)
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
return nil, gerror.NewCode(gcode.CodeNotImplemented)
fromCtx := g.RequestFromCtx(ctx)
operatorId := fromCtx.Get("operatorId").Int64()
operatorRole := fromCtx.Get("role").String()
out, err := service.User().List(ctx, &model.UserListIn{Page: req.Page, Size: req.Size, OperatorId: operatorId, OperatorRole: operatorRole})
if err != nil {
return nil, err
}
return &v1.ListRes{
List: out.List,
Total: out.Total,
}, nil
}

View File

@ -16,7 +16,6 @@ type AdminsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns AdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// AdminsColumns defines and stores column names for the table admins.
@ -50,12 +49,11 @@ var adminsColumns = AdminsColumns{
}
// NewAdminsDao creates and returns a new DAO object for table data access.
func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao {
func NewAdminsDao() *AdminsDao {
return &AdminsDao{
group: "default",
table: "admins",
columns: adminsColumns,
handlers: handlers,
}
}
@ -81,11 +79,7 @@ func (dao *AdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *AdminsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type FeedbacksDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns FeedbacksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// FeedbacksColumns defines and stores column names for the table feedbacks.
@ -52,12 +51,11 @@ var feedbacksColumns = FeedbacksColumns{
}
// NewFeedbacksDao creates and returns a new DAO object for table data access.
func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao {
func NewFeedbacksDao() *FeedbacksDao {
return &FeedbacksDao{
group: "default",
table: "feedbacks",
columns: feedbacksColumns,
handlers: handlers,
}
}
@ -83,11 +81,7 @@ func (dao *FeedbacksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *FeedbacksDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type GamesDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns GamesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// GamesColumns defines and stores column names for the table games.
@ -44,12 +43,11 @@ var gamesColumns = GamesColumns{
}
// NewGamesDao creates and returns a new DAO object for table data access.
func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao {
func NewGamesDao() *GamesDao {
return &GamesDao{
group: "default",
table: "games",
columns: gamesColumns,
handlers: handlers,
}
}
@ -75,11 +73,7 @@ func (dao *GamesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *GamesDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type MerchantAdminsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns MerchantAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// MerchantAdminsColumns defines and stores column names for the table merchant_admins.
@ -60,12 +59,11 @@ var merchantAdminsColumns = MerchantAdminsColumns{
}
// NewMerchantAdminsDao creates and returns a new DAO object for table data access.
func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao {
func NewMerchantAdminsDao() *MerchantAdminsDao {
return &MerchantAdminsDao{
group: "default",
table: "merchant_admins",
columns: merchantAdminsColumns,
handlers: handlers,
}
}
@ -91,11 +89,7 @@ func (dao *MerchantAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantAdminsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type MerchantsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns MerchantsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// MerchantsColumns defines and stores column names for the table merchants.
@ -72,12 +71,11 @@ var merchantsColumns = MerchantsColumns{
}
// NewMerchantsDao creates and returns a new DAO object for table data access.
func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao {
func NewMerchantsDao() *MerchantsDao {
return &MerchantsDao{
group: "default",
table: "merchants",
columns: merchantsColumns,
handlers: handlers,
}
}
@ -103,11 +101,7 @@ func (dao *MerchantsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type RewardTypesDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns RewardTypesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// RewardTypesColumns defines and stores column names for the table reward_types.
@ -44,12 +43,11 @@ var rewardTypesColumns = RewardTypesColumns{
}
// NewRewardTypesDao creates and returns a new DAO object for table data access.
func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao {
func NewRewardTypesDao() *RewardTypesDao {
return &RewardTypesDao{
group: "default",
table: "reward_types",
columns: rewardTypesColumns,
handlers: handlers,
}
}
@ -75,11 +73,7 @@ func (dao *RewardTypesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardTypesDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type RewardsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns RewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// RewardsColumns defines and stores column names for the table rewards.
@ -54,12 +53,11 @@ var rewardsColumns = RewardsColumns{
}
// NewRewardsDao creates and returns a new DAO object for table data access.
func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao {
func NewRewardsDao() *RewardsDao {
return &RewardsDao{
group: "default",
table: "rewards",
columns: rewardsColumns,
handlers: handlers,
}
}
@ -85,11 +83,7 @@ func (dao *RewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type RolesDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns RolesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// RolesColumns defines and stores column names for the table roles.
@ -46,12 +45,11 @@ var rolesColumns = RolesColumns{
}
// NewRolesDao creates and returns a new DAO object for table data access.
func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao {
func NewRolesDao() *RolesDao {
return &RolesDao{
group: "default",
table: "roles",
columns: rolesColumns,
handlers: handlers,
}
}
@ -77,11 +75,7 @@ func (dao *RolesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RolesDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type StoreAdminsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns StoreAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// StoreAdminsColumns defines and stores column names for the table store_admins.
@ -56,12 +55,11 @@ var storeAdminsColumns = StoreAdminsColumns{
}
// NewStoreAdminsDao creates and returns a new DAO object for table data access.
func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao {
func NewStoreAdminsDao() *StoreAdminsDao {
return &StoreAdminsDao{
group: "default",
table: "store_admins",
columns: storeAdminsColumns,
handlers: handlers,
}
}
@ -87,11 +85,7 @@ func (dao *StoreAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreAdminsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type StoreRewardsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns StoreRewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// StoreRewardsColumns defines and stores column names for the table store_rewards.
@ -34,12 +33,11 @@ var storeRewardsColumns = StoreRewardsColumns{
}
// NewStoreRewardsDao creates and returns a new DAO object for table data access.
func NewStoreRewardsDao(handlers ...gdb.ModelHandler) *StoreRewardsDao {
func NewStoreRewardsDao() *StoreRewardsDao {
return &StoreRewardsDao{
group: "default",
table: "store_rewards",
columns: storeRewardsColumns,
handlers: handlers,
}
}
@ -65,11 +63,7 @@ func (dao *StoreRewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreRewardsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type StoresDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns StoresColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// StoresColumns defines and stores column names for the table stores.
@ -50,12 +49,11 @@ var storesColumns = StoresColumns{
}
// NewStoresDao creates and returns a new DAO object for table data access.
func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao {
func NewStoresDao() *StoresDao {
return &StoresDao{
group: "default",
table: "stores",
columns: storesColumns,
handlers: handlers,
}
}
@ -81,11 +79,7 @@ func (dao *StoresDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoresDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type TasksDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns TasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// TasksColumns defines and stores column names for the table tasks.
@ -38,12 +37,11 @@ var tasksColumns = TasksColumns{
}
// NewTasksDao creates and returns a new DAO object for table data access.
func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao {
func NewTasksDao() *TasksDao {
return &TasksDao{
group: "default",
table: "tasks",
columns: tasksColumns,
handlers: handlers,
}
}
@ -69,11 +67,7 @@ func (dao *TasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *TasksDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type UserTasksDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns UserTasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// UserTasksColumns defines and stores column names for the table user_tasks.
@ -48,12 +47,11 @@ var userTasksColumns = UserTasksColumns{
}
// NewUserTasksDao creates and returns a new DAO object for table data access.
func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao {
func NewUserTasksDao() *UserTasksDao {
return &UserTasksDao{
group: "default",
table: "user_tasks",
columns: userTasksColumns,
handlers: handlers,
}
}
@ -79,11 +77,7 @@ func (dao *UserTasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UserTasksDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -16,7 +16,6 @@ type UsersDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns UsersColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// UsersColumns defines and stores column names for the table users.
@ -37,6 +36,7 @@ type UsersColumns struct {
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
RoleId string // 角色ID
LastLoginStoreId string // 上次登录门店ID
}
// usersColumns holds the columns for the table users.
@ -57,15 +57,15 @@ var usersColumns = UsersColumns{
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
RoleId: "role_id",
LastLoginStoreId: "last_login_store_id",
}
// NewUsersDao creates and returns a new DAO object for table data access.
func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao {
func NewUsersDao() *UsersDao {
return &UsersDao{
group: "default",
table: "users",
columns: usersColumns,
handlers: handlers,
}
}
@ -91,11 +91,7 @@ func (dao *UsersDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UsersDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -49,7 +49,7 @@ func (s *sMerchant) Audit(ctx context.Context, in *model.MerchantAuditIn) (out *
if merchant.IsEmpty() {
return nil, ecode.Params.Sub("商户不存在")
}
if merchant[dao.Merchants.Columns().AuditStatus].Int() != 0 {
if merchant[dao.Merchants.Columns().AuditStatus].Int() != 1 {
return nil, ecode.Params.Sub("商户已审核")
}
if err = dao.Merchants.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {

View File

@ -90,7 +90,11 @@ 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) {
one, err := dao.MerchantAdmins.Ctx(ctx).WherePri(in.MerchantAdminId).One()
one, err := dao.MerchantAdmins.Ctx(ctx).WherePri(in.MerchantAdminId).
LeftJoin(
dao.Stores.Table(),
fmt.Sprintf("%s.%s = %s.%s", dao.Stores.Table(), dao.Stores.Columns().MerchantId, dao.MerchantAdmins.Table(), dao.MerchantAdmins.Columns().MerchantId)).
Fields(fmt.Sprintf("%s.*, %s.%s %s", dao.MerchantAdmins.Table(), dao.Stores.Table(), dao.Stores.Columns().Id, "storeId")).One()
if err != nil {
return nil, ecode.Fail.Sub("查询商户管理员失败")
}
@ -102,7 +106,9 @@ func (s *sMerchantAdmin) Info(ctx context.Context, in *model.MerchantAdminInfoIn
return nil, ecode.Fail.Sub("查询商户管理员失败")
}
return &model.MerchantAdminInfoOut{
Name: admin.Username,
Username: admin.Username,
MerchantId: admin.MerchantId,
StoreId: one["storeId"].Int64(),
}, nil
}
func (s *sMerchantAdmin) Code(ctx context.Context, in *model.MerchantAdminCodeIn) (out *model.MerchantAdminCodeOut, err error) {
@ -167,7 +173,21 @@ func (s *sMerchantAdmin) Register(ctx context.Context, in *model.MerchantAdminRe
if err != nil {
return ecode.Fail.Sub("插入商户数据失败")
}
// 查询出商户角色 id 和门店角色 id
array, err := tx.Model(dao.Roles.Table()).WhereIn(dao.Roles.Columns().Code, []string{consts.MerchantRoleCode, consts.StoreRoleCode}).Fields(dao.Roles.Columns().Code, dao.Roles.Columns().Id).All()
if err != nil {
return ecode.Fail.Sub("查询角色数据失败")
}
var merchantRoleId, storeRoleId int64
for _, value := range array {
code := value[dao.Roles.Columns().Code].String()
id := value[dao.Roles.Columns().Id].Int64()
if code == consts.MerchantRoleCode {
merchantRoleId = id
} else if code == consts.StoreRoleCode {
storeRoleId = id
}
}
// 插入商户管理员数据
if _, err = tx.Model(dao.MerchantAdmins.Table()).Data(do.MerchantAdmins{
MerchantId: id,
@ -175,10 +195,41 @@ func (s *sMerchantAdmin) Register(ctx context.Context, in *model.MerchantAdminRe
Phone: in.Phone,
IsPrimary: true,
Username: in.Username,
RoleId: merchantRoleId,
Status: consts.MerchantAdministratorEnable,
}).Insert(); err != nil {
return ecode.Fail.Sub("插入商户管理员数据失败")
}
// 初始化一个网吧
storeCode, err := snowid.GetSnowClient().GenerateStoreCode()
if err != nil {
return ecode.Fail.Sub("生成网吧编号失败")
}
storeId, err := tx.Model(dao.Stores.Table()).Data(do.Stores{
MerchantId: id,
Name: fmt.Sprintf("%s的网吧", in.Username),
StoreCode: storeCode,
ContactPhone: in.Phone,
Status: consts.StoreEnable,
}).InsertAndGetId()
if err != nil {
return ecode.Fail.Sub("插入网吧数据失败")
}
// 初始化一个网吧管理员
if _, err = tx.Model(dao.StoreAdmins.Table()).Data(do.StoreAdmins{
StoreId: storeId,
Username: in.Username,
Phone: in.Phone,
Status: consts.StoreAdminEnable,
PasswordHash: hashPass,
IsPrimary: true,
RoleId: storeRoleId,
}).Insert(); err != nil {
return ecode.Fail.Sub("插入网吧管理员数据失败")
}
return
}); err != nil {
return nil, err

View File

@ -199,8 +199,22 @@ func (s *sUser) BindPhone(ctx context.Context, in *model.UserBindPhoneIn) (out *
}
func (s *sUser) List(ctx context.Context, in *model.UserListIn) (out *model.UserListOut, err error) {
// 用于系统管理员、商户、门店查看用户列表, 展示用户最近的相关信息
return
list := make([]model.User, 0)
var total int
orm := dao.Users.Ctx(ctx)
if in.Nickname != "" {
orm = orm.WhereLike(dao.Users.Columns().Nickname, "%"+in.Nickname+"%")
}
if err = orm.Page(in.Page, in.Size).LeftJoin(
dao.Stores.Table(),
fmt.Sprintf("%s.%s = %s.%s", dao.Users.Table(), dao.Users.Columns().LastLoginStoreId, dao.Stores.Table(), dao.Stores.Columns().Id),
).Fields(fmt.Sprintf("%s.*, %s.%s %s", dao.Users.Table(), dao.Stores.Table(), dao.Stores.Columns().Name, "last_login_store_name")).ScanAndCount(&list, &total, false); err != nil {
return nil, ecode.Fail.Sub("获取用户列表失败")
}
return &model.UserListOut{
List: list,
Total: total,
}, nil
}
func (s *sUser) BoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserBoundUrlOut, err error) {

View File

@ -28,4 +28,5 @@ type Users struct {
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间
RoleId interface{} // 角色ID
LastLoginStoreId interface{} // 上次登录门店ID
}

View File

@ -26,4 +26,5 @@ type Users struct {
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
LastLoginStoreId int64 `json:"lastLoginStoreId" orm:"last_login_store_id" description:"上次登录门店ID"` // 上次登录门店ID
}

View File

@ -19,7 +19,9 @@ type MerchantAdminInfoIn struct {
MerchantAdminId int64
}
type MerchantAdminInfoOut struct {
Name string
Username string
MerchantId int64
StoreId int64
}
type MerchantAdminCodeIn struct {
Phone string

View File

@ -10,7 +10,6 @@ import (
type User struct {
Id int64 `json:"id" orm:"id,primary"` // 用户ID
Username string `json:"username" orm:"username,not null"` // 用户名
PasswordHash string `json:"passwordHash" orm:"password_hash,not null"` // 密码哈希
Nickname string `json:"nickname" orm:"nickname"` // 昵称
Avatar string `json:"avatar" orm:"avatar"` // 头像
Phone string `json:"phone" orm:"phone"` // 手机号
@ -20,9 +19,8 @@ type User struct {
Status int `json:"status" orm:"status,default:1"` // 状态1=正常2=禁用
LastLoginAt *gtime.Time `json:"lastLoginAt" orm:"last_login_at"` // 最后登录时间
LastLoginIp string `json:"lastLoginIp" orm:"last_login_ip"` // 最后登录IP
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at"` // 软删除时间戳
LastLoginStoreId int `json:"lastLoginStoreId" orm:"last_login_store_id"` // 最后登录门店ID
LastLoginStoreName string `json:"lastLoginStoreName" orm:"last_login_store_name"` // 最后登录门店名称
}
// UserCreateIn 创建用户请求
@ -97,7 +95,7 @@ type UserBindPhoneOut struct {
type UserListIn struct {
OperatorId int64
Role string
OperatorRole string
Nickname string
Page int
Size int

View File

@ -15,7 +15,7 @@ database:
level: "all"
stdout: true
default:
link: "mysql:root:MSms0427@tcp(192.168.3.132:3306)/arenax?loc=Local&charset=utf8mb4"
link: "mysql:root:MSms0427@tcp(localhost:3306)/arenax?loc=Local&charset=utf8mb4"
debug: true
# Redis configuration.
@ -33,3 +33,7 @@ wechat:
appSecret: "4269b5a2bb0274e805b43efb3fbd232a"
ticketExpire: 60
token: "arenax"
rsa:
publickey: "./manifest/config/public.pem"
privatekey: "./manifest/config/private.pem"

View File

@ -82,8 +82,7 @@ func init() {
}
// 商户
{
// 商户:查
// 门店:增删查
enforcer.AddPolicy("merchant", "/x/merchant/info", "GET", "获取商户信息")
}
// 管理员