72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package pay
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) DeliveryCheck(session comm.IUserSession, req *pb.PayDeliveryReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /模拟充值
|
|
func (this *apiComp) Delivery(session comm.IUserSession, req *pb.PayDeliveryReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameRechargeData
|
|
voucher *cfg.Gameatn
|
|
amount uint32
|
|
neet uint32
|
|
err error
|
|
)
|
|
if errdata = this.DeliveryCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
req.Orderid = primitive.NewObjectID().Hex()
|
|
req.Uid = session.GetUserId()
|
|
|
|
if conf, err = this.module.configure.getGameRecharge(req.Productid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
voucher = this.module.ModuleTools.GetGlobalConf().Voucher
|
|
amount = this.module.ModuleItems.QueryItemAmount(session.GetUserId(), voucher.T)
|
|
neet = uint32(math.Floor(float64(conf.Amount) / 100))
|
|
if amount < neet {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ResNoEnough,
|
|
Title: pb.ErrorCode_ResNoEnough.ToString(),
|
|
Message: fmt.Sprintf("需要代金卷:%d 只有:%d", neet, amount),
|
|
}
|
|
return
|
|
}
|
|
needatn := []*cfg.Gameatn{{
|
|
A: voucher.A,
|
|
T: voucher.T,
|
|
N: int32(neet),
|
|
}}
|
|
|
|
if errdata = this.module.ConsumeRes(session, needatn, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.Rpc_ModulePayDelivery(context.Background(), req, &pb.PayDeliveryResp{}); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "delivery", &pb.PayDeliveryResp{})
|
|
return
|
|
}
|