fix: 修复bug

This commit is contained in:
quarkcms
2023-02-18 23:34:25 +08:00
parent fe2ab4be21
commit 83c887336f
2 changed files with 18 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ const (
AppName = "QuarkGo" AppName = "QuarkGo"
// Version of current package // Version of current package
Version = "1.1.19" Version = "1.1.20"
// 静态文件URL // 静态文件URL
RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/" RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/"

View File

@@ -86,14 +86,23 @@ func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
if value, ok := formValue.(float64); ok { if value, ok := formValue.(float64); ok {
reflectValue = reflect.ValueOf(int(value)) reflectValue = reflect.ValueOf(int(value))
} }
if reflectValue.IsZero() {
zeroValues[fieldName] = 0
}
case "float64": case "float64":
if value, ok := formValue.(float64); ok { if value, ok := formValue.(float64); ok {
reflectValue = reflect.ValueOf(float64(value)) reflectValue = reflect.ValueOf(float64(value))
} }
if reflectValue.IsZero() {
zeroValues[fieldName] = 0
}
case "float32": case "float32":
if value, ok := formValue.(float64); ok { if value, ok := formValue.(float64); ok {
reflectValue = reflect.ValueOf(float32(value)) reflectValue = reflect.ValueOf(float32(value))
} }
if reflectValue.IsZero() {
zeroValues[fieldName] = 0
}
case "time.Time": case "time.Time":
getTime, _ := time.ParseInLocation("2006-01-02 15:04:05", formValue.(string), time.Local) getTime, _ := time.ParseInLocation("2006-01-02 15:04:05", formValue.(string), time.Local)
reflectValue = reflect.ValueOf(getTime) reflectValue = reflect.ValueOf(getTime)
@@ -102,20 +111,21 @@ func (p *UpdateRequest) Handle(ctx *builder.Context) interface{} {
if reflect.ValueOf(formValue).Type().String() == "[]uint8" { if reflect.ValueOf(formValue).Type().String() == "[]uint8" {
reflectValue = reflect.ValueOf(string(formValue.([]uint8))) reflectValue = reflect.ValueOf(string(formValue.([]uint8)))
} }
if reflectValue.IsZero() {
zeroValues[fieldName] = nil
}
} }
if reflectValue.IsValid() {
if reflectFieldName.Type().String() != reflectValue.Type().String() { if reflectFieldName.Type().String() != reflectValue.Type().String() {
return ctx.JSON(200, msg.Error("结构体类型与传参类型不一致!", "")) return ctx.JSON(200, msg.Error("结构体类型与传参类型不一致!", ""))
} }
if reflectValue.IsZero() {
zeroValues[fieldName] = 0
}
reflectFieldName.Set(reflectValue) reflectFieldName.Set(reflectValue)
} }
} }
} }
}
// 获取对象 // 获取对象
getModel := db.Client.Model(&modelInstance).Where("id = ?", data["id"]).Updates(modelInstance) getModel := db.Client.Model(&modelInstance).Where("id = ?", data["id"]).Updates(modelInstance)