92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package warorder
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.WarorderReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.WarorderReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
warorders *pb.DBWarorders
|
|
info *pb.Warorder
|
|
confs []*cfg.GamePassCheckData
|
|
awards []*cfg.Gameatn
|
|
ads []*pb.UserAssets = make([]*pb.UserAssets, 0)
|
|
days int32
|
|
err error
|
|
ok bool
|
|
)
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if warorders, err = this.module.modelWarorder.getUserWarorders(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if confs, err = this.module.configure.getorder(req.Rtype); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, ok = warorders.Items[req.Rtype]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_WarorderNoOpen,
|
|
Title: pb.ErrorCode_WarorderNoOpen.ToString(),
|
|
Message: fmt.Sprintf("Activity:%d no open", req.Rtype),
|
|
}
|
|
return
|
|
}
|
|
|
|
days = int32(utils.DiffDays(configure.Now().Unix(), info.Opentime)) + 1
|
|
awards = make([]*cfg.Gameatn, 0)
|
|
for _, v := range confs {
|
|
if v.Parameter <= days {
|
|
if info.Freeprogress < v.Parameter {
|
|
awards = append(awards, v.FreeReward)
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.FreeReward.A,
|
|
T: v.FreeReward.T,
|
|
N: v.FreeReward.N,
|
|
})
|
|
}
|
|
if info.Vip {
|
|
if info.Payprogress < v.Parameter {
|
|
awards = append(awards, v.PayReward)
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.PayReward.A,
|
|
T: v.PayReward.T,
|
|
N: v.PayReward.N,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
info.Freeprogress = days
|
|
if info.Vip {
|
|
info.Payprogress = days
|
|
}
|
|
if errdata = this.module.DispenseRes(session, awards, true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "receive", &pb.WarorderReceiveResp{Rtype: req.Rtype, Info: info, Award: ads})
|
|
return
|
|
}
|