|
@@ -7,6 +7,7 @@ import (
|
|
|
"sfbase/utils"
|
|
|
"sfis/db"
|
|
|
"sfis/model"
|
|
|
+ "time"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
@@ -91,22 +92,23 @@ func after(productType int, dataLen int, userProduct *model.UserProduct, statusC
|
|
|
errs = db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
|
|
|
orderBefore := userProduct.LeftNum
|
|
|
orderAfter := userProduct.LeftNum - 1
|
|
|
+ nowStr := time.Now().Local().Format("2006-01-02 15:04:05")
|
|
|
//扣费
|
|
|
- err := tx.Exec("update user_product set left_num = IF(`left_num`<1, 0, `left_num`-1) WHERE `app_id` = ? and product_id=?", appID, productID).Error
|
|
|
+ err := tx.Exec("update user_product set left_num = IF(`left_num`<1, 0, `left_num`-1),update_at = ? WHERE `app_id` = ? and product_id=?", nowStr, appID, productID).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute cost left_num-1 error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
//生调用记录
|
|
|
- err = tx.Exec("insert into user_call_record (app_id,user_product_id,status,ip,param,order_code) values (?,?,?,?,?,?)", appID, userProductID, statusCode, ip, param, orderCode).Error
|
|
|
+ err = tx.Exec("insert into user_call_record (app_id,user_product_id,status,ip,param,order_code,create_at) values (?,?,?,?,?,?,?)", appID, userProductID, statusCode, ip, param, orderCode, nowStr).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute insert into user_call_record error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
//生订单
|
|
|
- err = tx.Exec("insert into interface_order (order_code,app_id,user_product_id,`before`,`after`,cost_model,trade_num) values (?,?,?,?,?,?,?)", orderCode, appID, userProductID, orderBefore, orderAfter, 0, 1).Error
|
|
|
+ err = tx.Exec("insert into interface_order (order_code,app_id,user_product_id,`before`,`after`,cost_model,trade_num,create_at) values (?,?,?,?,?,?,?,?)", orderCode, appID, userProductID, orderBefore, orderAfter, 0, 1, nowStr).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute insert into interface_order error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|
|
@@ -120,22 +122,23 @@ func after(productType int, dataLen int, userProduct *model.UserProduct, statusC
|
|
|
errs = db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
|
|
|
orderBefore := userProduct.LeftNum
|
|
|
orderAfter := userProduct.LeftNum - dataLen
|
|
|
+ nowStr := time.Now().Local().Format("2006-01-02 15:04:05")
|
|
|
//扣费
|
|
|
- err := tx.Exec("update user_product set left_num = IF(`left_num`<1, 0, `left_num`-?) WHERE `app_id` = ? and product_id=?", dataLen, appID, productID).Error
|
|
|
+ err := tx.Exec("update user_product set left_num = IF(`left_num`<1, 0, `left_num`-?),update_at = ? WHERE `app_id` = ? and product_id=?", nowStr, dataLen, appID, productID).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute cost money error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
//生调用记录
|
|
|
- err = tx.Exec("insert into user_call_record (app_id,user_product_id,status,ip,param,order_code) values (?,?,?,?,?,?)", appID, userProductID, statusCode, ip, param, orderCode).Error
|
|
|
+ err = tx.Exec("insert into user_call_record (app_id,user_product_id,status,ip,param,order_code,create_at) values (?,?,?,?,?,?,?)", appID, userProductID, statusCode, ip, param, orderCode, nowStr).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute insert into user_call_record error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
//生订单
|
|
|
- err = tx.Exec("insert into interface_order (order_code,app_id,user_product_id,`before`,`after`,cost_model,trade_num) values (?,?,?,?,?,?,?)", orderCode, appID, userProductID, orderBefore, orderAfter, 0, dataLen).Error
|
|
|
+ err = tx.Exec("insert into interface_order (order_code,app_id,user_product_id,`before`,`after`,cost_model,trade_num,create_at) values (?,?,?,?,?,?,?,?)", orderCode, appID, userProductID, orderBefore, orderAfter, 0, dataLen, nowStr).Error
|
|
|
if err != nil {
|
|
|
log.Printf("appID:[%s],productID:[%d] execute insert into interface_order error:[%v]", appID, productID, err)
|
|
|
tx.Rollback()
|