- store courier map

This commit is contained in:
gazebo
2018-10-18 09:49:04 +08:00
parent e56eb69b09
commit 6dbadf0569
5 changed files with 186 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"strings"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
"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"
@@ -368,3 +369,73 @@ func TmpGetJxBadCommentsByStoreId(storeID, page, size, commentType int) (retVal
}
return retVal, err
}
func GetStoreCourierMaps(db *dao.DaoDB, storeID int, vendorID int) (storeCourierMaps []*model.StoreCourierMap, err error) {
cond := map[string]interface{}{
model.FieldStoreID: storeID,
}
if vendorID != -1 {
cond[model.FieldVendorID] = vendorID
}
return storeCourierMaps, dao.GetEntitiesByKV(db, &storeCourierMaps, cond, false)
}
func AddStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, userName string) (outStoreCourierMap *model.StoreCourierMap, err error) {
if handler := basesch.FixedBaseScheduler.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
dao.WrapAddIDCULDEntity(storeCourierMap, userName)
storeCourierMap.StoreID = storeID
storeCourierMap.VendorID = vendorID
if db == nil {
db = dao.GetDB()
}
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
if err = dao.CreateEntity(db, storeCourierMap); err == nil {
dao.Commit(db)
outStoreCourierMap = storeCourierMap
err = CurVendorSync.SyncStore(db, storeCourierMap.VendorID, storeID, true, userName)
}
if err != nil {
dao.Rollback(db)
}
} else {
err = ErrCanNotFindVendor
}
return outStoreCourierMap, err
}
func DeleteStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
if db == nil {
db = dao.GetDB()
}
storeCourierMap := &model.StoreCourierMap{}
if num, err = dao.DeleteEntityLogically(db, storeCourierMap, map[string]interface{}{
model.FieldStatus: model.StoreStatusDisabled,
}, userName, map[string]interface{}{
model.FieldStoreID: storeID,
model.FieldVendorID: vendorID,
}); err == nil && num > 0 {
err = CurVendorSync.SyncStore(db, vendorID, storeID, true, userName)
}
return num, err
}
func UpdateStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
if db == nil {
db = dao.GetDB()
}
dummyStoreCourierMap := &model.StoreCourierMap{}
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreCourierMap, userName)
if len(valid) > 0 {
num, err = dao.UpdateEntityLogically(db, dummyStoreCourierMap, valid, userName, map[string]interface{}{
model.FieldStoreID: storeID,
model.FieldVendorID: vendorID,
})
}
return num, err
}