other order

This commit is contained in:
yangduo 2024-12-31 11:48:25 +08:00
parent 44ce15c20b
commit 2095b31004
3 changed files with 89 additions and 2 deletions

View File

@ -233,11 +233,13 @@ func (this *InGameApi) OrderInfo(c *gin.Context) {
OrderId string `json:"order_id"`
GoodsId int32 `json:"goods_id"`
Count int32 `json:"count"`
Others int32 `json:"others"`
Status int32 `json:"status"`
}{
OrderId: orderModel.OrderId,
GoodsId: orderModel.ItemId,
Count: orderModel.SpAmount,
Others: orderModel.SpOthers,
Status: orderModel.Status,
}
@ -260,11 +262,12 @@ func (this *InGameApi) OrderInfo(c *gin.Context) {
}
if balance >= count {
errcode = service.Wxpay.QueryPay(openid, gameid, userip, sessionkey, int32(count), orderModel.OrderId)
errcode = service.Wxpay.QueryPay(openid, gameid, userip, sessionkey, int32(balance), orderModel.OrderId)
if errcode == constant.WX_ERRCODE_OK {
orderModel.Status = 1
orderModel.SpAmount = int32(count)
orderModel.UpdateFields([]string{"status", "sp_amount"})
orderModel.SpOthers = int32(balance - count)
orderModel.UpdateFields([]string{"status", "sp_amount", "sp_others"})
}
}
}
@ -278,6 +281,87 @@ func (this *InGameApi) OrderInfo(c *gin.Context) {
}
}
func (this *InGameApi) OtherOrder(c *gin.Context) {
reqJson := struct {
AccountId string `json:"account_id" binding:"required"`
SessionId string `json:"session_id" binding:"required"`
}{}
if err := c.ShouldBindJSON(&reqJson); err != nil {
f5.RspErr(c, 401, "params error")
return
}
strs := strings.Split(reqJson.AccountId, "_")
if len(strs) < 3 {
f5.RspErr(c, 401, "params error1")
return
}
rediskey := "ls:accountid:" + reqJson.AccountId
str, err := service.Redis.Get(constant.LOGIN_REDIS, rediskey)
if err != nil {
f5.RspErr(c, 402, "invalid session")
return
}
data := map[string]interface{}{}
if json.Unmarshal([]byte(str), &data) != nil {
f5.RspErr(c, 402, "invalid session 1")
return
}
sessionkeytime := q5.SafeToInt64(data["update_time"])
if service.Wxpay.CheckExpireCache(reqJson.AccountId, sessionkeytime) {
f5.RspErr(c, 402, "session expired")
return
}
rspObj := struct {
ErrorCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
Count int64 `json:"count"`
}{}
gameid := q5.SafeToInt64(strs[1])
openid := q5.SafeToString(data["openid"])
sessionkey := q5.SafeToString(data["session_key"])
userip := this.getIP(c)
balance, errcode, err := service.Wxpay.QueryBalance(openid, gameid, userip, sessionkey)
if err != nil {
f5.RspErr(c, 500, "wx server busy")
return
}
if errcode == constant.WX_ERRCODE_OK && balance > 0 {
nowTime := int32(f5.GetApp().GetRealSeconds())
order := new(model.InAppOrder)
order.AccountId = reqJson.AccountId
order.OrderId = "o" + q5.ToString(f5.GetApp().NewLockNodeUuid())
errcode = service.Wxpay.QueryPay(openid, gameid, userip, sessionkey, int32(balance), order.OrderId)
if errcode == constant.WX_ERRCODE_OK {
order.GameId = int32(gameid)
order.Channel = q5.SafeToInt32(strs[0])
order.IP = this.getIP(c)
order.Status = 2
order.SpOthers = int32(balance)
order.CreateTime = nowTime
order.ModifyTime = nowTime
if err := order.Create(); err != nil {
f5.GetSysLog().Error("record other order error:%s, %s, %d", reqJson.AccountId, order.OrderId, balance)
}
rspObj.Count = balance
}
} else if errcode == constant.WX_ERRCODE_SESSIONERR || errcode == constant.WX_ERRCODE_SIGERR {
service.Wxpay.AddExpireInfo(reqJson.AccountId, sessionkeytime)
rspObj.ErrorCode = 402
rspObj.ErrMsg = "invalid session 2"
}
c.JSON(200, rspObj)
}
func (iga *InGameApi) getIP(c *gin.Context) (ip string) {
ip = c.Request.Header.Get("X-Real-Ip")
if ip == "" {

View File

@ -30,6 +30,7 @@ type InAppOrder struct {
SpOrderId string `gorm:"column:sp_orderid;comment:平台的订单id"`
SpAmount int32 `gorm:"column:sp_amount;comment:sp_amount"`
SpOthers int32 `gorm:"column:sp_others;comment:补单金额"`
SpConfirm int32 `gorm:"column:sp_confirmtime;comment:平台确认时间"`
SpResult int32 `gorm:"column:sp_pay_result;comment:0: 未确认 1: 支付成功 -1:支付失败"`
}

View File

@ -13,6 +13,8 @@ func (this *IngameRouter) InitRouter() {
api.InGameApi.PreOrder)
f5.GetApp().GetGinEngine().POST("/api/ingame/orderinfo",
api.InGameApi.OrderInfo)
f5.GetApp().GetGinEngine().POST("/api/ingame/otherorder",
api.InGameApi.OtherOrder)
f5.GetApp().GetGinEngine().GET("/api/ingame/spreorder",
api.InGameApi.ServerPreOrder)
f5.GetApp().GetGinEngine().GET("/api/ingame/paid",