- handle store.Status.
This commit is contained in:
@@ -217,7 +217,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
|
|||||||
if num, err = dao.UpdateEntityByKV(db, store, valid, nil); err == nil {
|
if num, err = dao.UpdateEntityByKV(db, store, valid, nil); err == nil {
|
||||||
globals.SugarLogger.Debug("2")
|
globals.SugarLogger.Debug("2")
|
||||||
dummy := &model.StoreMap{}
|
dummy := &model.StoreMap{}
|
||||||
_, err2 := dao.UpdateEntityByKV(db, dummy, utils.Params2Map("SyncStatus", 2), utils.Params2Map("StoreID", store.ID))
|
_, err2 := dao.UpdateEntityByKV(db, dummy, utils.Params2Map("SyncStatus", model.SyncFlagModifiedMask), utils.Params2Map("StoreID", store.ID))
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
if err = dao.GetEntity(db, store); err == nil {
|
if err = dao.GetEntity(db, store); err == nil {
|
||||||
err = SyncStore2Vendor(db, -1, store, false, userName)
|
err = SyncStore2Vendor(db, -1, store, false, userName)
|
||||||
@@ -239,12 +239,17 @@ func CreateStore(store *model.Store, userName string) (id int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SyncStore2Vendor(db *dao.DaoDB, vendorID int, store *model.Store, isForce bool, userName string) (err error) {
|
func SyncStore2Vendor(db *dao.DaoDB, vendorID int, store *model.Store, isForce bool, userName string) (err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = dao.GetDB()
|
||||||
|
}
|
||||||
storeMaps, err := GetStoreVendorMaps(db, store.ID, -1)
|
storeMaps, err := GetStoreVendorMaps(db, store.ID, -1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(store, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(store, false))
|
||||||
|
copiedStore := *store
|
||||||
for _, storeMap := range storeMaps {
|
for _, storeMap := range storeMaps {
|
||||||
if (vendorID == -1 || storeMap.VendorID == vendorID) && (isForce || storeMap.SyncStatus != 0) {
|
if (vendorID == -1 || storeMap.VendorID == vendorID) && (isForce || storeMap.SyncStatus != 0) {
|
||||||
if err = GetPurchaseHandler(storeMap.VendorID).UpdateStore(storeMap.VendorStoreID, store, userName); err == nil {
|
copiedStore.Status = mergeStoreStatus(store.Status, storeMap.Status)
|
||||||
|
if err = GetPurchaseHandler(storeMap.VendorID).UpdateStore(storeMap.VendorStoreID, &copiedStore, userName); err == nil {
|
||||||
storeMap.SyncStatus = 0
|
storeMap.SyncStatus = 0
|
||||||
dao.UpdateEntity(db, storeMap, "SyncStatus")
|
dao.UpdateEntity(db, storeMap, "SyncStatus")
|
||||||
}
|
}
|
||||||
@@ -267,6 +272,7 @@ func AddStoreVendorMap(db *dao.DaoDB, storeMap *model.StoreMap, userName string)
|
|||||||
store, err := GetPurchaseHandler(storeMap.VendorID).ReadStore(storeMap.VendorStoreID)
|
store, err := GetPurchaseHandler(storeMap.VendorID).ReadStore(storeMap.VendorStoreID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
storeMap.DeliveryType = store.DeliveryType
|
storeMap.DeliveryType = store.DeliveryType
|
||||||
|
storeMap.Status = store.Status
|
||||||
outStoreMap = storeMap
|
outStoreMap = storeMap
|
||||||
if err = dao.CreateEntity(db, storeMap); err == nil {
|
if err = dao.CreateEntity(db, storeMap); err == nil {
|
||||||
|
|
||||||
@@ -281,17 +287,39 @@ func DeleteStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, userName string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = dao.GetDB()
|
||||||
|
}
|
||||||
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
||||||
store, err2 := GetPurchaseHandler(vendorID).ReadStore(vendorStoreID)
|
jdStore, err2 := GetPurchaseHandler(vendorID).ReadStore(vendorStoreID)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
payload["deliveryType"] = store.DeliveryType
|
payload["deliveryType"] = jdStore.DeliveryType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dummy := &model.StoreMap{}
|
dummyStoreMap := &model.StoreMap{}
|
||||||
valid := jxutils.NormalMakeMapByStructObject(payload, dummy, userName)
|
valid := jxutils.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
|
||||||
|
if valid["status"] != nil {
|
||||||
|
valid["SyncStatus"] = model.SyncFlagModifiedMask
|
||||||
|
}
|
||||||
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||||
num, err = dao.UpdateEntityByKV(db, dummy, valid, utils.Params2Map("StoreID", storeID, "VendorID", vendorID))
|
if num, err = dao.UpdateEntityByKV(db, dummyStoreMap, valid, utils.Params2Map("StoreID", storeID, "VendorID", vendorID)); err == nil {
|
||||||
|
if valid["status"] != nil {
|
||||||
|
store := &model.Store{}
|
||||||
|
store.ID = storeID
|
||||||
|
if err = dao.GetEntity(db, store); err == nil {
|
||||||
|
err = SyncStore2Vendor(db, vendorID, store, true, userName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 合并得到最终的门店状态
|
||||||
|
func mergeStoreStatus(status int, vendorStatus int) int {
|
||||||
|
if status < vendorStatus {
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
return vendorStatus
|
||||||
|
}
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
|||||||
return FlatMap(m)
|
return FlatMap(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
||||||
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||||
excludedMap := make(map[string]int)
|
excludedMap := make(map[string]int)
|
||||||
for _, v := range excludedFields {
|
for _, v := range excludedFields {
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ type DaoDB struct {
|
|||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// beego orm的对于传代表字段的字串,数据库字段名(完全匹配,区分大小写),结构体字段名(不区分大小写)都可以
|
||||||
|
|
||||||
func GetDB() *DaoDB {
|
func GetDB() *DaoDB {
|
||||||
return &DaoDB{db: orm.NewOrm()}
|
return &DaoDB{db: orm.NewOrm()}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,3 +40,21 @@ func TestGetPlaceByName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(result)
|
t.Log(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateKV(t *testing.T) {
|
||||||
|
dummy := &model.Store{}
|
||||||
|
kvs := map[string]interface{}{
|
||||||
|
"status": 100,
|
||||||
|
"Tel1": "tel1",
|
||||||
|
"tEl2": "tel2",
|
||||||
|
"deliverY_Range_type": 15,
|
||||||
|
}
|
||||||
|
cond := map[string]interface{}{
|
||||||
|
"id": 100002,
|
||||||
|
}
|
||||||
|
num, err := UpdateEntityByKV(nil, dummy, kvs, cond)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(num)
|
||||||
|
}
|
||||||
|
|||||||
@@ -66,11 +66,12 @@ type StoreMap struct {
|
|||||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||||
Status int `json:"status"` // 取值同Store.Status
|
Status int `json:"status"` // 取值同Store.Status
|
||||||
|
|
||||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
|
||||||
|
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||||
|
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||||
|
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
|
||||||
|
|
||||||
AutoPickup int8 `json:"autoPickup"` // 是否自动拣货
|
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||||
DeliveryType int8 `json:"deliveryType"` // 配送类型
|
|
||||||
DeliveryCompetition int8 `json:"deliveryCompetition"` // 是否支持配送竞争
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*StoreMap) TableUnique() [][]string {
|
func (*StoreMap) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ func (c *StoreController) UpdateStoreVendorMap() {
|
|||||||
// @Title 新增门店映射信息
|
// @Title 新增门店映射信息
|
||||||
// @Description 新增门店映射信息
|
// @Description 新增门店映射信息
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param payload formData string true "json数据,storeMap对象"
|
// @Param payload formData string true "json数据,storeMap对象({'vendorID':0,'vendorStoreID':'11732425','autoPickup':1,'deliveryCompetition':1, 'pricePercentage':100})"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /AddStoreVendorMap [post]
|
// @router /AddStoreVendorMap [post]
|
||||||
|
|||||||
Reference in New Issue
Block a user