checkpowerlogic.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
  6. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
  7. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
  8. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type CheckPowerLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewCheckPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckPowerLogic {
  17. return &CheckPowerLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 检查用户权益
  24. func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) {
  25. resp := &pb.Resp{}
  26. if in.Appid == "" {
  27. l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
  28. return resp, nil
  29. } else if in.FunctionCode == "" {
  30. l.Error(fmt.Sprintf("%+v", in), "无效的参数function_code")
  31. return resp, nil
  32. } else if in.AccountId == 0 && in.EntId == 0 && in.EntUserId == 0 {
  33. l.Error(fmt.Sprintf("%+v", in), "无效的参数account_id、ent_id、ent_user_id")
  34. return resp, nil
  35. }
  36. function := Base_function.FindByCode(in.Appid, in.FunctionCode)
  37. if function == nil {
  38. l.Error(fmt.Sprintf("%+v", in), "功能原始表中没有找到该功能")
  39. return resp, nil
  40. }
  41. status, use_count, surplus_count, start_time, end_time, err := Surplus(in.Appid, in.FunctionCode, in.AccountId, in.EntAccountId, in.EntId, in.EntUserId)
  42. resp.Status = status
  43. resp.UseCount = use_count
  44. resp.SurplusCount = surplus_count
  45. resp.StartTime = start_time
  46. resp.EndTime = end_time
  47. if err != nil {
  48. l.Error(fmt.Sprintf("%+v", in), err.Error())
  49. }
  50. return resp, nil
  51. }