|
@@ -1,7 +1,6 @@
|
|
package service
|
|
package service
|
|
|
|
|
|
import (
|
|
import (
|
|
- "fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
"log"
|
|
"log"
|
|
@@ -22,18 +21,20 @@ func MoneyRecharge(appid string, money int, remark string) error {
|
|
//查用户当前余额
|
|
//查用户当前余额
|
|
userAccount := &model.UserAccount{}
|
|
userAccount := &model.UserAccount{}
|
|
db.GetSFISDB().First(userAccount, &model.UserAccount{AppID: appid})
|
|
db.GetSFISDB().First(userAccount, &model.UserAccount{AppID: appid})
|
|
|
|
+ // 更新时间
|
|
|
|
+ nowStr := time.Now().Local().Format("2006-01-02 15:04:05")
|
|
errs := db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
|
|
errs := db.GetSFISDB().Transaction(func(tx *gorm.DB) error {
|
|
moneyBefore := userAccount.Money
|
|
moneyBefore := userAccount.Money
|
|
moneyAfter := userAccount.Money + money
|
|
moneyAfter := userAccount.Money + money
|
|
//充值
|
|
//充值
|
|
- err := tx.Exec("update user_account set money = ? WHERE `app_id` = ?", moneyAfter, appid).Error
|
|
|
|
|
|
+ err := tx.Exec("update user_account set money = ?,update_at = ? WHERE `app_id` = ?", moneyAfter, nowStr,appid).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("appID:[%s],money:[%d] execute cost user_account error:[%v]", appid, moneyAfter, err)
|
|
log.Printf("appID:[%s],money:[%d] execute cost user_account error:[%v]", appid, moneyAfter, err)
|
|
tx.Rollback()
|
|
tx.Rollback()
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
//生充值记录
|
|
//生充值记录
|
|
- err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money,remark) values (?,?,?,?,?)", appid, moneyBefore, moneyAfter, money, remark).Error
|
|
|
|
|
|
+ err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money,remark,create_at) values (?,?,?,?,?,?)", appid, moneyBefore, moneyAfter, money, remark,nowStr).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("appID:[%s],trade_money:[%d] execute insert into user_money_record error:[%v]", appid, money, err)
|
|
log.Printf("appID:[%s],trade_money:[%d] execute insert into user_money_record error:[%v]", appid, money, err)
|
|
tx.Rollback()
|
|
tx.Rollback()
|
|
@@ -53,7 +54,6 @@ func ProductRecharge(appid string, productId, rechargeNum int, startTime string,
|
|
defer userLock.Unlock()
|
|
defer userLock.Unlock()
|
|
|
|
|
|
//查用户当前剩余量
|
|
//查用户当前剩余量
|
|
- fmt.Println(startTime, endTime)
|
|
|
|
userProduct := &model.UserProduct{}
|
|
userProduct := &model.UserProduct{}
|
|
db.GetSFISDB().First(userProduct, &model.UserProduct{AppID: appid, ProductID: productId})
|
|
db.GetSFISDB().First(userProduct, &model.UserProduct{AppID: appid, ProductID: productId})
|
|
product := &model.Product{}
|
|
product := &model.Product{}
|