Files
full/module/ec/mall/internal/logic/store/licensing.go
2026-09-22 21:15:34 +08:00

62 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package store
import (
"context"
"strings"
"time"
"bsm/full/module/ec/mall/internal/impl"
"bsm/full/module/ec/mall/internal/models"
pb "bsm/full/module/ec/mall/pb"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/service"
)
// 店铺许可授权
func Licensing(ctx context.Context, in *pb.LicensingRequest) (reply *pb.IdentityStatusReply, err error) {
// 要求调用者已登录,避免仅凭子域名匿名枚举店铺标识。
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
var identity string
licenseType := strings.ToUpper(in.GetLicenseType())
switch licenseType {
case "DOMAIN":
identity, err = LicensingDomain(in.Domain)
default:
return nil, errcode.ErrInvalidArgument
}
if identity == "" {
return nil, errcode.ErrNotFound(404, "store not found")
}
// 归属校验:调用者只能是该店铺的成员,避免店铺标识被枚举获取。
// 说明:完整许可码校验(in.License/in.LicenseType)需要许可数据源,当前仓库内不存在,暂无法实现。
owner, _ := auth.Owner.(map[string]any)
storeIdentity, _ := owner["store_identity"].(string)
if storeIdentity == "" || storeIdentity != identity {
return nil, errcode.ErrPermissionDenied
}
return &pb.IdentityStatusReply{
Code: 0,
Message: "OK",
Identity: identity,
Timeseq: time.Now().UnixMilli(),
}, nil
}
func LicensingDomain(domain string) (string, error) {
var store models.MallStore
err := impl.DBService.Model(&models.MallStore{}).Where("subdomain=?", domain).First(&store).Error
if err != nil {
return "", err
}
return store.Identity, nil
}