Merge remote-tracking branch 'origin/mark' into yonghui
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -31,6 +32,13 @@ const (
|
|||||||
SendMsgTypeSuggestRequest = "suggestRequest"
|
SendMsgTypeSuggestRequest = "suggestRequest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SysConfigLimit struct {
|
||||||
|
ValueType reflect.Kind
|
||||||
|
MinValue int64
|
||||||
|
MaxValue int64
|
||||||
|
AfterChanged func() error
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
serviceInfo map[string]interface{}
|
serviceInfo map[string]interface{}
|
||||||
allowUpdatePlaceFieldsMap = map[string]bool{
|
allowUpdatePlaceFieldsMap = map[string]bool{
|
||||||
@@ -54,6 +62,36 @@ var (
|
|||||||
needConfirmRequestMap = map[string]int{
|
needConfirmRequestMap = map[string]int{
|
||||||
SendMsgTypeOpenStoreRequest: 1,
|
SendMsgTypeOpenStoreRequest: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SysConfigLimitMap = map[string]*SysConfigLimit{
|
||||||
|
model.ConfigSysEbaiBoxFee: &SysConfigLimit{
|
||||||
|
ValueType: reflect.Int,
|
||||||
|
MinValue: 0,
|
||||||
|
MaxValue: 500,
|
||||||
|
AfterChanged: func() (err error) {
|
||||||
|
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDEBAI}, nil, model.SyncFlagModifiedMask)
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model.ConfigSysMtwmBoxFee: &SysConfigLimit{
|
||||||
|
ValueType: reflect.Int,
|
||||||
|
MinValue: 0,
|
||||||
|
MaxValue: 500,
|
||||||
|
AfterChanged: func() (err error) {
|
||||||
|
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDMTWM}, nil, model.SyncFlagModifiedMask)
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model.ConfigSysMtwmSkuBoxFee: &SysConfigLimit{
|
||||||
|
ValueType: reflect.Int,
|
||||||
|
MinValue: 0,
|
||||||
|
MaxValue: 50,
|
||||||
|
AfterChanged: func() (err error) {
|
||||||
|
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), model.VendorIDMTWM, nil, nil, model.SyncFlagModifiedMask)
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||||
@@ -193,6 +231,27 @@ func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, ms
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkSysConfig(key, value string) (err error) {
|
||||||
|
if limit := SysConfigLimitMap[key]; limit != nil {
|
||||||
|
if limit.ValueType == reflect.Int {
|
||||||
|
int64Value, err2 := strconv.ParseInt(value, 10, 64)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
if int64Value < limit.MinValue || int64Value > limit.MaxValue {
|
||||||
|
err = fmt.Errorf("配置%s,值%s超范围[%d,%d]", key, value, limit.MinValue, limit.MaxValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func onSysConfigChanged(key, value string) (err error) {
|
||||||
|
if limit := SysConfigLimitMap[key]; limit != nil && limit.AfterChanged != nil {
|
||||||
|
err = limit.AfterChanged()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func checkConfig(opFlag int, configType, key, value string) (err error) {
|
func checkConfig(opFlag int, configType, key, value string) (err error) {
|
||||||
switch configType {
|
switch configType {
|
||||||
case model.ConfigTypePricePack:
|
case model.ConfigTypePricePack:
|
||||||
@@ -228,8 +287,10 @@ func checkConfig(opFlag int, configType, key, value string) (err error) {
|
|||||||
}
|
}
|
||||||
case model.ConfigTypeRole:
|
case model.ConfigTypeRole:
|
||||||
case model.ConfigTypeSys:
|
case model.ConfigTypeSys:
|
||||||
if opFlag&(model.SyncFlagNewMask|model.SyncFlagDeletedMask) != 0 {
|
if opFlag&( /*model.SyncFlagNewMask|*/ model.SyncFlagDeletedMask) != 0 {
|
||||||
err = fmt.Errorf("系统参数只支持修改,不支持自由添加")
|
err = fmt.Errorf("系统参数只支持修改或添加,不支持删除")
|
||||||
|
} else {
|
||||||
|
err = checkSysConfig(key, value)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("当前只支持配置:%s, 传入的配置类型:%s", utils.Format4Output(model.ConfigTypeName, true), configType)
|
err = fmt.Errorf("当前只支持配置:%s, 传入的配置类型:%s", utils.Format4Output(model.ConfigTypeName, true), configType)
|
||||||
@@ -249,7 +310,11 @@ func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error
|
|||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
|
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
|
||||||
return dao.CreateEntity(db, conf)
|
err = dao.CreateEntity(db, conf)
|
||||||
|
if configType == model.ConfigTypeSys && err == nil {
|
||||||
|
err = onSysConfigChanged(key, value)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||||
@@ -314,6 +379,9 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
|||||||
"Type": configType,
|
"Type": configType,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if configType == model.ConfigTypeSys && err == nil {
|
||||||
|
err = onSysConfigChanged(key, "")
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,6 +461,9 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
|||||||
default:
|
default:
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
}
|
}
|
||||||
|
if configType == model.ConfigTypeSys && err == nil {
|
||||||
|
err = onSysConfigChanged(key, value)
|
||||||
|
}
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,15 +185,10 @@ func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB
|
|||||||
// return "", err
|
// return "", err
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) {
|
||||||
globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID)
|
globals.SugarLogger.Debugf("SyncStore2, storeIDs:%d", storeIDs)
|
||||||
var vendorIDs []int
|
userName := ctx.GetUserName()
|
||||||
if vendorID != -1 {
|
_, hint, err = v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, false, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||||
vendorIDs = []int{
|
|
||||||
vendorID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("同步门店信息:%d", storeID), isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
|
||||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
handler := v.GetStoreHandler(loopMapInfo.VendorID)
|
handler := v.GetStoreHandler(loopMapInfo.VendorID)
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
@@ -232,6 +227,16 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID,
|
|||||||
return hint, makeSyncError(err)
|
return hint, makeSyncError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||||
|
var vendorIDs []int
|
||||||
|
if vendorID != -1 {
|
||||||
|
vendorIDs = []int{
|
||||||
|
vendorID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v.SyncStore2(ctx, db, vendorIDs, []int{storeID}, false, isAsync)
|
||||||
|
}
|
||||||
|
|
||||||
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
|
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
|
||||||
var (
|
var (
|
||||||
nameIDs []int
|
nameIDs []int
|
||||||
@@ -384,7 +389,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v
|
|||||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
globals.SugarLogger.Debug("SyncStoresSkus2")
|
globals.SugarLogger.Debug("SyncStoresSkus2")
|
||||||
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
||||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs,
|
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, false,
|
||||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||||
@@ -561,9 +566,9 @@ func (v *VendorSync) AmendAndPruneStoreStuff(ctx *jxcontext.Context, vendorIDs [
|
|||||||
return hint, makeSyncError(err)
|
return hint, makeSyncError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, mustDirty bool, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||||
var storeMapList []*model.StoreMap
|
var storeMapList []*model.StoreMap
|
||||||
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
|
if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "", mustDirty); err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
if len(storeMapList) == 0 {
|
if len(storeMapList) == 0 {
|
||||||
@@ -585,7 +590,6 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
|||||||
if len(loopInfoList) == 1 {
|
if len(loopInfoList) == 1 {
|
||||||
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
|
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
|
||||||
}
|
}
|
||||||
// globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false))
|
|
||||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||||
tasksch.HandleTask(task, nil, isManageIt).Run()
|
tasksch.HandleTask(task, nil, isManageIt).Run()
|
||||||
if !isAsync {
|
if !isAsync {
|
||||||
@@ -604,7 +608,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) {
|
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) {
|
||||||
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, handler, isContinueWhenError)
|
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, false, handler, isContinueWhenError)
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,10 +225,23 @@ func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack mo
|
|||||||
return inSku
|
return inSku
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSkuBoxFee(vendorID int) (boxFee int64) {
|
||||||
|
if vendorID == model.VendorIDMTWM {
|
||||||
|
boxFee, _ = dao.GetSysConfigAsInt64(dao.GetDB(), model.ConfigSysMtwmSkuBoxFee)
|
||||||
|
}
|
||||||
|
return boxFee
|
||||||
|
}
|
||||||
|
|
||||||
func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyncInfo {
|
func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyncInfo {
|
||||||
for _, skuItem := range inSkuList {
|
if len(inSkuList) > 0 {
|
||||||
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
|
boxFee := getSkuBoxFee(inSkuList[0].VendorID)
|
||||||
skuItem.SkuName = jxutils.ComposeSkuNameSync(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd)
|
for _, skuItem := range inSkuList {
|
||||||
|
if skuItem.VendorPrice > skuItem.BoxFee {
|
||||||
|
skuItem.BoxFee = boxFee
|
||||||
|
}
|
||||||
|
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
|
||||||
|
skuItem.SkuName = jxutils.ComposeSkuNameSync(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return inSkuList
|
return inSkuList
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ func doDailyWork() {
|
|||||||
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
||||||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||||||
|
|
||||||
|
cms.CurVendorSync.SyncStore2(jxcontext.AdminCtx, dao.GetDB(), nil, nil, true, true)
|
||||||
|
|
||||||
syncStoreSku()
|
syncStoreSku()
|
||||||
|
|
||||||
InitEx()
|
InitEx()
|
||||||
|
|||||||
@@ -49,3 +49,13 @@ func ValidateRoles(db *DaoDB, roles ...string) (err error) {
|
|||||||
}
|
}
|
||||||
return errList.GetErrListAsOne()
|
return errList.GetErrListAsOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSysConfigAsInt64(db *DaoDB, key string) (value int64, err error) {
|
||||||
|
configList, err := QueryConfigs(db, key, model.ConfigTypeSys, "")
|
||||||
|
if err == nil && len(configList) > 0 {
|
||||||
|
value = utils.Str2Int64WithDefault(configList[0].Value, 0)
|
||||||
|
} else if IsNoRowsError(err) {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 带购物平台信息的
|
// 带购物平台信息的
|
||||||
@@ -26,7 +27,6 @@ type StoreDetail struct {
|
|||||||
|
|
||||||
FreightDeductionPackStr string `orm:"size(4096)" json:"-"` //
|
FreightDeductionPackStr string `orm:"size(4096)" json:"-"` //
|
||||||
FreightDeductionPackObj *model.FreightDeductionPack `orm:"-" json:"-"`
|
FreightDeductionPackObj *model.FreightDeductionPack `orm:"-" json:"-"`
|
||||||
BoxFee int `orm:"default(1)" json:"boxFee"` // 打包费
|
|
||||||
|
|
||||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||||
@@ -85,7 +85,7 @@ func getStoreDetail(db *DaoDB, storeID, vendorID int, vendorStoreID string) (sto
|
|||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*,
|
SELECT t1.*,
|
||||||
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee, t2.sync_status, t2.vendor_org_code,
|
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee, t2.sync_status, t2.vendor_org_code,
|
||||||
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name, t2.box_fee,
|
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync, t2.vendor_store_name,
|
||||||
t3.value price_percentage_pack_str,
|
t3.value price_percentage_pack_str,
|
||||||
t4.value freight_deduction_pack_str,
|
t4.value freight_deduction_pack_str,
|
||||||
district.name district_name,
|
district.name district_name,
|
||||||
@@ -211,7 +211,7 @@ func GetStoreCourierList(db *DaoDB, storeIDs []int, status, auditStatus int) (co
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string) (storeMapList []*model.StoreMap, err error) {
|
func GetStoresMapList2(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string, mustDirty bool) (storeMapList []*model.StoreMap, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*
|
SELECT t1.*
|
||||||
FROM store_map t1
|
FROM store_map t1
|
||||||
@@ -242,6 +242,10 @@ func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int,
|
|||||||
sql += " AND t1.price_percentage_pack = ?"
|
sql += " AND t1.price_percentage_pack = ?"
|
||||||
sqlParams = append(sqlParams, pricePack)
|
sqlParams = append(sqlParams, pricePack)
|
||||||
}
|
}
|
||||||
|
if mustDirty {
|
||||||
|
sql += " AND t1.sync_status <> 0"
|
||||||
|
sqlParams = append(sqlParams, pricePack)
|
||||||
|
}
|
||||||
sql += " ORDER BY t1.store_id DESC, t1.vendor_id"
|
sql += " ORDER BY t1.store_id DESC, t1.vendor_id"
|
||||||
if err = GetRows(db, &storeMapList, sql, sqlParams...); err == nil {
|
if err = GetRows(db, &storeMapList, sql, sqlParams...); err == nil {
|
||||||
return storeMapList, nil
|
return storeMapList, nil
|
||||||
@@ -249,6 +253,10 @@ func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoresMapList(db *DaoDB, vendorIDs, storeIDs []int, status, isSync int, pricePack string) (storeMapList []*model.StoreMap, err error) {
|
||||||
|
return GetStoresMapList2(db, vendorIDs, storeIDs, status, isSync, pricePack, false)
|
||||||
|
}
|
||||||
|
|
||||||
// 此函数在检测到一个门店的所有平台状态一样,且不为StoreStatusOpened时,
|
// 此函数在检测到一个门店的所有平台状态一样,且不为StoreStatusOpened时,
|
||||||
// 将平台门店状态全部改为StoreStatusOpened,则把京西门店状态改为之前那个统一的平台门店状态
|
// 将平台门店状态全部改为StoreStatusOpened,则把京西门店状态改为之前那个统一的平台门店状态
|
||||||
func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
||||||
@@ -580,3 +588,26 @@ func GetStorePriceScoreSnapshot(db *DaoDB, snapDate time.Time) (storePriceScoreS
|
|||||||
err = GetRows(db, &storePriceScoreSnapshot, sql, sqlParams...)
|
err = GetRows(db, &storePriceScoreSnapshot, sql, sqlParams...)
|
||||||
return storePriceScoreSnapshot, err
|
return storePriceScoreSnapshot, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetStoreMapSyncStatus(db *DaoDB, vendorIDs, storeIDs []int, syncStatus int) (num int64, err error) {
|
||||||
|
globals.SugarLogger.Debugf("SetStoreMapSyncStatus, vendorIDs:%v, storeIDs:%v", vendorIDs, storeIDs)
|
||||||
|
|
||||||
|
sql := `
|
||||||
|
UPDATE store_map t1
|
||||||
|
SET t1.sync_status = t1.sync_status | ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
syncStatus,
|
||||||
|
}
|
||||||
|
sql += " WHERE t1.is_sync <> 0 AND t1.deleted_at = ? AND t1.sync_status & ? = 0"
|
||||||
|
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.SyncFlagDeletedMask)
|
||||||
|
if len(vendorIDs) > 0 {
|
||||||
|
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, vendorIDs)
|
||||||
|
}
|
||||||
|
if len(storeIDs) > 0 {
|
||||||
|
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, storeIDs)
|
||||||
|
}
|
||||||
|
return ExecuteSQL(db, sql, sqlParams...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ type StoreSkuSyncInfo struct {
|
|||||||
StoreID int `orm:"column(store_id)"`
|
StoreID int `orm:"column(store_id)"`
|
||||||
SkuID int `orm:"column(sku_id)"` // 这个与Sku.ID的区别是SkuID是必然存在的
|
SkuID int `orm:"column(sku_id)"` // 这个与Sku.ID的区别是SkuID是必然存在的
|
||||||
|
|
||||||
|
BoxFee int64
|
||||||
|
|
||||||
Price int64
|
Price int64
|
||||||
UnitPrice int64
|
UnitPrice int64
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ConfigSysFakeOrderMobiles = "FakeOrderMobiles" // 假订单手机
|
ConfigSysFakeOrderMobiles = "FakeOrderMobiles" // 假订单手机
|
||||||
|
ConfigSysEbaiBoxFee = "EbaiBoxFee" // 饿百打包费
|
||||||
|
ConfigSysMtwmBoxFee = "MtwmBoxFee" // 美团外卖打包费
|
||||||
|
ConfigSysMtwmSkuBoxFee = "MtwmSkuBoxFee" // 美团外卖单商品打包费
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -398,8 +398,6 @@ type StoreMap struct {
|
|||||||
|
|
||||||
FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` //
|
FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` //
|
||||||
|
|
||||||
BoxFee int `orm:"default(0)" json:"boxFee"` // 打包费
|
|
||||||
|
|
||||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||||
DeliveryFee int `json:"deliveryFee"`
|
DeliveryFee int `json:"deliveryFee"`
|
||||||
|
|||||||
@@ -88,11 +88,18 @@ func (p *PurchaseHandler) GetOrderStatus(vendorOrgCode, vendorOrderID string) (s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) getOrder(vendorOrderID string) (order *model.GoodsOrder, orderMap map[string]interface{}, err error) {
|
func (p *PurchaseHandler) getOrder(vendorOrderID string) (order *model.GoodsOrder, orderMap map[string]interface{}, err error) {
|
||||||
result, err := api.EbaiAPI.OrderGet(vendorOrderID)
|
for i := 0; i < 2; i++ {
|
||||||
if err == nil {
|
orderMap, err = api.EbaiAPI.OrderGet(vendorOrderID)
|
||||||
order = p.Map2Order(result)
|
if err == nil {
|
||||||
|
order = p.Map2Order(orderMap)
|
||||||
|
// 饿百订单有时会出现取不到baidu_shop_id的情况,重试
|
||||||
|
if order.VendorStoreID != "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return order, result, err
|
return order, orderMap, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) GetOrder4PartRefund(vendorOrderID string) (order *model.GoodsOrder, err error) {
|
func (p *PurchaseHandler) GetOrder4PartRefund(vendorOrderID string) (order *model.GoodsOrder, err error) {
|
||||||
@@ -187,15 +194,15 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
|||||||
vendorOrderID := orderMap["order_id"].(string)
|
vendorOrderID := orderMap["order_id"].(string)
|
||||||
order = &model.GoodsOrder{
|
order = &model.GoodsOrder{
|
||||||
VendorOrderID: vendorOrderID,
|
VendorOrderID: vendorOrderID,
|
||||||
VendorOrderID2: orderMap["eleme_order_id"].(string),
|
VendorOrderID2: utils.Interface2String(orderMap["eleme_order_id"]),
|
||||||
VendorID: model.VendorIDEBAI,
|
VendorID: model.VendorIDEBAI,
|
||||||
VendorStoreID: shopMap["baidu_shop_id"].(string),
|
VendorStoreID: utils.Interface2String(shopMap["baidu_shop_id"]),
|
||||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)),
|
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)),
|
||||||
StoreName: shopMap["name"].(string),
|
StoreName: utils.Interface2String(shopMap["name"]),
|
||||||
VendorUserID: utils.Interface2String(userMap["user_id"]),
|
VendorUserID: utils.Interface2String(userMap["user_id"]),
|
||||||
ConsigneeName: userMap["name"].(string),
|
ConsigneeName: utils.Interface2String(userMap["name"]),
|
||||||
ConsigneeMobile: jxutils.FormalizeMobile(userMap["phone"].(string)),
|
ConsigneeMobile: jxutils.FormalizeMobile(utils.Interface2String(userMap["phone"])),
|
||||||
ConsigneeAddress: userMap["address"].(string),
|
ConsigneeAddress: utils.Interface2String(userMap["address"]),
|
||||||
CoordinateType: model.CoordinateTypeBaiDu,
|
CoordinateType: model.CoordinateTypeBaiDu,
|
||||||
BuyerComment: utils.TrimBlankChar(utils.Interface2String(orderMap["remark"])),
|
BuyerComment: utils.TrimBlankChar(utils.Interface2String(orderMap["remark"])),
|
||||||
ExpectedDeliveredTime: getTimeFromInterface(orderMap["send_time"]),
|
ExpectedDeliveredTime: getTimeFromInterface(orderMap["send_time"]),
|
||||||
@@ -453,6 +460,10 @@ func (c *PurchaseHandler) onOrderNew(msg *ebaiapi.CallbackMsg, orderStatus *mode
|
|||||||
vendorOrderID := GetOrderIDFromMsg(msg)
|
vendorOrderID := GetOrderIDFromMsg(msg)
|
||||||
order, orderMap, err := c.getOrder(vendorOrderID)
|
order, orderMap, err := c.getOrder(vendorOrderID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// 饿百订单有时会出现取不到baidu_shop_id的情况,返回错误让服务器重试
|
||||||
|
if order.VendorStoreID == "" {
|
||||||
|
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, fmt.Errorf("订单%s的baidu_shop_id为空", order.VendorOrderID), "")
|
||||||
|
}
|
||||||
if err = partner.CurOrderManager.OnOrderNew(order, orderStatus); err == nil {
|
if err = partner.CurOrderManager.OnOrderNew(order, orderStatus); err == nil {
|
||||||
utils.CallFuncAsync(func() {
|
utils.CallFuncAsync(func() {
|
||||||
c.OnOrderDetail(orderMap, partner.CreatedPeration)
|
c.OnOrderDetail(orderMap, partner.CreatedPeration)
|
||||||
|
|||||||
@@ -400,6 +400,9 @@ func genStoreMapFromStore(store *tEbaiStoreInfo) map[string]interface{} {
|
|||||||
params["name"] = jxutils.ComposeStoreName(store.Name, model.VendorIDEBAI)
|
params["name"] = jxutils.ComposeStoreName(store.Name, model.VendorIDEBAI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// boxFee, _ := dao.GetSysConfigAsInt64(dao.GetDB(), model.ConfigSysEbaiBoxFee)
|
||||||
|
// params["package_box_price"] = boxFee
|
||||||
|
|
||||||
params["address"] = store.Address
|
params["address"] = store.Address
|
||||||
// todo 饿百 开店审核通过后不允许修改商户信息
|
// todo 饿百 开店审核通过后不允许修改商户信息
|
||||||
if store.SyncStatus&(model.SyncFlagNewMask /*|model.SyncFlagStoreAddress*/) != 0 {
|
if store.SyncStatus&(model.SyncFlagNewMask /*|model.SyncFlagStoreAddress*/) != 0 {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
|||||||
errList.AddErr(p.UpdateStoreStatus(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, mergedStoreStatus))
|
errList.AddErr(p.UpdateStoreStatus(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, mergedStoreStatus))
|
||||||
}
|
}
|
||||||
errList.AddErr(p.UpdateStoreOpTime(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, storeDetail.GetOpTimeList()))
|
errList.AddErr(p.UpdateStoreOpTime(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, storeDetail.GetOpTimeList()))
|
||||||
errList.AddErr(p.UpdateStoreBoxFee(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID, storeDetail.BoxFee))
|
errList.AddErr(p.UpdateStoreBoxFee(jxcontext.AdminCtx, storeDetail.VendorOrgCode, storeID, storeDetail.VendorStoreID))
|
||||||
return errList.GetErrListAsOne()
|
return errList.GetErrListAsOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +292,10 @@ func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgC
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PurchaseHandler) UpdateStoreBoxFee(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, boxFee int) (err error) {
|
func (c *PurchaseHandler) UpdateStoreBoxFee(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (err error) {
|
||||||
err = api.MtwmAPI.PackagePriceUpdate(vendorStoreID, 1, boxFee)
|
// boxFee, err := dao.GetSysConfigAsInt64(dao.GetDB(), model.ConfigSysMtwmBoxFee)
|
||||||
|
// if err == nil {
|
||||||
|
// err = api.MtwmAPI.PackagePriceUpdate(vendorStoreID, 1, int(boxFee))
|
||||||
|
// }
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ const (
|
|||||||
|
|
||||||
specialStoreID = "8171010"
|
specialStoreID = "8171010"
|
||||||
// specialStoreID = "2523687"
|
// specialStoreID = "2523687"
|
||||||
fixBoxFee = 10
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -254,7 +253,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
foodData["min_order_count"] = 1
|
foodData["min_order_count"] = 1
|
||||||
foodData["unit"] = storeSku.Unit
|
foodData["unit"] = storeSku.Unit
|
||||||
foodData["box_num"] = 1
|
foodData["box_num"] = 1
|
||||||
foodData["box_price"] = jxutils.IntPrice2Standard(fixBoxFee)
|
foodData["box_price"] = jxutils.IntPrice2Standard(storeSku.BoxFee)
|
||||||
catCode := tryCatName2Code(storeSku.VendorCatID)
|
catCode := tryCatName2Code(storeSku.VendorCatID)
|
||||||
if catCode != "" {
|
if catCode != "" {
|
||||||
foodData["category_code"] = catCode
|
foodData["category_code"] = catCode
|
||||||
|
|||||||
@@ -144,6 +144,33 @@ func (c *SyncController) DeleteRemoteStoreSkus() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 同步门店
|
||||||
|
// @Description 同步门店
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param vendorIDs formData string false "平台ID(京东0 美团1 饿百3)列表"
|
||||||
|
// @Param vendorOrgCodes formData string false "平台账号列表"
|
||||||
|
// @Param storeIDs formData string false "门店ID列表"
|
||||||
|
// @Param isForce formData bool false "是否强制(设置修改标志)"
|
||||||
|
// @Param isAsync formData bool false "是否异步"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /SyncStores [post]
|
||||||
|
func (c *SyncController) SyncStores() {
|
||||||
|
c.callSyncStores(func(params *tSyncSyncStoresParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var vendorIDs, storeIDs []int
|
||||||
|
var vendorOrgCodes []string
|
||||||
|
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.StoreIDs, &storeIDs, params.VendorOrgCodes, &vendorOrgCodes); err == nil {
|
||||||
|
db := dao.GetDB()
|
||||||
|
if params.IsForce {
|
||||||
|
dao.SetStoreMapSyncStatus(db, vendorIDs, storeIDs, model.SyncFlagModifiedMask)
|
||||||
|
}
|
||||||
|
retVal, err = cms.CurVendorSync.SyncStore2(params.Ctx, db, vendorIDs, storeIDs, true, params.IsAsync)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 同步商家分类(多门店平台)
|
// @Title 同步商家分类(多门店平台)
|
||||||
// @Description 同步商家分类(多门店平台)
|
// @Description 同步商家分类(多门店平台)
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
|
|||||||
@@ -1944,6 +1944,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "SyncStores",
|
||||||
|
Router: `/SyncStores`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "SyncStoresCategory",
|
Method: "SyncStoresCategory",
|
||||||
|
|||||||
Reference in New Issue
Block a user