powerhandlelogic.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  35. if in.Type == 1 { //开通
  36. list := Base_goods_spec.FindById(in.GoodsSpecId, in.Appid, in.GoodsCode)
  37. if list != nil {
  38. if Base_power.OpenPower(in.GoodsSpecId, in.Appid, in.GoodsCode, in.UserId, in.EntId, in.BuyNum, list) {
  39. return &pb.Resp{Status: 1}, nil
  40. }
  41. } else {
  42. l.Error(fmt.Sprintf("%+v", in), "没有找到该商品规格")
  43. return resp, nil
  44. }
  45. } else if in.Type == -1 { //取消
  46. if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) {
  47. return &pb.Resp{Status: 1}, nil
  48. }
  49. } else {
  50. l.Error(fmt.Sprintf("%+v", in), "无效的参数type")
  51. return resp, nil
  52. }
  53. return resp, nil
  54. }