Bläddra i källkod

上传商品到第三方渠道

rambo 3 månader sedan
förälder
incheckning
6d52a6c06a
3 ändrade filer med 80 tillägg och 19 borttagningar
  1. 17 16
      python/api.py
  2. 35 0
      python/docs/socket命令.md
  3. 28 3
      python/service/online_request/module_online_data.py

+ 17 - 16
python/api.py

@@ -469,22 +469,23 @@ async def handle_detail(request: Request, params: HandlerDetail):
                             }
                         )
                 else:
-                    result_goods_no_dict = return_data_check_before_detail["data"][
-                        "goods_no_dict"
-                    ]
-                    for goods_idx,goods_no_dict in enumerate(result_goods_no_dict.keys()):
-                        all_detail_path_list = config_data["all_detail_path_list"]
-                        for detail_path in all_detail_path_list:
-                            if goods_no_dict in detail_path:
-                                detail_path_replace = detail_path.replace(
-                                    "\\", "/"
-                                )
-                                result_goods_no_dict[goods_no_dict][
-                                    "detail_path"
-                                ] = f"{detail_path_replace}/拼接图/1.jpg"
-                    onlineData.uploadGoods2ThirdParty(
-                        result_goods_no_dict, online_stores=online_stores
-                    )
+                    if len(online_stores) >0:
+                        result_goods_no_dict = return_data_check_before_detail["data"][
+                            "goods_no_dict"
+                        ]
+                        for goods_idx,goods_no_dict in enumerate(result_goods_no_dict.keys()):
+                            all_detail_path_list = config_data["all_detail_path_list"]
+                            for detail_path in all_detail_path_list:
+                                if goods_no_dict in detail_path:
+                                    detail_path_replace = detail_path.replace(
+                                        "\\", "/"
+                                    )
+                                    result_goods_no_dict[goods_no_dict][
+                                        "detail_path"
+                                    ] = f"{detail_path_replace}/详情页.jpg"
+                        onlineData.uploadGoods2ThirdParty(
+                            result_goods_no_dict, online_stores=online_stores
+                        )
                     handler_result = config_data["success_handler"]
         else:
             handler_result.append(

+ 35 - 0
python/docs/socket命令.md

@@ -1011,6 +1011,41 @@ _(该命令用于单独自定义配置中某一项的单独调整测试,不进
     "msg_type": "detail_progress"
 }
 ```
+##### 获取详情图处理接口中的<mark>[上传商品到第三方]</mark>执行进度信息
+* data:{}
+    * status:状态
+    * online_stores:上传商品到第三方得渠道名称,数组形式
+* msg_type:详情图处理固定为[upload_goods_progress]
+<mark>以下为消息发送得示例</mark>
+
+```
+{
+    "code": 0,
+    "msg": "开始上传商品数据",
+    "data": {
+        "status": "进行中",
+        "online_stores": [
+            "拼多多",
+            "天猫"
+        ]
+    },
+    "msg_type": "upload_goods_progress"
+}
+```
+```
+{
+    "code": 0,
+    "msg": "商品上传第三方成功",
+    "data": {
+        "status": "已完成",
+        "online_stores": [
+            "拼多多",
+            "天猫"
+        ]
+    },
+    "msg_type": "upload_goods_progress"
+}
+```
 ##### 发送独立抠图命令任务
 * data:{}
     * token:用户token信息

+ 28 - 3
python/service/online_request/module_online_data.py

@@ -1,9 +1,9 @@
 import base64
 import requests
 import settings
-import json
+import json, asyncio
 import numpy as np
-
+from utils.common import message_queue
 
 class JsonEncoder(json.JSONEncoder):
     """Convert numpy classes to JSON serializable objects."""
@@ -331,8 +331,26 @@ class OnlineDataRequest(object):
         print("上传商品api==>resultData", resultData)
         return resultData
 
-    def uploadGoods2ThirdParty(self, goods_no_dict=None,online_stores=[]):
+    def sendSocketMessage(self, code=0, msg="", data=None, device_status=2):
+        data = {
+            "code": code,
+            "msg": msg,
+            "status": device_status,
+            "data": data,
+            "msg_type": self.msg_type,
+        }
+        loop = asyncio.get_event_loop()
+        loop.create_task(message_queue.put(data))
+
+    def uploadGoods2ThirdParty(self, goods_no_dict=None, online_stores=[]):
         params = []
+        message_type = "upload_goods_progress"
+        self.sendSocketMessage(
+            code=0,
+            msg="开始上传商品数据",
+            data={"online_stores": online_stores, "status": "进行中"},
+            message_type=message_type,
+        )
         if goods_no_dict == None:
             return
         for goods_no in goods_no_dict.keys():
@@ -428,6 +446,13 @@ class OnlineDataRequest(object):
         encoded = base64.b64encode(json_params.encode("utf-8")).decode("utf-8")
         self.upload_goods_api({"bizcontent": encoded, "online_stores": online_stores})
         print("商品上传第三方成功")
+        self.sendSocketMessage(
+            code=0,
+            msg="商品上传第三方成功",
+            data={"online_stores": online_stores, "status": "已完成"},
+            message_type=message_type,
+        )
+
 
 class GetOnlineDataHLM(OnlineDataRequest):