fix version 1
This commit is contained in:
@@ -9,10 +9,17 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 审核
|
||||
func Approve(ctx context.Context, in *pb.ApproveRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// 解析授权信息,审核仅限有权限的角色
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var data *models.MarketAgency
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
|
||||
@@ -11,16 +11,18 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增代理商
|
||||
func Create(ctx context.Context, in *pb.MarketAgenctyItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// 解析授权信息,开号仅限有权限的角色
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetName() == "" || in.GetAccount() == "" || in.GetPassword() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
@@ -10,15 +10,16 @@ import (
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 删除一个代理商
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// 解析授权信息,删号仅限有权限的角色
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
|
||||
@@ -15,21 +15,25 @@ import (
|
||||
// 代理商列表
|
||||
func Fetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.AgencyReply, err error) {
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
cnt int64 = 0
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
)
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 先归一化分页参数,再计算偏移量
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
if in.GetPageSize() > 200 {
|
||||
in.PageSize = 200
|
||||
}
|
||||
Offset := (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
tx := impl.DBService.Model(&models.MarketAgency{})
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
@@ -47,6 +51,6 @@ func Fetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.AgencyRepl
|
||||
|
||||
return &pb.AgencyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
Count: cnt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -22,8 +23,9 @@ func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.MarketAgenctyItem,
|
||||
return nil, err
|
||||
}
|
||||
identity = auth.Identity
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
// 请求中的 identity 只能用于与 token 身份比对,不一致直接拒绝
|
||||
if in.GetIdentity() != "" && in.GetIdentity() != auth.Identity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
mktModel := models.MarketAgency{}
|
||||
if err := impl.DBService.Where("identity=?", identity).First(&mktModel).Error; err != nil {
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
"bsm/full/module/ec/market/internal/password"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/token"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -50,7 +51,8 @@ func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err
|
||||
Market_Identity: marketData.Identity,
|
||||
}
|
||||
|
||||
token, err := encipher.GenerateTokenAes(marketData.ID, marketData.Identity, "", "", market, map[string]string{})
|
||||
// 与接口侧 ParseMetaCtx 的 JWT 校验保持一致,使用 SDK 的签发函数
|
||||
tokenStr, err := token.New(env.Runtime.JwtSecretKey).GenerateJwt(marketData.ID, marketData.Identity, "", "", market, map[string]string{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -63,7 +65,7 @@ func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err
|
||||
}
|
||||
|
||||
return &pb.LoginReply{
|
||||
Token: token,
|
||||
Token: tokenStr,
|
||||
Identity: marketData.Identity,
|
||||
Name: marketData.Name,
|
||||
Account: marketData.Account,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"bsm/full/module/ec/market/internal/models"
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -22,8 +23,9 @@ func Modify(ctx context.Context, in *pb.MarketAgenctyItem) (reply *pb.IdentitySt
|
||||
return nil, err
|
||||
}
|
||||
identity = auth.Identity
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
// 请求中的 identity 只能用于与 token 身份比对,不一致直接拒绝
|
||||
if in.GetIdentity() != "" && in.GetIdentity() != auth.Identity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
mktModel := &models.MarketAgency{
|
||||
Name: in.GetName(),
|
||||
|
||||
@@ -20,17 +20,21 @@ func Pending(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.AgencyRe
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
cnt int64 = 0
|
||||
data = make([]*models.MarketAgency, 0)
|
||||
)
|
||||
|
||||
// 先归一化分页参数,再计算偏移量
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 0 {
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
if in.GetPageSize() > 200 {
|
||||
in.PageSize = 200
|
||||
}
|
||||
Offset := (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
tx := impl.DBService.Model(&models.MarketAgency{}).Where("approve = 0").Order("created_at desc")
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
@@ -42,6 +46,6 @@ func Pending(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.AgencyRe
|
||||
|
||||
return &pb.AgencyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
Count: cnt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ func SetPassword(ctx context.Context, in *pb.SetPasswordRequest) (reply *pb.Iden
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identity := auth.Identity
|
||||
if in.GetIdentity() != "" {
|
||||
identity = in.GetIdentity()
|
||||
// 请求中的 identity 只能用于与 token 身份比对,不一致直接拒绝
|
||||
if in.GetIdentity() != "" && in.GetIdentity() != auth.Identity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
identity := auth.Identity
|
||||
if in.GetOldPassword() == "" || in.GetNewPassword() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ func MemberDetails(ctx context.Context, in *pb.IdentRequest) (reply *pb.KeyVal,
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 尚未实现,显式返回未实现错误,避免调用方误判为“成功但无数据”
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,6 @@ func MemberFetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.Data
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 尚未实现,显式返回未实现错误,避免调用方误判为“成功但无数据”
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ func OrderDetails(ctx context.Context, in *pb.IdentRequest) (reply *pb.KeyVal, e
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 尚未实现,显式返回未实现错误,避免调用方误判为“成功但无数据”
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,6 @@ func OrderFetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.DataR
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 尚未实现,显式返回未实现错误,避免调用方误判为“成功但无数据”
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -15,9 +16,6 @@ func Overview(ctx context.Context, in *pb.Empty) (reply *pb.OverviewReply, err e
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 尚未实现,显式返回未实现错误,避免调用方误判为“成功但无数据”
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -10,17 +10,18 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新增供应商
|
||||
func Create(ctx context.Context, in *pb.MarketSupplyItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, nil)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// 解析授权信息,开号仅限有权限的角色
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetName() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
@@ -15,21 +15,25 @@ import (
|
||||
// 供应商列表
|
||||
func Fetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.SupplyReply, err error) {
|
||||
var (
|
||||
cnt int64 = 0
|
||||
Offset int64 = (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
data = make([]*models.MarketSupply, 0)
|
||||
cnt int64 = 0
|
||||
data = make([]*models.MarketSupply, 0)
|
||||
)
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 先归一化分页参数,再计算偏移量
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
if in.GetPageSize() > 200 {
|
||||
in.PageSize = 200
|
||||
}
|
||||
Offset := (in.GetPageNo() - 1) * in.GetPageSize()
|
||||
tx := impl.DBService.Model(&models.MarketSupply{}).Where("status = ?", 1)
|
||||
if in.GetIdentity() != "" {
|
||||
tx.Where("identity = ?", in.GetIdentity())
|
||||
@@ -40,6 +44,6 @@ func Fetch(ctx context.Context, in *pb.MarketFetchRequest) (reply *pb.SupplyRepl
|
||||
}
|
||||
return &pb.SupplyReply{
|
||||
Data: ref(data),
|
||||
Count: int64(len(data)),
|
||||
Count: cnt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -5,11 +5,25 @@ import (
|
||||
pb "bsm/full/module/ec/market/pb"
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// recoverUnaryInterceptor 捕获处理过程中的 panic,转为 Internal 错误返回,避免进程崩溃。
|
||||
func recoverUnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
printer.Error("grpc panic recovered: %v", r)
|
||||
err = status.Error(codes.Internal, "internal server error")
|
||||
}
|
||||
}()
|
||||
return handler(ctx, req)
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Grpc *grpc.Server
|
||||
Ctx context.Context
|
||||
@@ -20,7 +34,7 @@ type Server struct {
|
||||
func New(grpcServ *grpc.Server) *Server {
|
||||
standalone := grpcServ == nil
|
||||
if standalone {
|
||||
grpcServ = grpc.NewServer()
|
||||
grpcServ = grpc.NewServer(grpc.UnaryInterceptor(recoverUnaryInterceptor))
|
||||
}
|
||||
|
||||
srv := &Server{
|
||||
|
||||
Reference in New Issue
Block a user