create_order

This commit is contained in:
lwl0608 2024-05-14 09:52:23 +08:00
parent 5ffd2d6085
commit 77bb52fe88
2 changed files with 42 additions and 0 deletions

View File

@ -270,6 +270,32 @@ func (m *Mysql) GetOrders(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64, offs
return
}
// 获取订单数
func (m *Mysql) GetOrderCnt(ctx *gin.Context, tx *sqlx.Tx, mid, st, et int64, orderStatus int32) (int, error) {
type S struct {
Cnt int `json:"cnt"`
}
var (
err error
s = S{}
)
sqlStr := fmt.Sprintf("select count(1) as cnt from %s where mid=? and order_status=? and ct>=? and ct<?", TableOrder)
args := []any{mid, orderStatus, st, et}
if tx != nil {
err = tx.GetContext(ctx, &s, sqlStr, args...)
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &s, sqlStr, args...)
}
if err == sql.ErrNoRows {
return 0, nil
}
if err != nil {
return 0, err
}
return s.Cnt, nil
}
// 更新订单状态
func (m *Mysql) UpdateOrderStatus(ctx *gin.Context, tx *sqlx.Tx, orderId string, preStatus, aftStatus int32) error {
var err error

View File

@ -107,6 +107,22 @@ func (v *Vas) GetMembershipProductList(ctx *gin.Context, req *vasproto.GetMember
}
func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data *vasproto.CreateOrderData, err error) {
// 检查退订单次数
var (
et = time.Now().Unix()
st = et - 86400*30
)
cnt, err := v.store.GetOrderCnt(ctx, nil, req.Mid, st, et, dbstruct.VasOrderStatusRefund)
if err != nil {
logger.Error("GetOrderCnt fail, mid: %v, err: %v", req.Mid, err)
return
}
logger.Info("GetOrderCnt Refund, mid: %v, cnt: %v", req.Mid, cnt)
if cnt >= 8 {
err = fmt.Errorf("账号已受限,解限请联系客服")
return
}
var (
productId = req.ProductId
order *dbstruct.Order