- update places when only isGlobal is false.

This commit is contained in:
gazebo
2018-09-17 16:34:53 +08:00
parent 8e85a240e8
commit 531366631f

View File

@@ -1,7 +1,6 @@
package cms package cms
import ( import (
"encoding/json"
"errors" "errors"
"strconv" "strconv"
"strings" "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 num, err = dao.UpdateEntityByKV(db, skuName, valid, nil); err == nil && num == 1 {
if payload["places"] != nil { isGlobal, _ := payload["isGlobal"].(bool)
var places []int if !isGlobal && payload["places"] != nil {
if err = json.Unmarshal([]byte(payload["places"].(string)), &places); err == 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 { if _, err = dao.ExecuteSQL(db, "DELETE FROM sku_name_place_bind WHERE name_id = ?", nameID); err == nil {
for _, placeCode := range places { for _, placeCode := range places {
placeBind := model.SkuNamePlaceBind{} placeBind := model.SkuNamePlaceBind{}
dao.WrapAddIDCULEntity(placeBind, userName) placeBind.PlaceCode = int(utils.Interface2Int64WithDefault(placeCode, 0))
placeBind.NameID = nameID if placeBind.PlaceCode > 0 {
placeBind.PlaceCode = placeCode dao.WrapAddIDCULEntity(placeBind, userName)
err = dao.CreateEntity(db, placeBind) placeBind.NameID = nameID
err = dao.CreateEntity(db, placeBind)
} else {
dao.Rollback(db)
return 0, errors.New("地点代码非法")
}
} }
} }
} }