+RefreshPageShops
This commit is contained in:
@@ -51,30 +51,34 @@ func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []
|
|||||||
func getStorePageInfo(ctx *jxcontext.Context, handler partner.IPurchasePlatformNetSpiderHandler, cityCode int, vendorStoreID string) (storePageInfo *model.PageShop, err error) {
|
func getStorePageInfo(ctx *jxcontext.Context, handler partner.IPurchasePlatformNetSpiderHandler, cityCode int, vendorStoreID string) (storePageInfo *model.PageShop, err error) {
|
||||||
storePageInfo, err = handler.GetStorePageInfo(ctx, vendorStoreID)
|
storePageInfo, err = handler.GetStorePageInfo(ctx, vendorStoreID)
|
||||||
if err == nil && storePageInfo != nil {
|
if err == nil && storePageInfo != nil {
|
||||||
if !(storePageInfo.Lng != 0 && storePageInfo.Lat != 0) {
|
updatePageShopCityDistrictInfo(ctx, storePageInfo, cityCode)
|
||||||
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(cityCode))
|
|
||||||
if storePageInfo.DistrictCode == 0 && cityCode != 0 {
|
|
||||||
if place, err := dao.GetPlaceByCode(dao.GetDB(), cityCode); err == nil {
|
|
||||||
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(place.ParentCode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if storePageInfo.DistrictCode == 0 {
|
|
||||||
storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(storePageInfo.Lng, storePageInfo.Lat)
|
|
||||||
}
|
|
||||||
if storePageInfo.CityCode == 0 {
|
|
||||||
if storePageInfo.DistrictCode != 0 {
|
|
||||||
if place, err := dao.GetPlaceByCode(dao.GetDB(), storePageInfo.DistrictCode); err == nil {
|
|
||||||
storePageInfo.CityCode = place.ParentCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if storePageInfo.CityCode == 0 {
|
|
||||||
storePageInfo.CityCode = cityCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return storePageInfo, err
|
return storePageInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updatePageShopCityDistrictInfo(ctx *jxcontext.Context, storePageInfo *model.PageShop, cityCode int) {
|
||||||
|
if !(storePageInfo.Lng != 0 && storePageInfo.Lat != 0) {
|
||||||
|
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(cityCode))
|
||||||
|
if storePageInfo.DistrictCode == 0 && cityCode != 0 {
|
||||||
|
if place, err := dao.GetPlaceByCode(dao.GetDB(), cityCode); err == nil {
|
||||||
|
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(place.ParentCode))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if storePageInfo.DistrictCode == 0 {
|
||||||
|
storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(storePageInfo.Lng, storePageInfo.Lat)
|
||||||
|
}
|
||||||
|
if storePageInfo.CityCode == 0 {
|
||||||
|
if storePageInfo.DistrictCode != 0 {
|
||||||
|
if place, err := dao.GetPlaceByCode(dao.GetDB(), storePageInfo.DistrictCode); err == nil {
|
||||||
|
storePageInfo.CityCode = place.ParentCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if storePageInfo.CityCode == 0 {
|
||||||
|
storePageInfo.CityCode = cityCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, cityCode int, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
|
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, cityCode int, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
|
||||||
if len(coordList) > 0 {
|
if len(coordList) > 0 {
|
||||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||||
@@ -230,28 +234,23 @@ func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeLis
|
|||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefreshPageStore(ctx *jxcontext.Context) (err error) {
|
func RefreshPageShops(ctx *jxcontext.Context) (err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM page_shop t1
|
FROM page_shop t1
|
||||||
WHERE t1.vendor_id = 0
|
WHERE t1.district_code = 0 AND t1.lng != 0 AND t1.lat != 0`
|
||||||
`
|
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
var shopList []*model.PageShop
|
var shopList []*model.PageShop
|
||||||
if err = dao.GetRows(db, &shopList, sql); err != nil {
|
if err = dao.GetRows(db, &shopList, sql); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, v := range shopList {
|
task := tasksch.NewParallelTask(fmt.Sprintf("刷新网页门店信息:%d", len(shopList)), nil, ctx,
|
||||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(v.VendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
storePageInfo, err2 := getStorePageInfo(ctx, handler, v.CityCode, v.VendorStoreID)
|
pageShop := batchItemList[0].(*model.PageShop)
|
||||||
if err2 == nil {
|
updatePageShopCityDistrictInfo(ctx, pageShop, pageShop.CityCode)
|
||||||
v.RecentOrderNum = storePageInfo.RecentOrderNum
|
_, err = dao.UpdateEntity(db, pageShop, "CityCode", "DistrictCode", "Lng", "Lat")
|
||||||
v.SkuCount = storePageInfo.SkuCount
|
return retVal, err
|
||||||
dao.UpdateEntity(db, v, "RecentOrderNum", "SkuCount")
|
}, shopList)
|
||||||
} else {
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
globals.SugarLogger.Debugf("RefreshPageStore err:%v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,3 +136,16 @@ func (l PageShopList) Less(i, j int) bool {
|
|||||||
func (l PageShopList) Swap(i, j int) {
|
func (l PageShopList) Swap(i, j int) {
|
||||||
l[i], l[j] = l[j], l[i]
|
l[i], l[j] = l[j], l[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 刷新网页门店信息
|
||||||
|
// @Description 刷新网页门店信息
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /RefreshPageShops [post]
|
||||||
|
func (c *NetSpiderController) RefreshPageShops() {
|
||||||
|
c.callRefreshPageShops(func(params *tNetspiderRefreshPageShopsParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
err = netspider.RefreshPageShops(params.Ctx)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -702,6 +702,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:NetSpiderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:NetSpiderController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "RefreshPageShops",
|
||||||
|
Router: `/RefreshPageShops`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "AcceptOrRefuseFailedGetOrder",
|
Method: "AcceptOrRefuseFailedGetOrder",
|
||||||
|
|||||||
Reference in New Issue
Block a user