package logic import ( "context" "time" . "app.yhyue.com/moapp/jybase/date" . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/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 CheckPowerLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewCheckPowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckPowerLogic { return &CheckPowerLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *CheckPowerLogic) CheckPower(in *pb.CheckPowerReq) (*pb.Resp, error) { resp := &pb.Resp{} function := Base_function.FindByCode(in.Appid, in.FunctionCode) if function == nil { l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "功能原始表中没有找到该功能") return resp, nil } myPowers := Base_power.FindMyPower(in.Appid, in.FunctionCode, in.EntId, in.UserId) if myPowers == nil || len(*myPowers) == 0 { l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "功能权益表中没有找到权益记录") return resp, nil } isPass := false for _, v := range *myPowers { start, err := time.ParseInLocation(Date_Full_Layout, v.Start_time, time.Local) if err != nil { l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "开始时间转化错误", err) return resp, nil } end, err := time.ParseInLocation(Date_Full_Layout, v.End_time, time.Local) if err != nil { l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "结束时间转化错误", err) return resp, nil } if time.Now().After(start) && time.Now().Before(end) { isPass = true } } if !isPass { resp.Status = -1 l.Info(in.Appid, in.FunctionCode, in.EntId, in.UserId, "不在有效期内") return resp, nil } if function.Power_rule == 1 { resp.Status = 1 return resp, nil } else { if function.Power_rule == 3 { hasEmpower := false if (*myPowers)[0].Power_type == 2 { empower := Base_ent_empower.FindMyEntId(in.Appid, in.FunctionCode, in.EntId) if empower == nil || len(*empower) == 0 { resp.Status = -3 l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "没有授权记录") return resp, nil } if len(*empower) == 1 { if (*empower)[0].Ent_user_id == 0 { hasEmpower = true } } else { for _, v := range *empower { if v.Ent_user_id == in.UserId { hasEmpower = true break } } } } else { hasEmpower = true } if !hasEmpower { resp.Status = -3 l.Info(in.Appid, in.FunctionCode, in.EntId, in.UserId, "没有对该用户进行授权") return resp, nil } use, err := Base_resource_use.FindLastOneByEntId(in.Appid, in.FunctionCode, in.EntId) if err != nil { l.Error(in.Appid, in.FunctionCode, in.EntId, in.UserId, "查询资源使用记录失败") return resp, nil } else if use == nil { resp.Status = 1 return resp, nil } //limit_strategy := (*myPowers)[0].Limit_strategy } return resp, nil } return resp, nil }