80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package pay
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ActivityBuyCheck(session comm.IUserSession, req *pb.PayActivityBuyReq) (errdata *pb.ErrorData) {
|
|
if req.Id == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) ActivityBuy(session comm.IUserSession, req *pb.PayActivityBuyReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBActivityGiftbag
|
|
conf *cfg.GamePayGiftpackData
|
|
items []*pb.UserAssets
|
|
buynum, totalbuy int32
|
|
err error
|
|
)
|
|
if errdata = this.ActivityBuyCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getPayGiftpackeData(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.modelActivity.getUserActivitys(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info.Activitys[conf.Type] == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PayBuyNumNotEnough,
|
|
Title: pb.ErrorCode_PayBuyNumNotEnough.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
buynum = info.Activitys[conf.Type].Items[conf.Id].Buyunm
|
|
totalbuy = info.Activitys[conf.Type].Items[conf.Id].Totalbuynum
|
|
if conf.RepeatNum >= totalbuy || conf.BuyNum >= 0 && buynum >= 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.modelActivity.delivery(session, conf.Packagetype); errdata != nil {
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "activitybuy", &pb.PayDailyBuyResp{Isucc: true, Items: items})
|
|
return
|
|
}
|