78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package pay
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
|
|
"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
|
|
need []*cfg.Gameatn
|
|
order *pb.DBPayOrder
|
|
err error
|
|
)
|
|
if errdata = this.DeliveryCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getGameRecharge(req.BillingPoints); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
order = &pb.DBPayOrder{
|
|
Orderid: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
Bpoints: req.BillingPoints,
|
|
Ctime: time.Now().Unix(),
|
|
State: pb.DBPayOrderState_PayOrder_Unpaid,
|
|
Ptype: req.Ptype,
|
|
Pid: req.Pid,
|
|
Price: conf.Amount,
|
|
Amount: 1,
|
|
}
|
|
need = []*cfg.Gameatn{{A: comm.ItemType, T: comm.Vouchers, N: conf.Amount / 100}}
|
|
|
|
if errdata = this.module.ConsumeRes(session, need, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.model.create(order); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
|
|
if err = this.module.Rpc_ModulePayDelivery(context.Background(), &pb.HttpPayDeliveryReq{
|
|
Uid: session.GetUserId(),
|
|
Orderid: order.Orderid,
|
|
Productid: order.Bpoints,
|
|
Price: order.Price,
|
|
Amount: order.Amount,
|
|
}, &pb.HttpPayDeliveryResp{}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "delivery", &pb.PayDeliveryResp{})
|
|
return
|
|
}
|