73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package oldtimes
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.OldtimesReceiveReq) (errdata *pb.ErrorData) {
|
|
if req.ChapterId <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.OldtimesReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
|
|
rsp := &pb.OldtimesReceiveResp{}
|
|
ot := this.module.modelOldtimes.getDBOldtimes(uid)
|
|
if ot != nil {
|
|
for _, v := range ot.Chapters {
|
|
if v.Cid == req.ChapterId {
|
|
if v.Received == 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_OldtimesReceived,
|
|
Title: pb.ErrorCode_OldtimesReceived.ToString(),
|
|
}
|
|
return
|
|
} else if v.Status != int32(finish) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_OldtimesNoAllFinished,
|
|
Title: pb.ErrorCode_OldtimesNoAllFinished.ToString(),
|
|
}
|
|
return
|
|
} else {
|
|
v.Received = 1
|
|
this.module.modelOldtimes.updateOldtimes(uid, ot)
|
|
//发奖
|
|
gltl, err := this.module.configure.getTimelineCfg()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if conf, ok := gltl.GetDataMap()[req.ChapterId]; ok {
|
|
res = append(res, conf.Reward...)
|
|
//this.module.DispenseRes(session, conf.Reward, true)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
this.module.DispenseRes(session, res, true)
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), "OldtimesReceiveReq", res)
|
|
})
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "receive", rsp)
|
|
|
|
return
|
|
}
|