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