Selaa lähdekoodia

详情页生成问题

rambo 4 kuukautta sitten
vanhempi
commit
d59f9a839f

+ 54 - 22
python/api.py

@@ -146,7 +146,7 @@ def fromExcelHandler(params: HandlerDetail):
             raise UnicornException("没有可用货号数据")
         # 货号目录不存在再去进行移动和创建操作
         if move_folder_array.get(goods_art_no) == None:
-            image_dir = "{}/data/{}".format(os.getcwd(), goods_art_no).replace(
+            image_dir = "{}/data/".format(os.getcwd()).replace(
                 "\\", "/"
             )
             check_path(image_dir)
@@ -235,18 +235,34 @@ def fromExcelHandler(params: HandlerDetail):
                         token=token,
                     )
                     upload_pic.run()
-            out_put_dir = config_data["out_put_dir"]
-            out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
-                "\\", "/"
-            )
-            handler_result_folder = os.path.dirname(out_put_dir_path)
-            if len(config_data["success_handler"])==0:
-                for good_art in goods_art_no_arrays:
-                    handler_result.append(
-                        {"goods_art_no": good_art, "success": False, "info": "处理失败"}
-                    )
+            out_put_dir = config_data.get("out_put_dir")
+            out_put_dir = config_data.get("out_put_dir")
+            if out_put_dir == None:
+                handler_result_folder = ""
+                if len(config_data["success_handler"]) > 0:
+                    for good_art in config_data["success_handler"]:
+                        handler_result.append(good_art)
+                else:
+                    for good_art in goods_art_no_arrays:
+                        handler_result.append(
+                            {
+                                "goods_art_no": good_art,
+                                "success": False,
+                                "info": "处理失败",
+                            }
+                        )
             else:
-                handler_result = config_data["success_handler"]
+                out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
+                    "\\", "/"
+                )
+                handler_result_folder = os.path.dirname(out_put_dir_path)
+                if len(config_data["success_handler"])==0:
+                    for good_art in goods_art_no_arrays:
+                        handler_result.append(
+                            {"goods_art_no": good_art, "success": False, "info": "处理失败"}
+                        )
+                else:
+                    handler_result = config_data["success_handler"]
         else:
             for good_art in goods_art_no_arrays:
                 handler_result.append(
@@ -429,20 +445,36 @@ async def handle_detail(request: Request, params: HandlerDetail):
             #         )
             #         upload_pic.run()
             out_put_dir = config_data.get("out_put_dir")
-            if out_put_dir:
+            if out_put_dir == None:
+                handler_result_folder = ""
+                if len(config_data["success_handler"]) > 0:
+                    for good_art in config_data["success_handler"]:
+                        handler_result.append(good_art)
+                else:
+                    for good_art in goods_art_no_arrays:
+                        handler_result.append(
+                            {
+                                "goods_art_no": good_art,
+                                "success": False,
+                                "info": "处理失败",
+                            }
+                        )
+            else:
                 out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
                     "\\", "/"
                 )
                 handler_result_folder = os.path.dirname(out_put_dir_path)
-            else:
-                handler_result_folder = ""
-            if len(config_data["success_handler"]) == 0:
-                for good_art in goods_art_no_arrays:
-                    handler_result.append(
-                        {"goods_art_no": good_art, "success": False, "info": "处理失败"}
-                    )
-            else:
-                handler_result = config_data["success_handler"]
+                if len(config_data["success_handler"]) == 0:
+                    for good_art in goods_art_no_arrays:
+                        handler_result.append(
+                            {
+                                "goods_art_no": good_art,
+                                "success": False,
+                                "info": "处理失败",
+                            }
+                        )
+                else:
+                    handler_result = config_data["success_handler"]
         else:
             handler_result.append(
                 {"goods_art_no": "", "success": False, "info": "处理失败"}

+ 357 - 0
python/custom_plugins/plugins/detail_template/qingyangyizhan/detail_qingyangyizhan1.py

@@ -0,0 +1,357 @@
+"""
+步骤:
+1、整理需要处理的款号图-输出款号图文件夹
+2、整理所有相关的图片作为素材图
+3、按要求进行拼接
+"""
+
+from ast import mod
+import os
+import settings
+
+from PIL import ImageFont
+
+# from module.view_control.generate_goods_no_detail_pic.detail_generate_base import DetailBase
+# from module.view_control.generate_goods_no_detail_pic.pic_deal import PictureProcessing
+is_test_plugins = False
+try:
+    is_test_plugins = settings.is_test_plugins
+except:
+    is_test_plugins = False
+
+if is_test_plugins:
+    from custom_plugins.plugins_mode.detail_generate_base import DetailBase
+    from custom_plugins.plugins_mode.pic_deal import PictureProcessing
+else:
+    from plugins_mode.detail_generate_base import DetailBase
+    from plugins_mode.pic_deal import PictureProcessing
+
+plugins_name = "详情模板"
+company_name_list = ["轻氧驿站"]
+template_name = "qingyangyizhan-1"
+# "俯视", "侧视", "后跟", "鞋底", "内里" 组合,组合2
+
+class DetailPicGet(DetailBase):
+    need_view = ["俯视", "侧视", "后跟", "鞋底", "内里","组合","组合2"]
+    root = r"{}\resources\detail_temp\qingyangyizhan\1".format(os.getcwd())
+
+    def __init__(
+        self,
+        goods_no,
+        goods_no_value: dict,
+        out_put_dir,
+        windows=None,
+        test=False,
+        excel_data=None,
+        assigned_page_list=None,
+    ):
+        super().__init__(
+            goods_no,
+            goods_no_value,
+            out_put_dir,
+            windows=windows,
+            excel_data=excel_data,
+            assigned_page_list=assigned_page_list,
+        )
+        self.template_name = template_name
+
+        self.root = r"{}\resources\detail_temp\qingyangyizhan\1".format(os.getcwd())
+        print("run qingyangyizhan-1 ")
+        self.base_bg_color = (255, 255, 255)
+        self.base_bg_color_2 = (244, 242, 243)
+        self.deal_pic_func_list = [
+            self.deal_pic_1,
+            self.deal_pic_2,
+            self.deal_pic_3,
+            self.deal_pic_4,
+            self.deal_pic_5,
+            self.deal_pic_6,
+            self.deal_pic_7,
+            self.deal_pic_8,
+            self.deal_pic_9,
+        ]
+
+        if test:
+            # pp = self.generate_font_list_to_pic()
+            # pp.im.save(r"C:\Users\gymmc\Desktop\细节图示例/字号.png")
+            # for k, v in self.goods_no_value.items():
+            #     print(k, v)
+            self.run_test()
+        else:
+            self.run_all()
+
+    def run_test(self):
+        detailed_images = []
+        detailed_images.append(self.deal_pic_1())
+        detailed_images.append(self.deal_pic_2())
+        detailed_images.append(self.deal_pic_3())
+        detailed_images.append(self.deal_pic_4())
+        detailed_images.append(self.deal_pic_5())
+        detailed_images.append(self.deal_pic_6())
+        detailed_images.append(self.deal_pic_7())
+        detailed_images.append(self.deal_pic_8())
+        detailed_images.append(self.deal_pic_9())
+
+        img = self.add_pic(detailed_images)
+        img.save(r"{}/{}.jpg".format(self.out_put_dir, self.goods_no, format="JPEG"))
+        img.show()
+
+    # 标题文字展示
+    def deal_pic_1(self):
+        detailed_images = []
+        top_bg = PictureProcessing(r"{}\1.jpg".format(self.root),1600)
+        detailed_images.append(top_bg)
+        pp_bg = PictureProcessing(r"{}\2.jpg".format(self.root),1600)
+        font_main = ImageFont.truetype(r"resources\ttf\puhui\Medium.ttf", 80)  # 设计理念
+        mainTitle = self.get_text_value("主标题")
+        subTitle = self.get_text_value("副标题")
+        describe = self.get_text_value("描述")
+        main_title_text_bg = PictureProcessing("RGBA", (pp_bg.width, 200), (255, 255, 255, 0))
+        main_title_text_bg = main_title_text_bg.get_text_image_advanced(
+            value=(0, 0),
+            font=font_main,
+            text=mainTitle,
+            align="center",
+            spacing=5,
+            fill=(0, 0, 0),
+            return_mode="min_image",
+        )
+        pp_bg = pp_bg.paste_img(top_img=main_title_text_bg, base="nc", value=(0, 242))
+        font_sub = ImageFont.truetype(
+            r"resources\ttf\puhui\Regular.ttf", 30
+        )  # 设计理念
+        sub_title_text_bg = PictureProcessing(
+            "RGBA", (pp_bg.width, 200), (255, 255, 255, 0)
+        )
+        sub_title_text_bg = sub_title_text_bg.get_text_image_advanced(
+            value=(0, 0),
+            font=font_sub,
+            text=subTitle,
+            align="center",
+            spacing=5,
+            fill=(45, 50, 56),
+            return_mode="min_image",
+        )
+        pp_bg = pp_bg.paste_img(top_img=sub_title_text_bg, base="nc", value=(0, 337))
+        # 描述
+        font_sub = ImageFont.truetype(
+            r"resources\ttf\puhui\Regular.ttf", 24
+        )  # 设计理念
+        desc_title_text_bg = PictureProcessing(
+            "RGBA", (pp_bg.width, 200), (255, 255, 255, 0)
+        )
+        desc_title_text_bg = desc_title_text_bg.get_text_image_advanced(
+            value=(0, 0),
+            font=font_sub,
+            text=describe,
+            align="center",
+            spacing=5,
+            fill=(45, 50, 56),
+            return_mode="min_image",
+        )
+        pp_bg = pp_bg.paste_img(top_img=desc_title_text_bg, base="nc", value=(0, 389))
+        goods_art_no_list = list(self.data.keys())
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="后跟",
+        )
+        # pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.rotate(doge=-8)
+        pp_bg = pp_bg.paste_img(top_img=pp_png_1, base="nc", value=(0, 532))
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 展示鞋头和后跟
+    def deal_pic_2(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\3.jpg".format(self.root), 1600)
+        goods_art_no_list = list(self.data.keys())
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="侧视",
+        )
+        # pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.crop(mode="min")
+        pp_png_1 = pp_png_1.resize(value=210)
+        pp_png_1 = pp_png_1.rotate(doge=-8)
+        pp_bg = pp_bg.paste_img(top_img=pp_png_1, base="sw", value=(96, 226))
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 展示鞋头放大图
+    def deal_pic_3(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\4.jpg".format(self.root), 1600)
+        goods_art_no_list = list(self.data.keys())
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="鞋底",
+        )
+        # pp_jpg_1 = pp_jpg_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.rotate(doge=-8)
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=pp_png_1,
+            base="nc",
+            value=(0, 338),
+        )
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 展示后跟放大图
+    def deal_pic_4(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\5.jpg".format(self.root))
+        goods_art_no_list = list(self.data.keys())
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="侧视",
+        )
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width/1.3)
+        # pp_png_1 = pp_png_1.rotate(doge=-8)
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=pp_png_1,
+            base="nc",
+            value=(0, 190),
+        )
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 展示后跟细节卡片
+    def deal_pic_5(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\6.jpg".format(self.root))
+        circle = PictureProcessing(r"{}\circle.png".format(self.root))
+        goods_art_no_list = list(self.data.keys())
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="组合",
+        )
+        pp_png_1 = pp_png_1.crop(mode="min")
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width - 50)
+        desc_title_text_bg = PictureProcessing(
+            "RGBA", (pp_bg.width, pp_png_1.height + 150), (255, 255, 255, 0)
+        )
+        desc_title_text_bg = desc_title_text_bg.paste_img(
+            mode="pixel",
+            top_img=pp_png_1,
+            base="cc",
+            value=(0, 0),
+        )
+        desc_title_text_bg = desc_title_text_bg.rotate(doge=115)
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=desc_title_text_bg,
+            base="cs",
+            value=(0, 90),
+        )
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=circle,
+            base="en",
+            value=(30, 380),
+        )
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # "心动"设计亮点,展示旋转的侧视图
+    def deal_pic_6(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\7.jpg".format(self.root))
+        pp_bg_8 = PictureProcessing(r"{}\8.jpg".format(self.root))
+        goods_art_no_list = list(self.data.keys())
+        goods_art = goods_art_no_list[0]
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art,
+            name="侧视",
+        )
+        pp_png_1 = pp_png_1.crop(mode="min")
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width-100)
+        desc_title_text_bg = PictureProcessing(
+            "RGBA", (pp_bg.width, pp_png_1.height + 200), (255, 255, 255, 0)
+        )
+        desc_title_text_bg = desc_title_text_bg.paste_img(
+            mode="pixel",
+            top_img=pp_png_1,
+            base="cc",
+            value=(0, 0),
+        )
+        desc_title_text_bg = desc_title_text_bg.rotate(doge=150)
+        desc_title_text_bg = desc_title_text_bg.crop(mode="min")
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=desc_title_text_bg,
+            base="cs",
+            value=(0, 200),
+        )
+        detailed_images.append(pp_bg)
+        detailed_images.append(pp_bg_8)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 产品展示,帮面等等
+    def deal_pic_7(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\9.jpg".format(self.root))
+        goods_art_no_list = list(self.data.keys())
+        pp_jpg_1, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art_no_list[0],
+            name="鞋底",
+        )
+        pp_png_1 = pp_png_1.resize(value=pp_bg.width)
+        pp_png_1 = pp_png_1.crop(mode="min")
+        pp_png_1 = pp_png_1.rotate(doge=-8)
+        pp_png_1 = pp_png_1.transpose()
+        pp_bg.paste_img(top_img=pp_png_1, base="nc", value=(0, 520))
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 功能展示与卖点
+    def deal_pic_8(self):
+        detailed_images = []
+        pp_bg = PictureProcessing(r"{}\10.jpg".format(self.root))
+        goods_art_no_list = list(self.data.keys())
+        goods_art = goods_art_no_list[0]
+        _, pp_png_1 = self.image_one_pic(
+            return_orign=True,
+            goods_art_no=goods_art,
+            name="内里",
+        )
+        pp_png_1 = pp_png_1.crop(mode="min")
+        pp_png_1 = pp_png_1.resize(value=300)
+        desc_title_text_bg = PictureProcessing(
+            "RGB", (342, 268), (255, 255, 255, 0)
+        )
+        desc_title_text_bg = desc_title_text_bg.paste_img(
+            mode="pixel",
+            top_img=pp_png_1,
+            base="cc",
+            value=(0, 0),
+        )
+        # desc_title_text_bg = desc_title_text_bg.rotate(doge=150)
+        # desc_title_text_bg = desc_title_text_bg.crop(mode="min")
+        desc_title_text_bg = desc_title_text_bg.radius(value=30)
+        pp_bg.paste_img(
+            mode="pixel",
+            top_img=desc_title_text_bg,
+            base="en",
+            value=(62, 746),
+        )
+        detailed_images.append(pp_bg)
+        return PictureProcessing(im=self.add_pic(detailed_images))
+
+    # 添加尺码表
+    def deal_pic_9(self):
+        image_path = r"{}\11.jpg".format(self.root)
+        return PictureProcessing(image_path)
+
+    

+ 5 - 3
python/detail_template_test.py

@@ -4,17 +4,19 @@ import settings
 settings.is_test_plugins = True
 
 
-from custom_plugins.plugins.detail_template.xinjunlue.detail_xinjunlue1 import (
+from custom_plugins.plugins.detail_template.qingyangyizhan.detail_qingyangyizhan1 import (
     DetailPicGet,
 )
 
 
-data = json.load(open("detail_template_test_xinjunlue.json", mode="r", encoding="utf-8"))
+data = json.load(
+    open("detail_template_test_qingyangyizhan.json", mode="r", encoding="utf-8")
+)
 for goods_no, value in data.items():
     d = DetailPicGet(
         goods_no=goods_no,
         goods_no_value=value,
-        out_put_dir=r"C:\Development\project\python\CameraMachine\python\output\xinjunlue-1",
+        out_put_dir=r"C:\Development\project\python\CameraMachine\python\output\qingyangyizhan-1",
         test=True,
     )
 print("生成成功")

+ 42 - 0
python/detail_template_test_qingyangyizhan.json

@@ -0,0 +1,42 @@
+{
+    "AC5120913": {
+        "款号": "AC5120913",
+        "货号资料": [
+            {
+                "货号": "AC51016112",
+                "文件夹名称": "AC51016112",
+                "编号": "AC51016112",
+                "颜色名称": "枪色",
+                "pics": {
+                    "俯视-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(1)_俯视_抠图.png",
+                    "俯视-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(1)_俯视_阴影.png",
+                    "侧视-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(2)_侧视_抠图.png",
+                    "侧视-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(2)_侧视_阴影.png",
+                    "后跟-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(3)_后跟_抠图.png",
+                    "后跟-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(3)_后跟_阴影.png",
+                    "鞋底-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(4)_鞋底_抠图.png",
+                    "鞋底-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(4)_鞋底_阴影.png",
+                    "内里-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(5)_内里_抠图.png",
+                    "内里-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(5)_内里_阴影.png",
+                    "组合-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(6)_其他1_抠图.png",
+                    "组合-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(6)_其他1_阴影.png",
+                    "组合2-抠图": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(7)_其他0_抠图.png",
+                    "组合2-阴影": "C:/Users/15001/Desktop/ningbogongmao/阴影图处理/A12345(7)_其他0_阴影.png"
+                },
+                "800x800": [
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(1)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(2)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(3)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(4)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(5)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(6)_1600.jpg",
+                    "C:/Users/15001/Desktop/ningbogongmao/800x800/A12345(7)_1600.jpg"
+                ]
+            }
+        ],
+        "文件夹名称": "AC51016112",
+        "主标题": "舒适新体验",
+        "副标题": "“守护热爱骑行的你”",
+        "描述": "简约造型/头围可调/高颜值撞色搭配"
+    }
+}

+ 7 - 0
python/service/run_main.py

@@ -437,6 +437,13 @@ class RunMain():
                     return_data["message"] += "文件夹:{} 结构错误:{}\n".format(
                         one_folder, value["message"]
                     )
+                    return_data["data"]["config_data"]["success_handler"].append(
+                        {
+                            "goods_art_no": one_folder,
+                            "success": False,
+                            "info": value["message"],
+                        }
+                    )
                     continue
 
             # 符合要求的数据处理