68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package dispatch
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (a *apiComp) WeekreciveCheck(session comm.IUserSession, req *pb.DispatchWeekReciveReq) (errdata *pb.ErrorData) {
|
|
if req.Idx == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (a *apiComp) Weekrecive(session comm.IUserSession, req *pb.DispatchWeekReciveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
if errdata = a.WeekreciveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
rsp := &pb.DispatchWeekReciveResp{}
|
|
|
|
d := a.module.modelDispatch.getDBDispatch(session.GetUserId())
|
|
if d == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DataNotFound,
|
|
Title: pb.ErrorCode_DataNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//派发奖励
|
|
wr := a.module.ModuleTools.GetGlobalConf().DispatchWeektaskreward
|
|
for i, v := range wr {
|
|
if req.Idx == int32(i+1) {
|
|
if d.Nb.WeekCount >= v.N {
|
|
//更新周任务状态
|
|
if err := a.module.modelDispatch.updateWeekstatus(session.GetUserId(), req.Idx, d.Nb); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
res = append(res, v.G...)
|
|
// a.module.DispenseRes(session, v.G, true)
|
|
rsp.Idx = req.Idx
|
|
break
|
|
}
|
|
|
|
}
|
|
}
|
|
if len(res) > 0 {
|
|
a.module.DispenseRes(session, res, true)
|
|
go a.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
a.module.WriteUserLog(session.GetUserId(), "DispatchWeekReciveReq", res)
|
|
})
|
|
}
|
|
session.SendMsg(string(a.module.GetType()), "weekrecive", rsp)
|
|
return
|
|
}
|