powerhandlelogic.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/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. resp := &pb.Resp{}
  25. if in.Appid == "" {
  26. l.Error(fmt.Sprintf("%+v", in), "无效的参数appid")
  27. return resp, nil
  28. } else if in.GoodsCode == "" {
  29. l.Error(fmt.Sprintf("%+v", in), "无效的参数goods_code")
  30. return resp, nil
  31. } else if in.UserId == 0 && in.EntId == 0 {
  32. l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id")
  33. return resp, nil
  34. } else if in.StartTime == "" {
  35. l.Error(fmt.Sprintf("%+v", in), "无效的参数start_time")
  36. return resp, nil
  37. } else if in.EndTime == "" {
  38. l.Error(fmt.Sprintf("%+v", in), "无效的参数end_time")
  39. return resp, nil
  40. } else if in.Type != 1 && in.Type != -1 {
  41. l.Error(fmt.Sprintf("%+v", in), "无效的参数type")
  42. return resp, nil
  43. }
  44. if in.Type == 1 { //开通
  45. list := Base_goods_function.FindByGoodsCode(in.Appid, in.GoodsCode)
  46. if list != nil {
  47. if Base_power.OpenPower(in.Appid, in.GoodsCode, in.UserId, in.EntId, in.StartTime, in.EndTime, in.UseCount, list) {
  48. return &pb.Resp{Status: 1}, nil
  49. }
  50. }
  51. } else if in.Type == -1 { //取消
  52. if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
  53. return &pb.Resp{Status: 1}, nil
  54. }
  55. }
  56. return &pb.Resp{}, nil
  57. }