diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 5fba877fd..07c2331b1 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -1,7 +1,6 @@ package cms import ( - "encoding/json" "errors" "strconv" "strings" @@ -362,16 +361,21 @@ func UpdateSkuName(nameID int, payload map[string]interface{}, userName string) } }() if num, err = dao.UpdateEntityByKV(db, skuName, valid, nil); err == nil && num == 1 { - if payload["places"] != nil { - var places []int - if err = json.Unmarshal([]byte(payload["places"].(string)), &places); err == nil { + isGlobal, _ := payload["isGlobal"].(bool) + if !isGlobal && payload["places"] != nil { + if places, ok := payload["places"].([]interface{}); ok { if _, err = dao.ExecuteSQL(db, "DELETE FROM sku_name_place_bind WHERE name_id = ?", nameID); err == nil { for _, placeCode := range places { placeBind := model.SkuNamePlaceBind{} - dao.WrapAddIDCULEntity(placeBind, userName) - placeBind.NameID = nameID - placeBind.PlaceCode = placeCode - err = dao.CreateEntity(db, placeBind) + placeBind.PlaceCode = int(utils.Interface2Int64WithDefault(placeCode, 0)) + if placeBind.PlaceCode > 0 { + dao.WrapAddIDCULEntity(placeBind, userName) + placeBind.NameID = nameID + err = dao.CreateEntity(db, placeBind) + } else { + dao.Rollback(db) + return 0, errors.New("地点代码非法") + } } } }