From 04bab113619b351947c37ff9dfd870bce54014f3 Mon Sep 17 00:00:00 2001 From: qidongsheng Date: Mon, 29 Jun 2020 14:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95=E8=B0=83?= =?UTF-8?q?=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