go_dreamfactory/modules/dispatch/api_notice.go
2023-06-06 11:08:14 +08:00

84 lines
2.2 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) {
d := a.module.modelDispatch.getDBDispatch(session.GetUserId())
if d == nil {
code = pb.ErrorCode_DataNotFound
return
}
uid := session.GetUserId()
rsp := &pb.DispatchNoticeResp{}
if len(d.Nb.Tasks) == 0 {
tasks, err := a.module.modelDispatch.taskRandom(uid, d)
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
}
d.Nb = nb
} else {
//恢复门票
one := utils.DiffDays(d.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}
a.module.DispenseRes(session, []*cfg.Gameatn{atn}, true)
}
}
//周任务重置
n := utils.DiffDays(d.Nb.UpdateTime, configure.Now().Unix())
day := a.module.ModuleTools.GetGlobalConf().DispatchWeektaskcheck
if int32(n) >= day {
d.Nb.WeekCount = 0
d.Nb.WeekReceived = []int32{}
d.Nb.UpdateTime = configure.Now().Unix()
}
a.module.modelDispatch.updateNotice(session.GetUserId(), d)
}
rsp.Dispatch = d.Nb
session.SendMsg(string(a.module.GetType()), "notice", rsp)
return
}