예제 #1
0
/*保存订单,如果没有该订单会创建新的订单,并返回新的订单号*/
func SaveOrder(order model.Order) (orderId int) {
	result, err := db.Exec(INSERT_ORDER, order.CoOrderId, order.UserId, order.PlayerId, order.GameId, order.ServerId, order.Amount, order.PayType, order.ProductId, order.ProductCount, order.ExtData, order.SdkType, order.Source, order.OrderTime, order.PayTime, order.OrderStatus, order.PayStatus, order.SdkInfo)
	utils.Panic(err)
	if num, _ := result.RowsAffected(); num <= 0 {
		panic(fmt.Sprintf("Save order[%+v] to db error", order))
	}
	idF, err := result.LastInsertId()
	orderId = int(idF)
	utils.Panic(err)
	order.Id = orderId

	cache.SetD(getOrderKey(order.Id), order)
	return
}
예제 #2
0
func GetOrder(orderId int) (order model.Order, ok bool) {
	orderI, ok := cache.Get(getOrderKey(orderId))

	if !ok {

		rows, err := db.Query(SELECT_ORDER_BY_ID, orderId)
		if err != nil {
			panic(err.Error())
		}
		if rows.Next() {
			err = rows.Scan(&order.Id, &order.CoOrderId, &order.UserId, &order.PlayerId, &order.GameId, &order.ServerId, &order.Amount, &order.PayType, &order.ProductId, &order.ProductCount, &order.ExtData, &order.SdkType, &order.Source, &order.OrderTime, &order.PayTime, &order.OrderStatus, &order.PayStatus, &order.SdkInfo)
			if err != nil {
				panic(err.Error())
			}
		}
		defer rows.Close()
		cache.SetD(getOrderKey(order.Id), order)
		log.Debugf("Get order from db [%+v]", order)
	} else {
		order = orderI.(model.Order)
		log.Debugf("Get order from cache [%+v]", order)
	}
	return order, true
}