show sql error message

This commit is contained in:
RockYang
2024-08-05 16:14:44 +08:00
parent 3d720bdd81
commit cc551ba266
22 changed files with 115 additions and 130 deletions

View File

@@ -70,11 +70,10 @@ func (h *RewardHandler) Verify(c *gin.Context) {
exchange := vo.RewardExchange{}
power := math.Ceil(item.Amount / h.App.SysConfig.PowerPrice)
exchange.Power = int(power)
res = tx.Model(&user).UpdateColumn("power", gorm.Expr("power + ?", exchange.Power))
if res.Error != nil {
err = tx.Model(&user).UpdateColumn("power", gorm.Expr("power + ?", exchange.Power)).Error
if err != nil {
tx.Rollback()
logger.Error("添加应用失败:", res.Error)
resp.ERROR(c, "更新数据库失败!")
resp.ERROR(c, err.Error())
return
}
@@ -82,11 +81,10 @@ func (h *RewardHandler) Verify(c *gin.Context) {
item.Status = true
item.UserId = user.Id
item.Exchange = utils.JsonEncode(exchange)
res = tx.Updates(&item)
if res.Error != nil {
err = tx.Updates(&item).Error
if err != nil {
tx.Rollback()
logger.Error("添加应用失败:", res.Error)
resp.ERROR(c, "更新数据库失败!")
resp.ERROR(c, err.Error())
return
}