| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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,
- }
- }
- // ProductDetail 产品详情。根据产品 ID 查询产品的完整信息,超管可见 appKey。
- 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
- }
|