修改上下文参数传递,实现门店登录
This commit is contained in:
@ -8,4 +8,5 @@ type MerchantAdminInfoReq struct {
|
||||
g.Meta `path:"/merchant/info" method:"get" tags:"MerchantAdmin" summary:"(商户管理员)获取商户管理员信息"`
|
||||
}
|
||||
type MerchantAdminInfoRes struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
@ -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"`
|
||||
}
|
||||
|
||||
7
internal/consts/storeAdmin.go
Normal file
7
internal/consts/storeAdmin.go
Normal file
@ -0,0 +1,7 @@
|
||||
package consts
|
||||
|
||||
// 门店管理员状态
|
||||
const (
|
||||
StoreAdminEnable = iota + 1
|
||||
StoreAdminDisable
|
||||
)
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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()
|
||||
|
||||
1
internal/logic/store/store.go
Normal file
1
internal/logic/store/store.go
Normal file
@ -0,0 +1 @@
|
||||
package store
|
||||
93
internal/logic/storeAdmin/storeAdmin.go
Normal file
93
internal/logic/storeAdmin/storeAdmin.go
Normal file
@ -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
|
||||
}
|
||||
@ -19,7 +19,7 @@ type MerchantAdminInfoIn struct {
|
||||
MerchantAdminId int64
|
||||
}
|
||||
type MerchantAdminInfoOut struct {
|
||||
*MerchantAdmin
|
||||
Name string
|
||||
}
|
||||
type MerchantAdminCodeIn struct {
|
||||
Phone string
|
||||
26
internal/model/store.go
Normal file
26
internal/model/store.go
Normal file
@ -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
|
||||
}
|
||||
18
internal/model/storeAdmin.go
Normal file
18
internal/model/storeAdmin.go
Normal file
@ -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
|
||||
}
|
||||
8
internal/service/store.go
Normal file
8
internal/service/store.go
Normal file
@ -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 ()
|
||||
33
internal/service/store_admin.go
Normal file
33
internal/service/store_admin.go
Normal file
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user