package product import ( "context" "perms-system-server/internal/middleware" "perms-system-server/internal/response" "perms-system-server/internal/svc" "perms-system-server/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type ProductDetailLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic { return &ProductDetailLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ProductDetailLogic) ProductDetail(req *types.ProductDetailReq) (resp *types.ProductItem, err error) { product, err := l.svcCtx.SysProductModel.FindOne(l.ctx, req.Id) if err != nil { return nil, response.ErrNotFound("产品不存在") } caller := middleware.GetUserDetails(l.ctx) item := &types.ProductItem{ Id: product.Id, Code: product.Code, Name: product.Name, Remark: product.Remark, Status: product.Status, CreateTime: product.CreateTime, } if caller != nil && caller.IsSuperAdmin { item.AppKey = product.AppKey } return item, nil }