package logic import ( "context" "fmt" . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity" "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc" "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb" "github.com/zeromicro/go-zero/core/logx" ) type PowerHandleLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewPowerHandleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PowerHandleLogic { return &PowerHandleLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // 开通或者取消权益 func (l *PowerHandleLogic) PowerHandle(in *pb.PowerReq) (*pb.Resp, error) { resp := &pb.Resp{} if in.Appid == "" { l.Error(fmt.Sprintf("%+v", in), "无效的参数appid") return resp, nil } else if in.GoodsCode == "" { l.Error(fmt.Sprintf("%+v", in), "无效的参数goods_code") return resp, nil } else if in.UserId == 0 && in.EntId == 0 { l.Error(fmt.Sprintf("%+v", in), "无效的参数user_id、ent_id") return resp, nil } if in.Type == 1 { //开通 if in.StartTime == "" { l.Error(fmt.Sprintf("%+v", in), "无效的参数start_time") return resp, nil } else if in.EndTime == "" { l.Error(fmt.Sprintf("%+v", in), "无效的参数end_time") return resp, nil } list := Base_goods_function.FindByGoodsCode(in.Appid, in.GoodsCode) if list != nil { if Base_power.OpenPower(in.Appid, in.GoodsCode, in.UserId, in.EntId, in.StartTime, in.EndTime, in.UseCount, list) { return &pb.Resp{Status: 1}, nil } } } else if in.Type == -1 { //取消 if Base_power.CancelPower(in.Appid, in.GoodsCode, in.UserId, in.EntId) { return &pb.Resp{Status: 1}, nil } } else { l.Error(fmt.Sprintf("%+v", in), "无效的参数type") return resp, nil } return &pb.Resp{}, nil }