powerhandlelogic.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/entity"
  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 PowerHandleLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewPowerHandleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PowerHandleLogic {
  16. return &PowerHandleLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. //开通或者取消权益
  23. func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) {
  24. l.Info("开通或者取消权益请求参数", fmt.Sprintf("%+v", in))
  25. resp := &pb.Resp{}
  26. if in.Appid == "" {
  27. l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
  28. return resp, nil
  29. } else if in.GoodsCode == "" {
  30. l.Error(fmt.Sprintf("%+v", in), "无效的参数goods_code")
  31. return resp, nil
  32. } else if in.UserId == 0 && in.EntId == 0 {
  33. l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
  34. return resp, nil
  35. } else if in.StartTime == "" {
  36. l.Error(fmt.Sprintf("%+v", in), "无效的参数start_time")
  37. return resp, nil
  38. } else if in.EndTime == "" {
  39. l.Error(fmt.Sprintf("%+v", in), "无效的参数end_time")
  40. return resp, nil
  41. } else if in.Type != 1 && in.Type != -1 {
  42. l.Error(fmt.Sprintf("%+v", in), "无效的参数type")
  43. return resp, nil
  44. }
  45. if in.Type == 1 { //开通
  46. list := Base_goods_function.FindByGoodsCode(in.Appid, in.GoodsCode)
  47. if list != nil {
  48. if Base_power.OpenPower(in.Appid, in.GoodsCode, in.UserId, in.EntId, in.StartTime, in.EndTime, in.UseCount, list) {
  49. return &pb.Resp{Status: 1}, nil
  50. }
  51. }
  52. } else if in.Type == -1 { //取消
  53. if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
  54. return &pb.Resp{Status: 1}, nil
  55. }
  56. }
  57. return &pb.Resp{}, nil
  58. }