48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package base
|
|
|
|
import (
|
|
"backend/util"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type BaseModel interface {
|
|
Login(c *gin.Context)
|
|
VerifyToken(Uid string, Token string) error
|
|
}
|
|
|
|
type Param struct {
|
|
Uid int `form:"uid" json:"uid" binding:"required"`
|
|
AppId int `form:"appId" json:"appId" binding:"required"`
|
|
ServerId int `form:"serverId" json:"serverId" binding:"required"`
|
|
OrderId string `form:"orderId" json:"orderId" binding:"required"`
|
|
ChannelOrderId string
|
|
}
|
|
|
|
func (p *Param) ChangeOrderStatus(Platform string, prodprice string) error {
|
|
// 校验成功 修改订单状态为已支付
|
|
AppConf, err := util.GetAppConfig(p.AppId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
Db := util.MPool.GetMysqlDB(AppConf, 1)
|
|
defer Db.Close()
|
|
var chargeId int
|
|
var price float64
|
|
var paystatus int
|
|
err = Db.QueryRow("SELECT `ProductId`, `Price`, `PayStatus` FROM `t_player_charge` WHERE `OrderId`=?", p.OrderId).Scan(&chargeId, &price, &paystatus)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if fmt.Sprintf("%.2f", price) != prodprice {
|
|
return fmt.Errorf("订单金额不匹配,数据库金额:%.2f,回调金额:%s; 订单id:%s, chargeid:%d", price, prodprice, p.OrderId, chargeId)
|
|
}
|
|
if paystatus != 0 {
|
|
return fmt.Errorf("订单已支付,无法重复发货; 订单id:%s, chargeid:%d", p.OrderId, chargeId)
|
|
}
|
|
_, err = Db.Exec("UPDATE `t_player_charge` SET `PayStatus`=1, `PayTime`=?, `PayChannelOrderId` = ? , `PayPlatform` =? WHERE `OrderId`=? AND `PayStatus`=0", time.Now().Unix(), p.ChannelOrderId, Platform, p.OrderId)
|
|
return err
|
|
}
|