49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package dispatch
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (a *apiComp) WeekreciveCheck(session comm.IUserSession, req *pb.DispatchWeekReciveReq) (code pb.ErrorCode) {
|
|
if req.Idx == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (a *apiComp) Weekrecive(session comm.IUserSession, req *pb.DispatchWeekReciveReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = a.WeekreciveCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
rsp := &pb.DispatchWeekReciveResp{}
|
|
|
|
d := a.module.modelDispatch.getDBDispatch(session.GetUserId())
|
|
if d == nil {
|
|
code = pb.ErrorCode_DataNotFound
|
|
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 {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
a.module.DispenseRes(session, v.G, true)
|
|
rsp.Idx = req.Idx
|
|
break
|
|
}
|
|
|
|
}
|
|
}
|
|
session.SendMsg(string(a.module.GetType()), "weekrecive", rsp)
|
|
return
|
|
}
|