rechargelogic.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
  6. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
  7. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type RechargeLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewRechargeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeLogic {
  16. return &RechargeLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. // 资源充值
  23. func (l *RechargeLogic) Recharge(in *pb.RechargeReq) (*pb.Resp, error) {
  24. resp := &pb.Resp{}
  25. if in.Appid == "" {
  26. l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
  27. return resp, nil
  28. } else if in.FunctionCode == "" {
  29. l.Error(fmt.Sprintf("%+v", in), "无效的参数function_code")
  30. return resp, nil
  31. } else if in.Count <= 0 {
  32. l.Error(fmt.Sprintf("%+v", in), "无效的参数count")
  33. return resp, nil
  34. } else if in.UserId == 0 && in.EntId == 0 {
  35. l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
  36. return resp, nil
  37. }
  38. status, err := Deduction(in.Appid, in.FunctionCode, in.UserId, in.EntId, in.Count, in.Ids)
  39. if err != nil {
  40. l.Error(fmt.Sprintf("%+v", in), err)
  41. }
  42. resp.Status = status
  43. return resp, nil
  44. }