package dailytask import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" "go_dreamfactory/utils" ) type Dailytask struct { modules.ModuleBase service core.IService wtask comm.IWtask api *apiComp configure *configureComp modelDailytask *ModelDailytask } func NewModule() core.IModule { return &Dailytask{} } func (this *Dailytask) GetType() core.M_Modules { return comm.ModuleDailytask } func (this *Dailytask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service return } func (this *Dailytask) Start() (err error) { err = this.ModuleBase.Start() var module core.IModule if module, err = this.service.GetModule(comm.ModuleWtask); err != nil { return } this.wtask = module.(comm.IWtask) event.RegisterGO(comm.EventUserLogin, this.EventUserLogin) return } func (this *Dailytask) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelDailytask = this.RegisterComp(new(ModelDailytask)).(*ModelDailytask) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } // 用户登录 func (this *Dailytask) EventUserLogin(session comm.IUserSession) { var ( dtask *pb.DBDailytask user *pb.DBUser errdata *pb.ErrorData group []int32 tasks map[int32][]int32 err error ) if db.IsCross() { //跨服不支持 return } if dtask, err = this.modelDailytask.getUserDTasks(session.GetUserId()); err != nil { this.Errorln(err) return } if !utils.IsToday(dtask.Rtime) { //不是同一天 重置 if user = this.ModuleUser.GetUser(session.GetUserId()); user == nil { this.Error("no found user", log.Field{Key: "uid", Value: session.GetUserId()}) return } if group, err = this.modelDailytask.resetUserDTasks(user.Lv); err != nil { this.Errorln(err) return } if tasks, errdata = this.wtask.ResetDailytaskTask(session.Clone(), group...); errdata != nil { this.Errorln(errdata) return } dtask.Groups = make([]*pb.DBDailytaskGroup, 0) for k, v := range tasks { dtask.Groups = append(dtask.Groups, &pb.DBDailytaskGroup{ Group: k, Tasks: v, }) } dtask.Rtime = configure.Now().Unix() if err = this.modelDailytask.Change(session.GetUserId(), map[string]interface{}{ "groups": dtask.Groups, "rtime": dtask.Rtime, }); err != nil { this.Errorln(err) return } } }