72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package pay
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) DailyBuyCheck(session comm.IUserSession, req *pb.PayDailyBuyReq) (errdata *pb.ErrorData) {
|
|
if req.Id == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) DailyBuy(session comm.IUserSession, req *pb.PayDailyBuyReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBPayDaily
|
|
conf *cfg.GamePayPackageData
|
|
items []*pb.UserAssets
|
|
err error
|
|
)
|
|
if errdata = this.DailyBuyCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getPayPackageData(req.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.modelDaily.queryUserDaily(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info.Items[conf.Id] != nil {
|
|
if conf.BuyNum >= 0 && info.Items[conf.Id].Buyunm >= conf.BuyNum {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PayBuyNumNotEnough,
|
|
Title: pb.ErrorCode_PayBuyNumNotEnough.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
if len(conf.Costitem) > 0 {
|
|
if errdata = this.module.ConsumeRes(session, conf.Costitem, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
if errdata, items = this.module.modelDaily.delivery(session, conf.Packagetype); errdata != nil {
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "dailybuy", &pb.PayDailyBuyResp{Isucc: true, Items: items})
|
|
return
|
|
}
|