新接口获取京东门店手划范围

This commit is contained in:
苏尹岚
2020-09-03 15:45:25 +08:00
parent ba0f74b86d
commit ddabf4c763
4 changed files with 106 additions and 77 deletions

View File

@@ -3455,3 +3455,82 @@ func UpdateStorePricePack(ctx *jxcontext.Context, storeID, vendorID int, pricePa
}
return err
}
func GetJdDeliveryArea(ctx *jxcontext.Context, storeIDs []int) (err error) {
type tmp struct {
JdID string `json:"jdID"`
S int `json:"s"`
}
type SpecialtyStoreSkus struct {
StoreID int `json:"门店ID"`
StoreName string `json:"门店名"`
City string `json:"城市"`
Area int `json:"面积"`
}
var (
ss []*tmp
excelTitle = []string{
"门店ID",
"门店名",
"城市",
"面积",
}
sheetList []*excel.Obj2ExcelSheetConfig
specialtyStoreSkus []*SpecialtyStoreSkus
downloadURL, fileName string
)
storeMaps, _ := dao.GetStoresMapList(dao.GetDB(), []int{model.VendorIDJD}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
for _, v := range storeMaps {
time.Sleep(time.Second / 3)
station, err := jd.GetAPI("320406").GetDeliveryRangeByStationNo2(v.VendorStoreID)
if err != nil {
continue
}
if station.DeliveryRangeType == 2 {
strs := strings.Split(station.DeliveryRange, ";")
ss = append(ss, &tmp{
JdID: v.VendorStoreID,
S: utils.Float64TwoInt(math.Ceil((jxutils.ComputeSignedArea(strs[:len(strs)-1])))),
})
}
}
for i := 0; i < len(ss)-1; i++ {
for j := 0; j < len(ss)-1-i; j++ {
if ss[j].S > ss[j+1].S {
temp := ss[j]
ss[j] = ss[j+1]
ss[j+1] = temp
}
}
}
for _, v := range ss {
storeDetail, _ := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), v.JdID, model.VendorIDJD)
place, _ := dao.GetPlaceByCode(dao.GetDB(), storeDetail.CityCode)
specialtyStoreSku := &SpecialtyStoreSkus{
StoreID: storeDetail.ID,
StoreName: storeDetail.Name,
City: place.Name,
Area: v.S,
}
specialtyStoreSkus = append(specialtyStoreSkus, specialtyStoreSku)
}
excelConf := &excel.Obj2ExcelSheetConfig{
Title: "sheet1",
Data: specialtyStoreSkus,
CaptionList: excelTitle,
}
sheetList = append(sheetList, excelConf)
if excelConf != nil {
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "面积")
} else {
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
}
if err != nil {
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err)
} else {
noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, ctx.GetUserID(), "异步任务完成", noticeMsg)
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess downloadURL: [%v]", downloadURL)
}
return err
}