surplusdetaillogic.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
  6. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
  7. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type SurplusDetailLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewSurplusDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SurplusDetailLogic {
  16. return &SurplusDetailLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. //资源剩余详情
  23. func (l *SurplusDetailLogic) SurplusDetail(req *types.SurplusReq) (resp *types.Reply, err error) {
  24. resp = &types.Reply{}
  25. if req.AppId == "" {
  26. resp.Error_msg = "无效的参数appid"
  27. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  28. return resp, nil
  29. } else if req.Function_code == "" {
  30. resp.Error_msg = "无效的参数function_code"
  31. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  32. return resp, nil
  33. } else if req.User_id == 0 && req.Ent_id == 0 && req.Ent_user_id == 0 {
  34. resp.Error_msg = "无效的参数user_id、ent_id、ent_user_id"
  35. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  36. return resp, nil
  37. }
  38. status, total, surplus, err := Surplus(req.AppId, req.Function_code, req.User_id, req.Ent_id, req.Ent_user_id)
  39. if err != nil {
  40. resp.Error_msg = err.Error()
  41. l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
  42. }
  43. resp.Error_code = status
  44. resp.Data = &types.SurplusData{
  45. Total: total,
  46. Surplus: surplus,
  47. }
  48. return
  49. }