You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.1 KiB

package api
import (
"yunyan/comm"
"yunyan/lego/sys/log"
"yunyan/pb"
)
// 获取品牌商列表
func (this *apiComp) GetBrands(session comm.IUserSession, req *pb.ApiGetBrandsReq) (resp *pb.ApiGetBrandsResp, errdata *pb.ErrorData) {
var (
models []*pb.DBBrand
err error
)
if models, err = this.module.model.factorys(); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
this.module.Error("GetBrands Fail!", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "err", Value: err.Error()})
return
}
// 运营/代理:按账号的 品牌商 + 产品白名单过滤
scope := this.getSessionScope(session)
if !scope.Unlimited {
allProducts, _ := this.module.model.products()
allowed := visibleFactoryIDs(scope, allProducts)
allowSet := make(map[uint32]struct{}, len(allowed))
for _, id := range allowed {
allowSet[id] = struct{}{}
}
filtered := make([]*pb.DBBrand, 0, len(models))
for _, f := range models {
if _, ok := allowSet[f.Id]; ok {
filtered = append(filtered, f)
}
}
models = filtered
}
resp = &pb.ApiGetBrandsResp{
Brands: models,
}
return
}