- RefreshMissingDadaStores
- auto acreate dada store when link jd store
This commit is contained in:
@@ -8,14 +8,17 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -424,7 +427,8 @@ func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vend
|
||||
return storeMaps, dao.GetEntitiesByKV(db, &storeMaps, cond, false)
|
||||
}
|
||||
|
||||
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
|
||||
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeMap *model.StoreMap) (outStoreMap *model.StoreMap, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil {
|
||||
store, err2 := handler.ReadStore(storeMap.VendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
@@ -456,6 +460,21 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID
|
||||
} else {
|
||||
err = ErrCanNotFindVendor
|
||||
}
|
||||
if err == nil && vendorID == model.VendorIDJD {
|
||||
db2 := dao.GetDB()
|
||||
storeDetailList, err2 := dao.GetMissingDadaStores(db2, storeID)
|
||||
if err = err2; err == nil {
|
||||
storeDetail := storeDetailList[0]
|
||||
if _, err = api.DadaAPI.ShopAdd(utils.Int2Str(storeID), storeDetail.Name, dadaapi.BusinessTypeFruitVegetable, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil); err == nil {
|
||||
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
Status: model.StoreStatusOpened,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return outStoreMap, err
|
||||
}
|
||||
|
||||
@@ -635,7 +654,8 @@ func GetStoreCourierMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, ven
|
||||
return storeCourierMaps, dao.GetEntitiesByKV(db, &storeCourierMaps, cond, false)
|
||||
}
|
||||
|
||||
func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, userName string) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
|
||||
dao.WrapAddIDCULDEntity(storeCourierMap, userName)
|
||||
storeCourierMap.StoreID = storeID
|
||||
@@ -694,3 +714,35 @@ func UpdateStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendo
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func RefreshMissingDadaStores(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetMissingDadaStores(db, 0)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
task := tasksch.NewParallelTask("RefreshMissingDadaStores", nil, ctx.GetUserName(), func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||
_, err = api.DadaAPI.ShopDetail(utils.Int2Str(storeDetail.ID))
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(utils.Int2Str(storeDetail.ID), storeDetail.Name, dadaapi.BusinessTypeFruitVegetable, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
Status: model.StoreStatusOpened,
|
||||
})
|
||||
}
|
||||
return nil, err
|
||||
}, storeList)
|
||||
ctx.SetTaskOrAddChild(task, nil)
|
||||
tasksch.ManageTask(task).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -22,12 +22,19 @@ type StoreDetail struct {
|
||||
model.Place // district info
|
||||
}
|
||||
|
||||
type StoreDetail2 struct {
|
||||
model.Store
|
||||
VendorStoreID string `orm:"column(vendor_store_id)`
|
||||
DistrictName string
|
||||
CityName string
|
||||
}
|
||||
|
||||
func GetStoreDetail(db *DaoDB, storeID, vendorID int) (storeDetail *StoreDetail, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
t2.vendor_store_id, t2.status vendor_status, t2.delivery_fee, t2.sync_status,
|
||||
t2.price_percentage, t2.auto_pickup, t2.delivery_type, t2.delivery_competition, t2.is_sync,
|
||||
district.*
|
||||
district.code, district.name, district.parent_code, district.level, district.tel_code, district.jd_code, district.ebai_code, district.enabled, district.mtps_price
|
||||
FROM store t1
|
||||
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
|
||||
LEFT JOIN place district ON t1.district_code = district.code
|
||||
@@ -40,7 +47,7 @@ func GetStoreDetail(db *DaoDB, storeID, vendorID int) (storeDetail *StoreDetail,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (storeList []*StoreDetail, err error) {
|
||||
func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (storeList []*StoreDetail2, err error) {
|
||||
sqlList := []string{
|
||||
`
|
||||
SELECT t1.*, t5.vendor_store_id
|
||||
@@ -50,8 +57,8 @@ func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (sto
|
||||
WHERE t1.status = ?
|
||||
`,
|
||||
`
|
||||
SELECT t1.*
|
||||
FROM store t1, t5.vendor_store_id
|
||||
SELECT t1.*, t5.vendor_store_id
|
||||
FROM store t1
|
||||
JOIN place t2 ON t2.code = t1.city_code
|
||||
JOIN place t3 ON t3.code = t2.parent_code AND t3.name = ?
|
||||
LEFT JOIN store_map t5 ON t1.id = t5.store_id AND t5.vendor_id = ? AND t5.deleted_at = ?
|
||||
@@ -94,3 +101,34 @@ func GetPossibleStoresByPlaceName(db *DaoDB, cityName, provinceName string) (sto
|
||||
// 正常是不应该达到这里的
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
// 这个返回的地点信息是城市
|
||||
func GetMissingDadaStores(db *DaoDB, storeID int) (storeList []*StoreDetail2, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
t2.vendor_store_id,
|
||||
city.name city_name, district.name district_name
|
||||
FROM store t1
|
||||
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
|
||||
JOIN place city ON city.code = t1.city_code
|
||||
JOIN place district ON district.code = t1.district_code
|
||||
LEFT JOIN store_map t3 ON t3.store_id = t1.id AND t3.vendor_id = ? AND t3.deleted_at = ?
|
||||
WHERE t1.deleted_at = ? AND t1.status <> ? AND t3.id IS NULL
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.VendorIDJD,
|
||||
utils.DefaultTimeValue,
|
||||
model.VendorIDDada,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.StoreStatusDisabled,
|
||||
}
|
||||
if storeID != 0 {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if err = GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||
return storeList, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func (p *PurchaseHandler) arrangeSaleStore(order *model.GoodsOrder, cityName, pr
|
||||
userLng := jxutils.IntCoordinate2Standard(order.ConsigneeLng)
|
||||
userLat := jxutils.IntCoordinate2Standard(order.ConsigneeLat)
|
||||
for k, store := range storeList {
|
||||
// 展示门店自身不参与排单
|
||||
// 展示门店自身不参与派单
|
||||
if store.VendorStoreID != order.VendorStoreID {
|
||||
sortItem := &utils.SortItem{
|
||||
CompareValue: int64(jxutils.EarthDistance(userLng, userLat, jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat)) * 1000),
|
||||
|
||||
@@ -254,7 +254,29 @@ func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentT
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return hint, err
|
||||
userName := ctx.GetUserName()
|
||||
globals.SugarLogger.Debugf("wsc FullSyncStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
db := dao.GetDB()
|
||||
rootTask := tasksch.NewSeqTask("微盟微商城FullSyncStoreSkus", userName, func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
case 1:
|
||||
_, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDWSC, storeID, nil, model.SyncFlagNewMask)
|
||||
case 2:
|
||||
_, err = p.SyncLocalStoreCategory(ctx, db, storeID, false)
|
||||
case 3:
|
||||
_, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||
case 4:
|
||||
_, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError)
|
||||
}
|
||||
return nil, err
|
||||
}, 5)
|
||||
tasksch.AddChild(parentTask, rootTask).Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
}
|
||||
return rootTask.ID, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
|
||||
@@ -166,7 +166,7 @@ func (c *StoreController) AddStoreVendorMap() {
|
||||
c.callAddStoreVendorMap(func(params *tStoreAddStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||
storeMap := &model.StoreMap{}
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), storeMap); err == nil {
|
||||
retVal, err = cms.AddStoreVendorMap(params.Ctx, nil, params.StoreID, params.VendorID, storeMap, params.Ctx.GetUserName())
|
||||
retVal, err = cms.AddStoreVendorMap(params.Ctx, nil, params.StoreID, params.VendorID, storeMap)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
@@ -268,7 +268,7 @@ func (c *StoreController) AddStoreCourierMap() {
|
||||
c.callAddStoreCourierMap(func(params *tStoreAddStoreCourierMapParams) (retVal interface{}, errCode string, err error) {
|
||||
storeCourierMap := &model.StoreCourierMap{}
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), storeCourierMap); err == nil {
|
||||
retVal, err = cms.AddStoreCourierMap(params.Ctx, nil, params.StoreID, params.VendorID, storeCourierMap, params.Ctx.GetUserName())
|
||||
retVal, err = cms.AddStoreCourierMap(params.Ctx, nil, params.StoreID, params.VendorID, storeCourierMap)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
@@ -288,3 +288,17 @@ func (c *StoreController) DeleteStoreCourierMap() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 根据绑定的京东定,自动创建达达店
|
||||
// @Description 根据绑定的京东定,自动创建达达店
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isAsync query bool true "是否异步操作"
|
||||
// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /RefreshMissingDadaStores [put]
|
||||
func (c *StoreController) RefreshMissingDadaStores() {
|
||||
c.callRefreshMissingDadaStores(func(params *tStoreRefreshMissingDadaStoresParams) (retVal interface{}, errCode string, err error) {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user