powerhandlelogic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package logic
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  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 PowerHandleLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewPowerHandleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PowerHandleLogic {
  17. return &PowerHandleLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 开通或者取消权益
  24. func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
  25. resp := &pb.Resp{}
  26. var err error
  27. if in.Type == 1 { //开通
  28. if err = OpenPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.AccountId, in.EntAccountId, in.EntId, in.BuyNum, in.StartTime, in.EndTime); err == nil {
  29. resp = &pb.Resp{Status: 1}
  30. }
  31. } else if in.Type == -1 { //取消
  32. var ok bool
  33. ok, err = CancelPower(in.Appid, in.GoodsCode, in.GoodsSpecId, in.AccountId, in.EntAccountId)
  34. if ok {
  35. resp = &pb.Resp{Status: 1}
  36. }
  37. } else {
  38. err = errors.New("无效的参数type")
  39. }
  40. if err != nil {
  41. l.Error(fmt.Sprintf("%+v", in), err)
  42. }
  43. return resp, nil
  44. }