- move some funcs from jxtools to dao.
This commit is contained in:
@@ -19,6 +19,7 @@ var (
|
||||
|
||||
var (
|
||||
ErrHaveNotImplementedYet = errors.New("还没有实现")
|
||||
ErrEntityNotExist = errors.New("找不到相应实体")
|
||||
)
|
||||
|
||||
func GetPurchaseHandler(vendorID int) partner.IPurchasePlatformHandler {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -52,9 +51,8 @@ func GetCategories(parentID int) (cats []*model.SkuCategory, err error) {
|
||||
}
|
||||
|
||||
func AddCategory(cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
|
||||
cat.ID = 0
|
||||
dao.WrapAddIDCULDEntity(cat, userName)
|
||||
cat.JdSyncStatus = model.SyncFlagNewMask
|
||||
cat.DeletedAt = utils.DefaultTimeValue
|
||||
if err = dao.CreateEntity(nil, cat); err == nil {
|
||||
outCat = cat
|
||||
err = CurVendorSync.SyncCategory(cat.ID, false, userName)
|
||||
@@ -65,7 +63,7 @@ func AddCategory(cat *model.SkuCategory, userName string) (outCat *model.SkuCate
|
||||
func UpdateCategory(categoryID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = categoryID
|
||||
valid := jxutils.NormalMakeMapByStructObject(payload, cat, userName)
|
||||
valid := dao.NormalMakeMapByStructObject(payload, cat, userName)
|
||||
valid[model.FieldJdSyncStatus] = model.SyncFlagModifiedMask
|
||||
db := dao.GetDB()
|
||||
if num, err = dao.UpdateEntityByKV(db, cat, valid, nil); err == nil {
|
||||
@@ -96,6 +94,7 @@ func ReorderCategories(parentID int, categoryIDs []int, userName string) (err er
|
||||
break
|
||||
}
|
||||
}
|
||||
// todo 这里应该也需要先置标记
|
||||
if err == nil {
|
||||
err = GetPurchaseHandler(model.VendorIDJD).ReorderCategories(parentCat, userName)
|
||||
}
|
||||
@@ -262,8 +261,31 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
func AddSkuName(skuNameID int, payload map[string]interface{}) (num int64, err error) {
|
||||
return num, err
|
||||
func AddSkuName(skuNameExt *SkuNameExt, userName string) (outSkuNameExt *SkuNameExt, err error) {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
dao.WrapAddIDCULDEntity(&skuNameExt.SkuName, userName)
|
||||
if err = dao.CreateEntity(db, &skuNameExt.SkuName); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
for _, sku := range skuNameExt.Skus {
|
||||
dao.WrapAddIDCULDEntity(sku, userName)
|
||||
if err = dao.CreateEntity(db, sku); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
tmpInfo, err := GetSkuNames("", utils.Params2Map("id", skuNameExt.SkuName.ID), 0, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tmpInfo.TotalCount != 1 {
|
||||
return nil, ErrEntityNotExist
|
||||
}
|
||||
outSkuNameExt = tmpInfo.SkuNames[0]
|
||||
return outSkuNameExt, err
|
||||
}
|
||||
|
||||
func UpdateSkuName(skuNameID int, payload map[string]interface{}) (num int64, err error) {
|
||||
|
||||
@@ -4,10 +4,8 @@ import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -57,11 +55,7 @@ func UpdatePlaces(places []map[string]interface{}, userName string) (num int64,
|
||||
return 0, ErrMissingInput
|
||||
}
|
||||
placeid := &model.Place{}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(place, false))
|
||||
valid, _ := jxutils.FilterMapByFieldList(place, []string{"jdCode", "enabled", "mtpsPrice"})
|
||||
valid["updatedAt"] = time.Now()
|
||||
valid["lastOperator"] = userName
|
||||
globals.SugarLogger.Debug(valid)
|
||||
valid := dao.NormalMakeMapByFieldList(place, []string{"jdCode", "enabled", "mtpsPrice"}, userName)
|
||||
if num, err = dao.UpdateEntityByKV(nil, placeid, valid, utils.Params2Map("Code", place["code"])); err != nil {
|
||||
return num, err
|
||||
}
|
||||
@@ -74,6 +68,7 @@ func UpdatePlace(placeCode int, payload map[string]interface{}, userName string)
|
||||
return UpdatePlaces([]map[string]interface{}{payload}, userName)
|
||||
}
|
||||
|
||||
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
sql := `
|
||||
FROM store t1
|
||||
@@ -205,7 +200,7 @@ func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err e
|
||||
func UpdateStore(storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
store := &model.Store{}
|
||||
store.ID = storeID
|
||||
valid := jxutils.NormalMakeMapByStructObject(payload, store, userName)
|
||||
valid := dao.NormalMakeMapByStructObject(payload, store, userName)
|
||||
db := dao.GetDB()
|
||||
if num, err = dao.UpdateEntityByKV(db, store, valid, nil); err == nil {
|
||||
dummy := &model.StoreMap{}
|
||||
@@ -220,10 +215,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
|
||||
}
|
||||
|
||||
func CreateStore(store *model.Store, userName string) (id int, err error) {
|
||||
store.ID = 0
|
||||
store.LastOperator = userName
|
||||
store.CreatedAt = time.Now()
|
||||
store.UpdatedAt = store.CreatedAt
|
||||
dao.WrapAddIDCULEntity(store, userName)
|
||||
if err = dao.CreateEntity(nil, store); err == nil {
|
||||
return store.ID, nil
|
||||
}
|
||||
@@ -243,6 +235,7 @@ func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*
|
||||
func AddStoreVendorMap(db *dao.DaoDB, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
|
||||
store, err := GetPurchaseHandler(storeMap.VendorID).ReadStore(storeMap.VendorStoreID)
|
||||
if err == nil {
|
||||
dao.WrapAddIDCULEntity(storeMap, userName)
|
||||
storeMap.DeliveryType = store.DeliveryType
|
||||
storeMap.Status = store.Status
|
||||
storeMap.SyncStatus = model.SyncFlagModifiedMask
|
||||
@@ -271,8 +264,8 @@ func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[stri
|
||||
}
|
||||
if err == nil {
|
||||
dummyStoreMap := &model.StoreMap{}
|
||||
valid := jxutils.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
|
||||
if valid["status"] != nil {
|
||||
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
|
||||
if valid["status"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商
|
||||
valid[model.FieldSyncStatus] = model.SyncFlagModifiedMask
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||
|
||||
Reference in New Issue
Block a user