1
This commit is contained in:
parent
5b2b37d7ec
commit
15ba863a5c
@ -53,6 +53,129 @@ func (this *InGameApi) PreOrder(c *gin.Context) {
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *InGameApi) ServerPreOrder(c *gin.Context) {
|
||||
accountId := c.Query("account_id")
|
||||
goodsid := c.Query("goods_id")
|
||||
sessionid := c.Query("session_id")
|
||||
sign := c.Query("sign")
|
||||
if strings.ToLower(q5.Md5Str(accountId+goodsid+"f3a6a9a5-217a-4079-ab99-b5d69b8212be"+sessionid)) != strings.ToLower(sign) {
|
||||
f5.RspErr(c, 401, "sign err")
|
||||
return
|
||||
}
|
||||
|
||||
nowTime := int32(f5.GetApp().GetRealSeconds())
|
||||
order := new(model.InAppOrder)
|
||||
order.AccountId = accountId
|
||||
order.OrderId = q5.ToString(f5.GetApp().NewLockNodeUuid())
|
||||
order.ItemId = q5.SafeToInt32(goodsid)
|
||||
order.IP = c.Query("user_ip")
|
||||
|
||||
order.CreateTime = nowTime
|
||||
order.ModifyTime = nowTime
|
||||
|
||||
if err := order.Create(); err != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
}
|
||||
|
||||
rspObj := struct {
|
||||
ErrorCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
OrderId string `json:"order_id"`
|
||||
}{
|
||||
0,
|
||||
"",
|
||||
order.OrderId,
|
||||
}
|
||||
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *InGameApi) PayDone(c *gin.Context) {
|
||||
accountId := c.Query("account_id")
|
||||
orderid := c.Query("orderid")
|
||||
sessionid := c.Query("session_id")
|
||||
sign := c.Query("sign")
|
||||
if strings.ToLower(q5.Md5Str(accountId+orderid+"f3a6a9a5-217a-4079-ab99-b5d69b8212be"+sessionid)) != strings.ToLower(sign) {
|
||||
f5.RspErr(c, 401, "sign err")
|
||||
return
|
||||
}
|
||||
|
||||
orderModel := new(model.InAppOrder)
|
||||
if err, found := orderModel.Find(accountId, orderid); err != nil {
|
||||
f5.RspErr(c, 500, "server internal error")
|
||||
return
|
||||
} else if !found {
|
||||
f5.RspErr(c, 1, "order not found")
|
||||
return
|
||||
}
|
||||
|
||||
strs := strings.Split(accountId, "_")
|
||||
if len(strs) < 3 {
|
||||
f5.RspErr(c, 401, "params error1")
|
||||
return
|
||||
}
|
||||
|
||||
rediskey := "ls:accountid:" + 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
|
||||
}
|
||||
|
||||
status := orderModel.Status
|
||||
rspObj := struct {
|
||||
ErrorCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
OrderId string `json:"order_id"`
|
||||
Diamond int64 `json:"diamond"`
|
||||
}{
|
||||
OrderId: orderid,
|
||||
}
|
||||
for status < 2 {
|
||||
gameid := q5.SafeToInt64(strs[1])
|
||||
openid := strs[2]
|
||||
sessionkey := q5.SafeToString(data["session_key"])
|
||||
userip := this.getIP(c)
|
||||
balance, errcode, err := int64(0), int32(0), error(nil)
|
||||
if status == 0 {
|
||||
balance, errcode, err = service.Wxpay.QueryBalance(openid, gameid, userip, sessionkey)
|
||||
if err != nil {
|
||||
f5.RspErr(c, 500, "system busy")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
balance = int64(orderModel.SpAmount)
|
||||
}
|
||||
|
||||
if errcode == constant.WX_ERRCODE_OK && balance > 0 {
|
||||
errcode = service.Wxpay.QueryPay(openid, gameid, userip, sessionkey, int32(balance), orderModel.OrderId)
|
||||
if errcode == constant.WX_ERRCODE_OK {
|
||||
status = 1
|
||||
orderModel.Status = 3
|
||||
orderModel.UpdateFields([]string{"status"})
|
||||
}
|
||||
}
|
||||
|
||||
if errcode == constant.WX_ERRCODE_SESSIONERR || errcode == constant.WX_ERRCODE_SIGERR {
|
||||
rspObj.ErrorCode = 402
|
||||
rspObj.ErrMsg = "session overtime"
|
||||
}
|
||||
|
||||
rspObj.Diamond = balance
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
||||
func (this *InGameApi) OrderInfo(c *gin.Context) {
|
||||
reqJson := struct {
|
||||
AccountId string `json:"account_id" binding:"required"`
|
||||
@ -134,6 +257,8 @@ func (this *InGameApi) OrderInfo(c *gin.Context) {
|
||||
rspObj.ErrorCode = 402
|
||||
rspObj.ErrMsg = "session overtime"
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
rspObj.OrderId = orderModel.OrderId
|
||||
|
Loading…
x
Reference in New Issue
Block a user