go_dreamfactory/modules/dispatch/api_notice.go
2024-02-26 11:37:51 +08:00

97 lines
2.5 KiB
Go

package dispatch
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
)
// 公告板信息
func (a *apiComp) NoticeCheck(session comm.IUserSession, req *pb.DispatchNoticeReq) (errdata *pb.ErrorData) {
return
}
func (a *apiComp) Notice(session comm.IUserSession, req *pb.DispatchNoticeReq) (errdata *pb.ErrorData) {
var (
info *pb.DBDispatch
err error
)
if info, err = a.module.modelDispatch.getDBDispatch(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
uid := session.GetUserId()
rsp := &pb.DispatchNoticeResp{}
if len(info.Nb.Tasks) == 0 {
tasks, err := a.module.modelDispatch.taskRandom(uid, info)
if err != nil {
return
}
if len(tasks) == 0 {
return
}
freeCount := a.module.ModuleTools.GetGlobalConf().DispatchFreecheck
nb := &pb.Noticeboard{
Lv: 1, //公告初始等级
FreeCount: freeCount,
Tasks: tasks,
UpdateTime: configure.Now().Unix(),
}
update := map[string]interface{}{
"nb": nb,
}
if err := a.module.modelDispatch.Change(uid, update); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
info.Nb = nb
} else {
//恢复门票
one := utils.DiffDays(info.Nb.UpdateTime, configure.Now().Unix())
if one >= 1 {
itemId := a.module.ModuleTools.GetGlobalConf().DispatchNumtools.T
left := a.module.ModuleItems.QueryItemAmount(uid, itemId)
limit := a.module.ModuleTools.GetGlobalConf().DispatchNumoftimes
if int32(left) < limit {
add := limit - int32(left)
atn := &cfg.Gameatn{A: "item", T: itemId, N: add}
if e, atno := a.module.DispenseAtno(session, []*cfg.Gameatn{atn}, true); e != nil {
return e
} else {
go a.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
a.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "恢复门票", atno)
})
}
}
}
//周任务重置
n := utils.DiffDays(info.Nb.UpdateTime, configure.Now().Unix())
day := a.module.ModuleTools.GetGlobalConf().DispatchWeektaskcheck
if int32(n) >= day {
info.Nb.WeekCount = 0
info.Nb.WeekReceived = []int32{}
info.Nb.UpdateTime = configure.Now().Unix()
}
a.module.modelDispatch.updateNotice(session.GetUserId(), info)
}
rsp.Dispatch = info.Nb
session.SendMsg(string(a.module.GetType()), "notice", rsp)
return
}