From dc5711ca8cae337707a1cd242a3251a667c95894 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Sat, 27 Jun 2020 08:12:59 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A=E6=8A=8A=E6=89=80=E6=9C=89=E8=90=A5=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E9=97=A8=E5=BA=97=EF=BC=8C=E4=BA=AC=E8=A5=BF=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E9=97=A8=E5=BA=97=E9=83=BD=E6=89=93=E5=BC=80=EF=BC=8C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=8C=83=E5=9B=B43km=EF=BC=8C=E9=BB=98=E8=AE=A4100-10?= =?UTF-8?q?0=E4=BA=AC=E8=A5=BF=E4=BB=B7=E6=A0=BC=E5=A5=97=E9=A4=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 57 +++++++++++++++++++++++++ controllers/temp_op.go | 17 ++++++++ routers/commentsRouter_controllers.go | 28 ++++++++++++ 3 files changed, 102 insertions(+) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index d34526a67..83c3cf2e1 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -5,6 +5,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "github.com/astaxie/beego" + "strconv" "strings" "sync" "time" @@ -563,6 +564,62 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool } } +func StoreOpenAll(ctx *jxcontext.Context) { + db := dao.GetDB() + StoreLists, err := dao.GetStoreList(db, nil, nil, []int{1}, nil, "") + if err != nil { + globals.SugarLogger.Debugf("商店列表获取失败") + } + var StoreMapLists []*model.StoreMap + for _, StoreList := range StoreLists { + if StoreMapLists, err = dao.GetStoresMapList(db, []int{0, 1, 3}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { + globals.SugarLogger.Debugf("商店列表获取失败") + } + if len(StoreMapLists) > 0 { + /*将map查询的结果全部放进数组*/ + for _, StoreMapList := range StoreMapLists { + /*二元运算符*/ + StoreMapList.SyncStatus = StoreMapList.SyncStatus | model.SyncFlagModifiedMask + StoreMapList.UpdatedAt = time.Now() + StoreMapList.LastOperator = ctx.GetUserName() + dao.UpdateEntity(db, StoreMapList, "SyncStatus", "UpdatedAt", "LastOperator") + //} + /*同步*/ + if _, err = CurVendorSync.SyncStore(ctx, db, StoreMapList.VendorID, StoreList.ID, false, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debugf("同步失败") + } + } + } + if StoreMapLists, err = dao.GetStoresMapList(db, []int{9}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { + globals.SugarLogger.Debugf("商店列表获取失败") + } + if len(StoreMapLists) == 0 { + /*遍历,绑定*/ + Map := &model.StoreMap{} + Map.VendorStoreID = strconv.Itoa(StoreList.ID) + Map.AutoPickup = 1 + Map.DeliveryCompetition = 1 + Map.PricePercentage = 100 + Map.IsSync = 1 + Map.PricePercentagePack = "京西100-100" + Map.DeliveryFeeDeductionSill = 0 + Map.DeliveryFeeDeductionFee = 0 + Map.IsOrder = 0 + if _, err := AddStoreVendorMap(ctx, db, 9, "", StoreList.ID, Map); err != nil { + globals.SugarLogger.Debugf("AddStoreVendorMap调用出错,StoreID是" + strconv.Itoa(StoreList.ID)) + } + } + /*改配送范围*/ + //deliverrangetype 3 + //deliverrange 3000 + StoreList.DeliveryRange = "3000" + StoreList.DeliveryRangeType = 3 + StoreList.UpdatedAt = time.Now() + StoreList.LastOperator = ctx.GetUserName() + dao.UpdateEntity(db, StoreList, "DeliveryRange", "DeliveryRangeType", "LastOperator", "UpdatedAt") + } +} + func TestDiff(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now()) startProcessTime := time.Now().Unix() diff --git a/controllers/temp_op.go b/controllers/temp_op.go index f73763f27..d9e55c8ab 100644 --- a/controllers/temp_op.go +++ b/controllers/temp_op.go @@ -311,6 +311,23 @@ func (c *TempOpController) StoreSkuCheckDiff() { }) } +// @Title 把所有营业的门店,京西商城门店都打开,默认范围3km,默认100-100京西价格套餐 +// @Description 对比Test +// @Param token header string true "认证token" +// @Success 200 {object} controllers.CallResult +// @Failure 404 User not found +// @router /StoreOpenAll [post] +func (c *TempOpController) StoreOpenAll() { + c.callCheckSkuDiffBetweenJxAndVendor(func(params *tTempopCheckSkuDiffBetweenJxAndVendorParams) (retVal interface{}, errCode string, err error) { + var vendorIDList []int + var storeIDList []int + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList, params.StoreIDs, &storeIDList); err == nil { + cms.StoreOpenAll(params.Ctx) + } + return retVal, "", err + }) +} + // @Title 通过订单创建消费者用户 // @Description 通过订单创建消费者用户 // @Param token header string true "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 79bf8f9aa..9c584ef7c 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1224,6 +1224,15 @@ func init() { 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: "SaveJdsOrders", + Router: `/SaveJdsOrders`, + 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: "SelfDelivered", @@ -1539,6 +1548,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], + beego.ControllerComments{ + Method: "UpdateSkuExinfoMap", + Router: `/UpdateSkuExinfoMap`, + AllowHTTPMethods: []string{"put"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"], beego.ControllerComments{ Method: "UpdateSkuName", @@ -2502,6 +2520,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], + beego.ControllerComments{ + Method: "StoreOpenAll", + Router: `/StoreOpenAll`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"], beego.ControllerComments{ Method: "StoreSkuCheckDiff", @@ -2816,4 +2843,5 @@ func init() { MethodParams: param.Make(), Filters: nil, Params: nil}) + } From 45b9559b0d86afcc015222c08e5fdbae25ec4219 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Sat, 27 Jun 2020 10:10:48 +0800 Subject: [PATCH 2/6] test --- business/jxstore/cms/store_sku_check.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 83c3cf2e1..4f1c4515d 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -607,6 +607,7 @@ func StoreOpenAll(ctx *jxcontext.Context) { Map.IsOrder = 0 if _, err := AddStoreVendorMap(ctx, db, 9, "", StoreList.ID, Map); err != nil { globals.SugarLogger.Debugf("AddStoreVendorMap调用出错,StoreID是" + strconv.Itoa(StoreList.ID)) + globals.SugarLogger.Debugf(err.Error()) } } /*改配送范围*/ From b297499b0df0e4f340cfa501ca5ae26d76bb5fea Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Mon, 29 Jun 2020 09:14:19 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E6=AF=94=E7=BE=8E=E5=9B=A2=E5=9B=A2=E5=92=8C?= =?UTF-8?q?=E9=97=A8=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 379 +++++++++++++++++++++--- 1 file changed, 331 insertions(+), 48 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 4f1c4515d..2bef0d039 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -1,10 +1,15 @@ package cms import ( + "encoding/json" "fmt" "git.rosy.net.cn/baseapi/platformapi/dingdingapi" + "git.rosy.net.cn/cms" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" + "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" + "io/ioutil" + "net/http" "strconv" "strings" "sync" @@ -565,62 +570,340 @@ func CompareJxAndMultiVenderDepot(ctx *jxcontext.Context, vendorMap map[int]bool } func StoreOpenAll(ctx *jxcontext.Context) { - db := dao.GetDB() - StoreLists, err := dao.GetStoreList(db, nil, nil, []int{1}, nil, "") - if err != nil { - globals.SugarLogger.Debugf("商店列表获取失败") + /* 美团配送的门店营业状态,如果是休息,则京西这边不发单,如果是营业,京西这边状态就是发单 + 美团配送的门店营业状态要通过网页扒取(应该是接了的代码里要找一下)*/ + /*获取门店信息*/ + type DataList struct { + OuterPoiId string `json:"outerPoiId"` //店ID + PoiName string `json:"poiName"` //店名 + OpenType int `json:"openType"` //营业状态 1是营业 0是休息 } - var StoreMapLists []*model.StoreMap - for _, StoreList := range StoreLists { - if StoreMapLists, err = dao.GetStoresMapList(db, []int{0, 1, 3}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { - globals.SugarLogger.Debugf("商店列表获取失败") + type jdData struct { + PageNum int `json:"pageNum"` + PageSize int `json:"pageSize"` + DataList []DataList `json:"dataList"` + } + type JdStore struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data1 jdData `json:"data"` + } + client := &http.Client{} + var StoreInfoList []*JdStore + num := 1 + for { + /* cookie还需要修改*/ + /* context.TODO()*/ + cookie := "_lxsdk_cuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "_lxsdk=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "uuid=fa1894be8819a84be4ef.1592458555.1.0.0; wm_order_channel=sjzxpc; " + + "cssVersion=82f258e3; utm_source=60376; au_trace_key_net=default; " + + "openh5_uuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "bmm-uuid=dbdc11bf-fcfe-84a0-0586-97e3d7d23ec7; " + + "token=-MfbU7noKEgDWuNA559DeG6LmYZ51CCiH8bYrH-eYuaugCOqJL7863lKoAWfx8HoydOzJE8r9gGM3QJ0IC3niA; " + + "_lxsdk_s=172fa436aed-861-103-c9b%7C%7C7" + url := "https://peisong.meituan.com/api/haikuiopen/haikui/open/partner/poi/search?pageSize=20&pageNum=" + strconv.Itoa(num) + "" + req, _ := http.NewRequest("POST", url, nil) + req.Header.Set("Cookie", cookie) + req.Header.Set("Referer", "https://peisong.meituan.com/open/admin/accountList") + res, _ := client.Do(req) + defer res.Body.Close() + if res.Body != nil { + StoreInfo := &JdStore{} + body, _ := ioutil.ReadAll(res.Body) + json.Unmarshal(body, StoreInfo) + StoreInfoList = append(StoreInfoList, StoreInfo) + if StoreInfo.Data1.DataList == nil { + break + } + num++ + } else { + break } - if len(StoreMapLists) > 0 { - /*将map查询的结果全部放进数组*/ - for _, StoreMapList := range StoreMapLists { - /*二元运算符*/ - StoreMapList.SyncStatus = StoreMapList.SyncStatus | model.SyncFlagModifiedMask - StoreMapList.UpdatedAt = time.Now() - StoreMapList.LastOperator = ctx.GetUserName() - dao.UpdateEntity(db, StoreMapList, "SyncStatus", "UpdatedAt", "LastOperator") - //} - /*同步*/ - if _, err = CurVendorSync.SyncStore(ctx, db, StoreMapList.VendorID, StoreList.ID, false, ctx.GetUserName()); err != nil { - globals.SugarLogger.Debugf("同步失败") + } + /*StoreInfoList1 map[11691658]=1*/ + StoreInfoList1 := make(map[string]int) + for _, store := range StoreInfoList { + for _, data := range store.Data1.DataList { + StoreInfoList1[data.OuterPoiId] = data.OpenType + } + } + /* fmt.Println(num) + fmt.Println(StoreInfoList)*/ + db := dao.GetDB() + /*比较营业状态*/ + StoreCourierList, err := dao.GetStoreCourierList(db, []int{0}, -9, -9) + for _, StoreCourierList1 := range StoreCourierList { + if _, ok := StoreInfoList1[StoreCourierList1.VendorStoreID]; ok { + /*营业状态是没有营业的,但是京西却关联美团了*/ + if StoreInfoList1[StoreCourierList1.VendorStoreID] == 0 { + //调用方法解绑 {"status":0,"vendorStoreID":"667222"} + sl := make(map[string]interface{}) + sl["status"] = 0 + sl["vendorStoreID"] = "667222" + cms.UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) + } + } + } + /* 美团配送的门店是否存在,调用美团配送的api(有可能接了),查询京西门店对应的美团配送门店是否存在,若不存在则要在京西这边解绑美团配送门店 + 怎么解绑可以在网页上门店管理那点一下看看调的什么接口,传的什么参数*/ + /*获取所有门店信息*/ + StoreLists, err := dao.GetStoreList(db, nil, nil, []int{}, nil, "") + if err != nil { + globals.SugarLogger.Debug(err.Error()) + } + for _, StoreList := range StoreLists { + StoreCourierList, err := dao.GetStoreCourierList(db, []int{StoreList.ID}, -9, -9) + if err != nil { + globals.SugarLogger.Debug(err.Error()) + } + for _, StoreCourierList1 := range StoreCourierList { + if StoreCourierList1.VendorID != 102 { + continue + } + /*京西不为空*/ + if StoreCourierList1.VendorStoreID != "" { + /*调用API获取美团的商店信息*/ + MTPSInfo, _ := api.MtpsAPI.ShopQuery(StoreCourierList1.VendorStoreID) + if MTPSInfo.ShopID != "" { + if MTPSInfo.ShopName == StoreList.Name { + /*平台上有且名字相同*/ + continue + } else { + /*平台上但是名字不同,解绑*/ + if _, err := cms.DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + } + } else { + /*美团平台上面没找到,解绑*/ + if _, err := cms.DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + //} else { + // 美团平台上有,京西没得,调用方法可能需要做一些修改 + // context.TODO() + //} } } } - if StoreMapLists, err = dao.GetStoresMapList(db, []int{9}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { - globals.SugarLogger.Debugf("商店列表获取失败") - } - if len(StoreMapLists) == 0 { - /*遍历,绑定*/ - Map := &model.StoreMap{} - Map.VendorStoreID = strconv.Itoa(StoreList.ID) - Map.AutoPickup = 1 - Map.DeliveryCompetition = 1 - Map.PricePercentage = 100 - Map.IsSync = 1 - Map.PricePercentagePack = "京西100-100" - Map.DeliveryFeeDeductionSill = 0 - Map.DeliveryFeeDeductionFee = 0 - Map.IsOrder = 0 - if _, err := AddStoreVendorMap(ctx, db, 9, "", StoreList.ID, Map); err != nil { - globals.SugarLogger.Debugf("AddStoreVendorMap调用出错,StoreID是" + strconv.Itoa(StoreList.ID)) - globals.SugarLogger.Debugf(err.Error()) - } - } - /*改配送范围*/ - //deliverrangetype 3 - //deliverrange 3000 - StoreList.DeliveryRange = "3000" - StoreList.DeliveryRangeType = 3 - StoreList.UpdatedAt = time.Now() - StoreList.LastOperator = ctx.GetUserName() - dao.UpdateEntity(db, StoreList, "DeliveryRange", "DeliveryRangeType", "LastOperator", "UpdatedAt") + /* 果园和菜市的门店ID可能有重复,导致在美团配送上建的门店只有一方的门店是生效的,可以根据ID在美团配送上查,查到是果园的店,那菜市的店则要重新绑定美团配送(要换一个美团配送的门店ID。不然要重复), + 反之也要,可根据其他信息,比如门店名(传到平台上的规则都是一样的),坐标等判断是果园的还是菜市的*/ } } +//func StoreOpenAll(ctx *jxcontext.Context) { +//db := dao.GetDB() +///*获取所有门店信息*/ +//StoreLists, err := dao.GetStoreList(db, nil, nil, []int{}, nil, "") +//if err != nil { +// globals.SugarLogger.Debugf("商店列表获取失败") +//} +///*距离结构体*/ +//type Distance struct { +// StoreID string `json:"门店ID"` +// StoreStatus string `json:"门店状态"` +// StoreName string `json:"门店名"` +// Tel string `json:"电话"` +// City string `json:"城市"` +// Address string `json:"地址"` +// DistanceId string `json:"附近门店ID"` +// DistanceStatus string `json:"附近门店状态"` +// DistanceName string `json:"附近门店名"` +// DistanceAddress string `json:"附近门店地址"` +// DistanceValue string `json:"距离附近门店距离(m)"` +//} +//distanceStore := make(map[int][]Distance) +//var isCloud []string +//var CloudBool bool +//for _, StoreList := range StoreLists { +// /*循环内部声明,1对多*/ +// var a []Distance +// lng := jxutils.IntCoordinate2Standard(StoreList.Lng) +// lat := jxutils.IntCoordinate2Standard(StoreList.Lat) +// for _, StoreList1 := range StoreLists { +// if StoreList1.ID == StoreList.ID { +// continue +// } +// /*把s与提前存好的字段对比,如果相同说明 A+B=B+A的情况,直接跳过*/ +// s := strconv.Itoa(StoreList1.ID) + strconv.Itoa(StoreList.ID) +// for _, x := range isCloud { +// if s == x { +// CloudBool = true +// break +// } +// } +// if CloudBool == true{ +// CloudBool = false +// continue +// } +// lng1 := jxutils.IntCoordinate2Standard(StoreList1.Lng) +// lat1 := jxutils.IntCoordinate2Standard(StoreList1.Lat) +// if jxutils.EarthDistance(lng, lat, lng1, lat1) < 0.5 { +// //门店ID,门店名,电话,城市,地址,附近门店ID,附近门店名,距离附近门店距离(m) +// b := &Distance{ +// strconv.Itoa(StoreList.ID), +// strconv.Itoa(StoreList.Status), +// StoreList.Name, +// StoreList.Tel1, +// strconv.Itoa(StoreList.CityCode), +// StoreList.Address, +// strconv.Itoa(StoreList1.ID), +// strconv.Itoa(StoreList1.Status), +// StoreList1.Name, +// StoreList1.Address, +// fmt.Sprintf("%.2f", jxutils.EarthDistance(lng, lat, lng1, lat1)*1000), +// } +// a = append(a, *b) +// distanceStore[StoreList.ID] = a +// isCloud = append(isCloud, strconv.Itoa(StoreList.ID)+strconv.Itoa(StoreList1.ID)) +// } +// } +//} +// +////DistanceTitle := []string{ +//// "门店ID", +//// "门店名", +//// "电话", +//// "城市", +//// "地址", +//// "附近门店ID", +//// "附近门店名", +//// "距离附近门店距离(m)", +////} +//fmt.Println(len(distanceStore)) +//xlsx := excelize.NewFile() +//index := xlsx.NewSheet("Sheet1") +//xlsx.SetCellValue("Sheet1", "A1", "门店ID") +//xlsx.SetCellValue("Sheet1", "B1", "门店状态") +//xlsx.SetCellValue("Sheet1", "C1", "门店名") +//xlsx.SetCellValue("Sheet1", "D1", "电话") +//xlsx.SetCellValue("Sheet1", "E1", "城市") +//xlsx.SetCellValue("Sheet1", "F1", "地址") +//xlsx.SetCellValue("Sheet1", "G1", "附近门店ID") +//xlsx.SetCellValue("Sheet1", "H1", "附近门店状态") +//xlsx.SetCellValue("Sheet1", "I1", "附近门店名") +//xlsx.SetCellValue("Sheet1", "J1", "附近门店地址") +//xlsx.SetCellValue("Sheet1", "K1", "距离附近门店距离(M)") +//i := 2 +//for _, value := range distanceStore { +// for _, value1 := range value { +// xlsx.SetCellValue("Sheet1", "A"+strconv.Itoa(i), value1.StoreID) +// xlsx.SetCellValue("Sheet1", "B"+strconv.Itoa(i), value1.StoreStatus) +// xlsx.SetCellValue("Sheet1", "C"+strconv.Itoa(i), value1.StoreName) +// xlsx.SetCellValue("Sheet1", "D"+strconv.Itoa(i), value1.Tel) +// xlsx.SetCellValue("Sheet1", "E"+strconv.Itoa(i), value1.City) +// xlsx.SetCellValue("Sheet1", "F"+strconv.Itoa(i), value1.Address) +// xlsx.SetCellValue("Sheet1", "G"+strconv.Itoa(i), value1.DistanceId) +// xlsx.SetCellValue("Sheet1", "H"+strconv.Itoa(i), value1.DistanceStatus) +// xlsx.SetCellValue("Sheet1", "I"+strconv.Itoa(i), value1.DistanceName) +// xlsx.SetCellValue("Sheet1", "J"+strconv.Itoa(i), value1.DistanceAddress) +// xlsx.SetCellValue("Sheet1", "K"+strconv.Itoa(i), value1.DistanceValue) +// i++ +// } +//} +//// Set active sheet of the workbook. +//xlsx.SetActiveSheet(index) +//// Save xlsx file by the given path. +//err = xlsx.SaveAs("C:\\Users\\86159\\Desktop\\WorkForTemp\\距离小于500米门店信息.xlsx") +//if err != nil { +// fmt.Println(err) +//} +//var sheetList []*excel.Obj2ExcelSheetConfig +//sheetName := "附近500米门店信息" +//for _, value := range distanceStore { +// excelConf := &excel.Obj2ExcelSheetConfig{ +// Title: sheetName, +// Data: value, +// CaptionList: DistanceTitle, +// } +// file,err := os.OpenFile("C:\\Users\\86159\\Desktop\\WorkForTemp\\haha.txt",os.O_APPEND|os.O_RDWR,6660) +// if err != nil{ +// fmt.Println(err.Error()) +// } +// file.WriteString(fmt.Sprintln(excelConf.Data)) +// sheetList = append(sheetList, excelConf) +// baseapi.SugarLogger.Debugf("WriteToExcel:append:%s count:%d", sheetName, len(value)) +//} +//if len(sheetList) > 0 { +// excelBin := excel.Obj2Excel(sheetList) +// sheetList = nil +// timeStr := utils.Int64ToStr(time.Now().Unix()) +// diffFullFileName := "附近500米门店信息数据" + timeStr + fileExt +// baseapi.SugarLogger.Debugf("WriteToExcel:save %s success", diffFullFileName) +// //上传 +// downloadURL, err := jxutils.UploadExportContent(excelBin, diffFullFileName) +// if err != nil { +// baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", diffFullFileName, err) +// } else { +// baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL: %s", diffFullFileName, downloadURL) +// /*************发送钉钉消息**************/ +// //ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "", "异步任务完成", "附近500米门店信息数据上传成功:Excel下载地址是 "+downloadURL) +// } +//} else { +// baseapi.SugarLogger.Debug("WriteToExcel:No diff data!!!") +//} +//} + +//}func StoreOpenAll(ctx *jxcontext.Context) { +// db := dao.GetDB() +// StoreLists, err := dao.GetStoreList(db, nil, nil, []int{1}, nil, "") +// if err != nil { +// globals.SugarLogger.Debugf("商店列表获取失败") +// } +// var StoreMapLists []*model.StoreMap +// for _, StoreList := range StoreLists { +// if StoreMapLists, err = dao.GetStoresMapList(db, []int{0, 1, 3}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { +// globals.SugarLogger.Debugf("商店列表获取失败") +// } +// if len(StoreMapLists) > 0 { +// /*将map查询的结果全部放进数组*/ +// for _, StoreMapList := range StoreMapLists { +// /*二元运算符*/ +// StoreMapList.SyncStatus = StoreMapList.SyncStatus | model.SyncFlagModifiedMask +// StoreMapList.UpdatedAt = time.Now() +// StoreMapList.LastOperator = ctx.GetUserName() +// dao.UpdateEntity(db, StoreMapList, "SyncStatus", "UpdatedAt", "LastOperator") +// //} +// /*同步*/ +// if _, err = CurVendorSync.SyncStore(ctx, db, StoreMapList.VendorID, StoreList.ID, false, ctx.GetUserName()); err != nil { +// globals.SugarLogger.Debugf("同步失败") +// } +// } +// } +// if StoreMapLists, err = dao.GetStoresMapList(db, []int{9}, []int{StoreList.ID}, nil, 1, -1, "", ""); err != nil { +// globals.SugarLogger.Debugf("商店列表获取失败") +// } +// if len(StoreMapLists) == 0 { +// /*遍历,绑定*/ +// Map := &model.StoreMap{} +// Map.VendorStoreID = strconv.Itoa(StoreList.ID) +// Map.AutoPickup = 1 +// Map.DeliveryCompetition = 1 +// Map.PricePercentage = 100 +// Map.IsSync = 1 +// Map.PricePercentagePack = "京西100-100" +// Map.DeliveryFeeDeductionSill = 0 +// Map.DeliveryFeeDeductionFee = 0 +// Map.IsOrder = 0 +// if _, err := AddStoreVendorMap(ctx, db, 9, "", StoreList.ID, Map); err != nil { +// globals.SugarLogger.Debugf("AddStoreVendorMap调用出错,StoreID是" + strconv.Itoa(StoreList.ID)) +// globals.SugarLogger.Debugf(err.Error()) +// } +// } +// /*改配送范围*/ +// //deliverrangetype 3 +// //deliverrange 3000 +// StoreList.DeliveryRange = "3000" +// StoreList.DeliveryRangeType = 3 +// StoreList.UpdatedAt = time.Now() +// StoreList.LastOperator = ctx.GetUserName() +// dao.UpdateEntity(db, StoreList, "DeliveryRange", "DeliveryRangeType", "LastOperator", "UpdatedAt") +// } +//} + func TestDiff(ctx *jxcontext.Context, vendorIDList []int, storeIDList []int) { baseapi.SugarLogger.Debugf("CheckSkuDiffBetweenJxAndVendor start time: %v", time.Now()) startProcessTime := time.Now().Unix() From 8ec989aded3a1e5c7d033a6f805bcf9bf6acc77e Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Mon, 29 Jun 2020 09:52:54 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=AF=BC=E9=94=99=E5=8C=85=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 2bef0d039..0495618fa 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "git.rosy.net.cn/baseapi/platformapi/dingdingapi" - "git.rosy.net.cn/cms" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" @@ -641,7 +640,7 @@ func StoreOpenAll(ctx *jxcontext.Context) { sl := make(map[string]interface{}) sl["status"] = 0 sl["vendorStoreID"] = "667222" - cms.UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) + UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) } } } @@ -671,14 +670,14 @@ func StoreOpenAll(ctx *jxcontext.Context) { continue } else { /*平台上但是名字不同,解绑*/ - if _, err := cms.DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { globals.SugarLogger.Debug(err.Error()) return } } } else { /*美团平台上面没找到,解绑*/ - if _, err := cms.DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { globals.SugarLogger.Debug(err.Error()) return } From 04bab113619b351947c37ff9dfd870bce54014f3 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Mon, 29 Jun 2020 14:57:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 100 +++++++++++++++--------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 0495618fa..7246aa0d7 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -589,36 +589,43 @@ func StoreOpenAll(ctx *jxcontext.Context) { } client := &http.Client{} var StoreInfoList []*JdStore - num := 1 - for { - /* cookie还需要修改*/ - /* context.TODO()*/ - cookie := "_lxsdk_cuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "_lxsdk=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "uuid=fa1894be8819a84be4ef.1592458555.1.0.0; wm_order_channel=sjzxpc; " + - "cssVersion=82f258e3; utm_source=60376; au_trace_key_net=default; " + - "openh5_uuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "bmm-uuid=dbdc11bf-fcfe-84a0-0586-97e3d7d23ec7; " + - "token=-MfbU7noKEgDWuNA559DeG6LmYZ51CCiH8bYrH-eYuaugCOqJL7863lKoAWfx8HoydOzJE8r9gGM3QJ0IC3niA; " + - "_lxsdk_s=172fa436aed-861-103-c9b%7C%7C7" - url := "https://peisong.meituan.com/api/haikuiopen/haikui/open/partner/poi/search?pageSize=20&pageNum=" + strconv.Itoa(num) + "" - req, _ := http.NewRequest("POST", url, nil) - req.Header.Set("Cookie", cookie) - req.Header.Set("Referer", "https://peisong.meituan.com/open/admin/accountList") - res, _ := client.Do(req) - defer res.Body.Close() - if res.Body != nil { - StoreInfo := &JdStore{} - body, _ := ioutil.ReadAll(res.Body) - json.Unmarshal(body, StoreInfo) - StoreInfoList = append(StoreInfoList, StoreInfo) - if StoreInfo.Data1.DataList == nil { - break + complate := make(chan bool, 1) + cookie := "_lxsdk_cuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "_lxsdk=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "uuid=fa1894be8819a84be4ef.1592458555.1.0.0; wm_order_channel=sjzxpc; " + + "cssVersion=82f258e3; utm_source=60376; au_trace_key_net=default; " + + "openh5_uuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + "bmm-uuid=dbdc11bf-fcfe-84a0-0586-97e3d7d23ec7; " + + "token=-MfbU7noKEgDWuNA559DeG6LmYZ51CCiH8bYrH-eYuaugCOqJL7863lKoAWfx8HoydOzJE8r9gGM3QJ0IC3niA; " + + "_lxsdk_s=172fa436aed-861-103-c9b%7C%7C7" + go func() { + num := 1 + for { + /* cookie还需要修改*/ + /* context.TODO()*/ + url := "https://peisong.meituan.com/api/haikuiopen/haikui/open/partner/poi/search?pageSize=20&pageNum=" + strconv.Itoa(num) + "" + req, _ := http.NewRequest("POST", url, nil) + req.Header.Set("Cookie", cookie) + req.Header.Set("Referer", "https://peisong.meituan.com/open/admin/accountList") + res, _ := client.Do(req) + //defer res.Body.Close() + if res.Body != nil { + StoreInfo := &JdStore{} + body, _ := ioutil.ReadAll(res.Body) + json.Unmarshal(body, StoreInfo) + if len(StoreInfo.Data1.DataList) == 0 || StoreInfo.Data1.DataList == nil { + complate <- true + } + StoreInfoList = append(StoreInfoList, StoreInfo) + num++ + } else { + complate <- true } - num++ - } else { - break } + }() + select { + case <-complate: + break } /*StoreInfoList1 map[11691658]=1*/ StoreInfoList1 := make(map[string]int) @@ -631,15 +638,21 @@ func StoreOpenAll(ctx *jxcontext.Context) { fmt.Println(StoreInfoList)*/ db := dao.GetDB() /*比较营业状态*/ - StoreCourierList, err := dao.GetStoreCourierList(db, []int{0}, -9, -9) + StoreCourierList, err := dao.GetStoreCourierList(db, []int{}, -9, -9) for _, StoreCourierList1 := range StoreCourierList { + /*如果京西店在美团上没有,那下面有专门方法处理*/ if _, ok := StoreInfoList1[StoreCourierList1.VendorStoreID]; ok { - /*营业状态是没有营业的,但是京西却关联美团了*/ - if StoreInfoList1[StoreCourierList1.VendorStoreID] == 0 { - //调用方法解绑 {"status":0,"vendorStoreID":"667222"} + /*京西配送状态为配送,美团营业状态是没有营业的*/ + if StoreCourierList1.Status == 1 && StoreInfoList1[StoreCourierList1.VendorStoreID] == 0 { sl := make(map[string]interface{}) sl["status"] = 0 - sl["vendorStoreID"] = "667222" + sl["vendorStoreID"] = StoreCourierList1.VendorStoreID + UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) + /*京西配送状态为不配送,美团营业状态是营业的*/ + } else if StoreCourierList1.Status != 1 && StoreInfoList1[StoreCourierList1.VendorStoreID] == 1 { + sl := make(map[string]interface{}) + sl["status"] = 1 + sl["vendorStoreID"] = StoreCourierList1.VendorStoreID UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) } } @@ -660,23 +673,38 @@ func StoreOpenAll(ctx *jxcontext.Context) { if StoreCourierList1.VendorID != 102 { continue } + if StoreCourierList1.Status == -2 { + continue + } /*京西不为空*/ if StoreCourierList1.VendorStoreID != "" { /*调用API获取美团的商店信息*/ MTPSInfo, _ := api.MtpsAPI.ShopQuery(StoreCourierList1.VendorStoreID) - if MTPSInfo.ShopID != "" { + /*京西有,美团没有*/ + if MTPSInfo == nil { + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + continue + } + /*美团上商店名不为空,容错*/ + if MTPSInfo.ShopName != "" { if MTPSInfo.ShopName == StoreList.Name { - /*平台上有且名字相同*/ + /*平台上有且名字相同不做处理*/ continue } else { /*平台上但是名字不同,解绑*/ + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { globals.SugarLogger.Debug(err.Error()) return } } - } else { + } else { //容错 /*美团平台上面没找到,解绑*/ + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { globals.SugarLogger.Debug(err.Error()) return From a6c7c1e7dddd4eadbec042a012ae241dffc2a3a9 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Tue, 30 Jun 2020 08:39:41 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BE=8E=E5=9B=A2?= =?UTF-8?q?=E9=85=8D=E9=80=81=E5=90=8C=E6=AD=A5=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku_check.go | 147 ++++++++++++------------ business/jxstore/cms/sync.go | 100 ++++++++++++++++ business/jxstore/misc/misc.go | 2 + 3 files changed, 178 insertions(+), 71 deletions(-) diff --git a/business/jxstore/cms/store_sku_check.go b/business/jxstore/cms/store_sku_check.go index 7246aa0d7..ad492db2c 100644 --- a/business/jxstore/cms/store_sku_check.go +++ b/business/jxstore/cms/store_sku_check.go @@ -1,14 +1,11 @@ package cms import ( - "encoding/json" "fmt" "git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" - "io/ioutil" - "net/http" "strconv" "strings" "sync" @@ -572,66 +569,73 @@ func StoreOpenAll(ctx *jxcontext.Context) { /* 美团配送的门店营业状态,如果是休息,则京西这边不发单,如果是营业,京西这边状态就是发单 美团配送的门店营业状态要通过网页扒取(应该是接了的代码里要找一下)*/ /*获取门店信息*/ - type DataList struct { - OuterPoiId string `json:"outerPoiId"` //店ID - PoiName string `json:"poiName"` //店名 - OpenType int `json:"openType"` //营业状态 1是营业 0是休息 - } - type jdData struct { - PageNum int `json:"pageNum"` - PageSize int `json:"pageSize"` - DataList []DataList `json:"dataList"` - } - type JdStore struct { - Code int `json:"code"` - Msg string `json:"msg"` - Data1 jdData `json:"data"` - } - client := &http.Client{} - var StoreInfoList []*JdStore - complate := make(chan bool, 1) - cookie := "_lxsdk_cuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "_lxsdk=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "uuid=fa1894be8819a84be4ef.1592458555.1.0.0; wm_order_channel=sjzxpc; " + - "cssVersion=82f258e3; utm_source=60376; au_trace_key_net=default; " + - "openh5_uuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + - "bmm-uuid=dbdc11bf-fcfe-84a0-0586-97e3d7d23ec7; " + - "token=-MfbU7noKEgDWuNA559DeG6LmYZ51CCiH8bYrH-eYuaugCOqJL7863lKoAWfx8HoydOzJE8r9gGM3QJ0IC3niA; " + - "_lxsdk_s=172fa436aed-861-103-c9b%7C%7C7" - go func() { - num := 1 - for { - /* cookie还需要修改*/ - /* context.TODO()*/ - url := "https://peisong.meituan.com/api/haikuiopen/haikui/open/partner/poi/search?pageSize=20&pageNum=" + strconv.Itoa(num) + "" - req, _ := http.NewRequest("POST", url, nil) - req.Header.Set("Cookie", cookie) - req.Header.Set("Referer", "https://peisong.meituan.com/open/admin/accountList") - res, _ := client.Do(req) - //defer res.Body.Close() - if res.Body != nil { - StoreInfo := &JdStore{} - body, _ := ioutil.ReadAll(res.Body) - json.Unmarshal(body, StoreInfo) - if len(StoreInfo.Data1.DataList) == 0 || StoreInfo.Data1.DataList == nil { - complate <- true - } - StoreInfoList = append(StoreInfoList, StoreInfo) - num++ - } else { - complate <- true - } - } - }() - select { - case <-complate: - break - } - /*StoreInfoList1 map[11691658]=1*/ + //type DataList struct { + // OuterPoiId string `json:"outerPoiId"` //店ID + // PoiName string `json:"poiName"` //店名 + // OpenType int `json:"openType"` //营业状态 1是营业 0是休息 + //} + //type jdData struct { + // PageNum int `json:"pageNum"` + // PageSize int `json:"pageSize"` + // DataList []DataList `json:"dataList"` + //} + //type JdStore struct { + // Code int `json:"code"` + // Msg string `json:"msg"` + // Data1 jdData `json:"data"` + //} + //client := &http.Client{} + //var StoreInfoList []*JdStore + //complate := make(chan bool, 1) + //cookie := "_lxsdk_cuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + // "_lxsdk=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + // "uuid=fa1894be8819a84be4ef.1592458555.1.0.0; wm_order_channel=sjzxpc; " + + // "cssVersion=82f258e3; utm_source=60376; au_trace_key_net=default; " + + // "openh5_uuid=172c5ed322ac8-081f1f7ebdcbeb-f7d1d38-149c48-172c5ed322ac8; " + + // "bmm-uuid=dbdc11bf-fcfe-84a0-0586-97e3d7d23ec7; " + + // "token=-MfbU7noKEgDWuNA559DeG6LmYZ51CCiH8bYrH-eYuaugCOqJL7863lKoAWfx8HoydOzJE8r9gGM3QJ0IC3niA; " + + // "_lxsdk_s=172fa436aed-861-103-c9b%7C%7C7" + //go func() { + // num := 1 + // for { + // /* cookie还需要修改*/ + // /* context.TODO()*/ + // url := "https://peisong.meituan.com/api/haikuiopen/haikui/open/partner/poi/search?pageSize=20&pageNum=" + strconv.Itoa(num) + "" + // req, _ := http.NewRequest("POST", url, nil) + // req.Header.Set("Cookie", cookie) + // req.Header.Set("Referer", "https://peisong.meituan.com/open/admin/accountList") + // res, _ := client.Do(req) + // //defer res.Body.Close() + // if res.Body != nil { + // StoreInfo := &JdStore{} + // body, _ := ioutil.ReadAll(res.Body) + // json.Unmarshal(body, StoreInfo) + // if len(StoreInfo.Data1.DataList) == 0 || StoreInfo.Data1.DataList == nil { + // complate <- true + // } + // StoreInfoList = append(StoreInfoList, StoreInfo) + // num++ + // } else { + // complate <- true + // } + // } + //}() + //select { + //case <-complate: + // break + //} + ///*StoreInfoList1 map[11691658]=1*/ + //StoreInfoList1 := make(map[string]int) + //for _, store := range StoreInfoList { + // for _, data := range store.Data1.DataList { + // StoreInfoList1[data.OuterPoiId] = data.OpenType + // } + //} + StoreInfoList, err := api.MtpsAPI.GetStoreStatusAll() StoreInfoList1 := make(map[string]int) for _, store := range StoreInfoList { - for _, data := range store.Data1.DataList { - StoreInfoList1[data.OuterPoiId] = data.OpenType + for _, data := range store.DataList { + StoreInfoList1[data.OuterPoiID] = data.OpenType } } /* fmt.Println(num) @@ -665,15 +669,15 @@ func StoreOpenAll(ctx *jxcontext.Context) { globals.SugarLogger.Debug(err.Error()) } for _, StoreList := range StoreLists { - StoreCourierList, err := dao.GetStoreCourierList(db, []int{StoreList.ID}, -9, -9) + StoreCourierList, err := dao.GetStoreCourierList(db, []int{StoreList.ID}, model.StoreStatusAll, model.StoreStatusAll) if err != nil { globals.SugarLogger.Debug(err.Error()) } for _, StoreCourierList1 := range StoreCourierList { - if StoreCourierList1.VendorID != 102 { + if StoreCourierList1.VendorID != model.VendorIDMTPS { continue } - if StoreCourierList1.Status == -2 { + if StoreCourierList1.Status == model.StoreStatusDisabled { continue } /*京西不为空*/ @@ -689,13 +693,16 @@ func StoreOpenAll(ctx *jxcontext.Context) { } continue } - /*美团上商店名不为空,容错*/ - if MTPSInfo.ShopName != "" { - if MTPSInfo.ShopName == StoreList.Name { - /*平台上有且名字相同不做处理*/ + /* 果园和菜市的门店ID可能有重复,导致在美团配送上建的门店只有一方的门店是生效的,可以根据ID在美团配送上查,查到是果园的店,那菜市的店则要重新绑定美团配送(要换一个美团配送的门店ID。不然要重复), + 反之也要,可根据其他信息,比如门店名(传到平台上的规则都是一样的),坐标等判断是果园的还是菜市的*/ + + /*美团上坐标不为空,容错 PS:用名字的话,本身就没办法判断是菜市还是果园*/ + if MTPSInfo.ShopLng != 0 && MTPSInfo.ShopLat != 0 { + if MTPSInfo.ShopLng == StoreList.Lng && MTPSInfo.ShopLat == StoreList.Lat { + /*平台上有且坐标相同不做处理*/ continue } else { - /*平台上但是名字不同,解绑*/ + /*平台上但是坐标不同,解绑*/ fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { globals.SugarLogger.Debug(err.Error()) @@ -716,8 +723,6 @@ func StoreOpenAll(ctx *jxcontext.Context) { } } } - /* 果园和菜市的门店ID可能有重复,导致在美团配送上建的门店只有一方的门店是生效的,可以根据ID在美团配送上查,查到是果园的店,那菜市的店则要重新绑定美团配送(要换一个美团配送的门店ID。不然要重复), - 反之也要,可根据其他信息,比如门店名(传到平台上的规则都是一样的),坐标等判断是果园的还是菜市的*/ } } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index d3069e6d9..8314af25d 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,6 +3,7 @@ package cms import ( "errors" "fmt" + "strconv" "sync" "time" @@ -1250,3 +1251,102 @@ func SyncSkuExperfixAndWatermark(ctx *jxcontext.Context) (err error) { _, err = task.GetResult(0) return err } + +func SetMTPSStatus(ctx *jxcontext.Context) { + /* 美团配送的门店营业状态,如果是休息,则京西这边不发单,如果是营业,京西这边状态就是发单 + 美团配送的门店营业状态要通过网页扒取(应该是接了的代码里要找一下)*/ + /*获取门店信息*/ + StoreInfoList, err := api.MtpsAPI.GetStoreStatusAll() + StoreInfoList1 := make(map[string]int) + for _, store := range StoreInfoList { + for _, data := range store.DataList { + StoreInfoList1[data.OuterPoiID] = data.OpenType + } + } + /* fmt.Println(num) + fmt.Println(StoreInfoList)*/ + db := dao.GetDB() + /*比较营业状态*/ + StoreCourierList, err := dao.GetStoreCourierList(db, []int{}, -9, -9) + for _, StoreCourierList1 := range StoreCourierList { + /*如果京西店在美团上没有,那下面有专门方法处理*/ + if _, ok := StoreInfoList1[StoreCourierList1.VendorStoreID]; ok { + /*京西配送状态为配送,美团营业状态是没有营业的*/ + if StoreCourierList1.Status == 1 && StoreInfoList1[StoreCourierList1.VendorStoreID] == 0 { + sl := make(map[string]interface{}) + sl["status"] = 0 + sl["vendorStoreID"] = StoreCourierList1.VendorStoreID + UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) + /*京西配送状态为不配送,美团营业状态是营业的*/ + } else if StoreCourierList1.Status != 1 && StoreInfoList1[StoreCourierList1.VendorStoreID] == 1 { + sl := make(map[string]interface{}) + sl["status"] = 1 + sl["vendorStoreID"] = StoreCourierList1.VendorStoreID + UpdateStoreCourierMap(ctx, nil, StoreCourierList1.StoreID, StoreCourierList1.VendorID, sl, ctx.GetUserName()) + } + } + } + /* 美团配送的门店是否存在,调用美团配送的api(有可能接了),查询京西门店对应的美团配送门店是否存在,若不存在则要在京西这边解绑美团配送门店 + 怎么解绑可以在网页上门店管理那点一下看看调的什么接口,传的什么参数*/ + /*获取所有门店信息*/ + StoreLists, err := dao.GetStoreList(db, nil, nil, []int{}, nil, "") + if err != nil { + globals.SugarLogger.Debug(err.Error()) + } + for _, StoreList := range StoreLists { + StoreCourierList, err := dao.GetStoreCourierList(db, []int{StoreList.ID}, model.StoreStatusAll, model.StoreStatusAll) + if err != nil { + globals.SugarLogger.Debug(err.Error()) + } + for _, StoreCourierList1 := range StoreCourierList { + if StoreCourierList1.VendorID != model.VendorIDMTPS { + continue + } + if StoreCourierList1.Status == model.StoreStatusDisabled { + continue + } + /*京西不为空*/ + if StoreCourierList1.VendorStoreID != "" { + /*调用API获取美团的商店信息*/ + MTPSInfo, _ := api.MtpsAPI.ShopQuery(StoreCourierList1.VendorStoreID) + /*京西有,美团没有*/ + if MTPSInfo == nil { + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + continue + } + /* 果园和菜市的门店ID可能有重复,导致在美团配送上建的门店只有一方的门店是生效的,可以根据ID在美团配送上查,查到是果园的店,那菜市的店则要重新绑定美团配送(要换一个美团配送的门店ID。不然要重复), + 反之也要,可根据其他信息,比如门店名(传到平台上的规则都是一样的),坐标等判断是果园的还是菜市的*/ + + /*美团上坐标不为空,容错 PS:用名字的话,本身就没办法判断是菜市还是果园*/ + if MTPSInfo.ShopLng != 0 && MTPSInfo.ShopLat != 0 { + if MTPSInfo.ShopLng == StoreList.Lng && MTPSInfo.ShopLat == StoreList.Lat { + /*平台上有且坐标相同不做处理*/ + continue + } else { + /*平台上但是坐标不同,解绑*/ + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + } + } else { //容错 + /*美团平台上面没找到,解绑*/ + fmt.Println(strconv.Itoa(StoreCourierList1.StoreID) + " 被解绑") + if _, err := DeleteStoreCourierMap(ctx, db, StoreCourierList1.StoreID, StoreCourierList1.VendorID, ctx.GetUserName()); err != nil { + globals.SugarLogger.Debug(err.Error()) + return + } + //} else { + // 美团平台上有,京西没得,调用方法可能需要做一些修改 + // context.TODO() + //} + } + } + } + } +} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 2f84dd366..d8e9ea0c5 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -422,6 +422,8 @@ func doDailyWork() { orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, time.Now().AddDate(0, 0, -3).Format("20060102"), time.Now().Format("20060102")) //同步上架京东商城待售商品 cms.RefreshJdsSkusStatus(jxcontext.AdminCtx) + //同步美团配送与否状态及美团门店是否存在 + cms.SetMTPSStatus(jxcontext.AdminCtx) } func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {