diff --git a/controller/end_user.go b/controller/end_user.go index 42ff28c..9445102 100644 --- a/controller/end_user.go +++ b/controller/end_user.go @@ -1,6 +1,7 @@ package controller import ( + "database/sql" "electricity_bill_calc/excel" "electricity_bill_calc/global" "electricity_bill_calc/response" @@ -202,13 +203,14 @@ func modifyEndUserRegisterRecord(c *gin.Context) { result.NotAccept("抄表数据合法性验证失败。") return } - tx := global.DBConn.NewSession() - if err = tx.Begin(); err != nil { + ctx, cancel := global.TimeoutContext() + defer cancel() + tx, err := global.DB.BeginTx(ctx, &sql.TxOptions{}) + if err != nil { result.Error(http.StatusInternalServerError, err.Error()) return } - defer tx.Close() - err = service.EndUserService.UpdateEndUserRegisterRecord(tx, *meter) + err = service.EndUserService.UpdateEndUserRegisterRecord(&tx, &ctx, *meter) if err != nil { tx.Rollback() result.Error(http.StatusInternalServerError, err.Error()) diff --git a/controller/user.go b/controller/user.go index def1121..9532ceb 100644 --- a/controller/user.go +++ b/controller/user.go @@ -324,6 +324,7 @@ func modifyAccountDetail(c *gin.Context) { return } newUserInfo := new(model.UserDetail) + newUserInfo.Id = targetUserId newUserInfo.Name = &modForm.Name newUserInfo.Region = modForm.Region newUserInfo.Address = modForm.Address @@ -334,13 +335,15 @@ func modifyAccountDetail(c *gin.Context) { result.BadRequest("用户月服务费无法解析。") return } - _, err = global.DBConn.ID(targetUserId).Update(newUserInfo) + _, err = global.DB.NewUpdate().Model(newUserInfo). + WherePK(). + Column("name", "region", "address", "contact", "phone", "unit_service_fee"). + Exec(c) if err != nil { result.Error(http.StatusInternalServerError, err.Error()) return } - cache.AbolishRelation("user") - cache.AbolishRelation(fmt.Sprintf("user_%s", targetUserId)) + cache.AbolishRelation(fmt.Sprintf("user:%s", targetUserId)) result.Updated("指定用户的信息已经更新。") }