productDetailLogic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package product
  2. import (
  3. "context"
  4. "perms-system-server/internal/middleware"
  5. "perms-system-server/internal/response"
  6. "perms-system-server/internal/svc"
  7. "perms-system-server/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type ProductDetailLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic {
  16. return &ProductDetailLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. // ProductDetail 产品详情。根据产品 ID 查询产品的完整信息,超管可见 appKey。
  23. func (l *ProductDetailLogic) ProductDetail(req *types.ProductDetailReq) (resp *types.ProductItem, err error) {
  24. product, err := l.svcCtx.SysProductModel.FindOne(l.ctx, req.Id)
  25. if err != nil {
  26. return nil, response.ErrNotFound("产品不存在")
  27. }
  28. caller := middleware.GetUserDetails(l.ctx)
  29. item := &types.ProductItem{
  30. Id: product.Id,
  31. Code: product.Code,
  32. Name: product.Name,
  33. Remark: product.Remark,
  34. Status: product.Status,
  35. CreateTime: product.CreateTime,
  36. }
  37. if caller != nil && caller.IsSuperAdmin {
  38. item.AppKey = product.AppKey
  39. }
  40. return item, nil
  41. }