+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) {
|
||||
storePageInfo, err = handler.GetStorePageInfo(ctx, vendorStoreID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
updatePageShopCityDistrictInfo(ctx, storePageInfo, cityCode)
|
||||
}
|
||||
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) {
|
||||
if len(coordList) > 0 {
|
||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||
@@ -230,28 +234,23 @@ func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeLis
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshPageStore(ctx *jxcontext.Context) (err error) {
|
||||
func RefreshPageShops(ctx *jxcontext.Context) (err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
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()
|
||||
var shopList []*model.PageShop
|
||||
if err = dao.GetRows(db, &shopList, sql); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range shopList {
|
||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(v.VendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||
storePageInfo, err2 := getStorePageInfo(ctx, handler, v.CityCode, v.VendorStoreID)
|
||||
if err2 == nil {
|
||||
v.RecentOrderNum = storePageInfo.RecentOrderNum
|
||||
v.SkuCount = storePageInfo.SkuCount
|
||||
dao.UpdateEntity(db, v, "RecentOrderNum", "SkuCount")
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("RefreshPageStore err:%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("刷新网页门店信息:%d", len(shopList)), nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pageShop := batchItemList[0].(*model.PageShop)
|
||||
updatePageShopCityDistrictInfo(ctx, pageShop, pageShop.CityCode)
|
||||
_, err = dao.UpdateEntity(db, pageShop, "CityCode", "DistrictCode", "Lng", "Lat")
|
||||
return retVal, err
|
||||
}, shopList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -136,3 +136,16 @@ func (l PageShopList) Less(i, j int) bool {
|
||||
func (l PageShopList) Swap(i, j int) {
|
||||
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,
|
||||
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.ControllerComments{
|
||||
Method: "AcceptOrRefuseFailedGetOrder",
|
||||
|
||||
Reference in New Issue
Block a user