调整商户注册逻辑
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user