Просмотр исходного кода

Merge branch 'redesign‌-260706' into dev

shizhongqi 13 часов назад
Родитель
Сommit
11da59efd7

+ 1 - 1
app-hd/controllers/MainController.php

@@ -195,7 +195,7 @@ class MainController extends BaseController
 
         // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
         // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
-        $posterCacheKey = "wx_mini_item_poster_url_{$shopId}_{$adminId}_{$envVersion}";
+        $posterCacheKey = "wx_mini_item_poster_url:{$shopId}_{$adminId}_{$envVersion}";
         $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
         if (!empty($cachedPoster)) {
             $respond = json_decode($cachedPoster, true);

+ 37 - 0
app-hd/controllers/OrderController.php

@@ -1709,6 +1709,43 @@ class OrderController extends BaseController
             ->column();
     }
 
+    /**
+     * PC 本地 hiprint 打 A4:返回 printData + template(版式对齐 delivery-slip-a4)
+     * 对应前端 order/a4-print-info,不走链科云
+     */
+    public function actionA4PrintInfo()
+    {
+        $id = intval(Yii::$app->request->get('id', 0));
+        if ($id <= 0) {
+            util::fail('订单id不对');
+        }
+        $order = OrderService::getById($id);
+        OrderService::valid($order, $this->mainId);
+        try {
+            $payload = deliverySlipPrintUtil::buildHiprintPayload($order);
+        } catch (\Throwable $e) {
+            Yii::error('A4 hiprint 数据组装失败: ' . $e->getMessage(), __METHOD__);
+            util::fail($e->getMessage());
+        }
+        util::success($payload);
+    }
+
+    /**
+     * 增加订单打印次数(本地打 A4 / 打票后刷新列表「打印」列)
+     */
+    public function actionAddPrintNum()
+    {
+        $id = intval(Yii::$app->request->get('id', 0));
+        if ($id <= 0) {
+            util::fail('订单id不对');
+        }
+        $order = OrderClass::getById($id, true);
+        OrderClass::valid($order, $this->mainId);
+        $order->printNum += 1;
+        $order->save();
+        util::complete();
+    }
+
     /**
      * 链科云打印纸张类型列表
      */

+ 59 - 5
common/components/deliverySlipPrintUtil.php

@@ -8,12 +8,12 @@ use bizHd\order\services\OrderService;
 use Yii;
 
 /**
- * A4 鲜花配送单打印
+ * A4 鲜花配送单打印(链科云 HTML + PC 端 hiprint)
  */
 class deliverySlipPrintUtil
 {
     /**
-     * 根据零售订单 ID 打印 A4 配送单
+     * 根据零售订单 ID 打印 A4 配送单(链科云)
      */
     public static function printByOrderId($orderId, $mainId = 0, array $printOptions = [])
     {
@@ -30,7 +30,7 @@ class deliverySlipPrintUtil
     }
 
     /**
-     * 直接按模板数据打印
+     * 直接按模板数据打印(链科云)
      */
     public static function printByData(array $data, array $printOptions = [])
     {
@@ -47,10 +47,61 @@ class deliverySlipPrintUtil
         return (new cloudPrintUtil())->printHtml($html, $paper['dmPaperSize']);
     }
 
+    /**
+     * PC 本地 hiprint 打 A4:返回 printData + template(对齐 delivery-slip-a4 版式)
+     * @param array $order 订单数组
+     * @return array{printData:array,template:string}
+     */
+    public static function buildHiprintPayload(array $order)
+    {
+        return [
+            'printData' => self::buildHiprintDataFromOrder($order),
+            'template' => self::getHiprintTemplate(),
+        ];
+    }
+
+    /**
+     * 组装 hiprint 字段:封面用 URL(不做 data URI,避免本机打印慢)
+     */
+    public static function buildHiprintDataFromOrder(array $order)
+    {
+        $data = self::buildDataFromOrder($order, ['imageAsDataUri' => false]);
+        $addressBlock = (string)($data['fullAddress'] ?? '');
+        if (!empty($data['distanceText'])) {
+            $addressBlock .= ' 配送距离: ' . $data['distanceText'];
+        }
+        $data['addressBlock'] = $addressBlock;
+        $data['reachTimeText'] = trim(($data['reachDateLabel'] ?? '') . ' ' . ($data['reachDateTime'] ?? ''));
+        $data['productCountText'] = '共 ' . ($data['productCount'] ?? '1') . ' 个';
+        $data['serviceTip'] = '';
+        if (!empty($data['servicePhone'])) {
+            $data['serviceTip'] = '如在制作,配送环节出现问题或疑问,欢迎随时致电: ' . $data['servicePhone'];
+        }
+        return $data;
+    }
+
+    /**
+     * 读取 A4 配送单 hiprint JSON 模板字符串
+     */
+    public static function getHiprintTemplate()
+    {
+        $path = Yii::getAlias('@common/templates/delivery-slip-a4-hiprint.json');
+        if (!is_file($path)) {
+            throw new CloudPrinterApiException('配送单 hiprint 模板不存在');
+        }
+        $json = file_get_contents($path);
+        if ($json === false || $json === '') {
+            throw new CloudPrinterApiException('配送单 hiprint 模板读取失败');
+        }
+        return $json;
+    }
+
     /**
      * 组装配送单展示数据
+     * @param array $order 订单
+     * @param array $options imageAsDataUri=true 时封面转 base64(云打印盒需离线图)
      */
-    public static function buildDataFromOrder(array $order)
+    public static function buildDataFromOrder(array $order, array $options = [])
     {
         $shopId = intval($order['shopId'] ?? 0);
         $shop = ShopClass::getById($shopId, true);
@@ -110,6 +161,9 @@ class deliverySlipPrintUtil
 
         $sendNum = (string)($order['sendNum'] ?? '');
         $batchDay = str_pad((string)date('j'), 2, '0', STR_PAD_LEFT);
+        // 云打印默认转 data URI;本机 hiprint 传 URL 即可
+        $imageAsDataUri = !isset($options['imageAsDataUri']) || $options['imageAsDataUri'];
+        $productImage = $imageAsDataUri ? self::imageToDataUri($cover) : $cover;
 
         return [
             'title' => $shopName . ' 鲜花配送单',
@@ -123,7 +177,7 @@ class deliverySlipPrintUtil
             'reachDateTime' => $reachDateTime,
             'productName' => $productName,
             'productCount' => (string)$goodsNum,
-            'productImage' => self::imageToDataUri($cover),
+            'productImage' => $productImage,
             'cardInfo' => $order['cardInfo'] ?? '',
             'bookName' => $bookName,
             'bookMobile' => $bookMobile,

+ 434 - 0
common/templates/delivery-slip-a4-hiprint.json

@@ -0,0 +1,434 @@
+{
+  "panels": [
+    {
+      "index": 0,
+      "name": 1,
+      "height": 297,
+      "width": 210,
+      "paperHeader": 0,
+      "paperFooter": 780,
+      "printElements": [
+        {
+          "options": {
+            "left": 56,
+            "top": 20,
+            "height": 42,
+            "width": 400,
+            "title": "标题",
+            "field": "title",
+            "testData": "花掌柜 鲜花配送单",
+            "fontSize": 29,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 420,
+            "top": 28,
+            "height": 32,
+            "width": 140,
+            "title": "批次号",
+            "field": "batchNo",
+            "testData": "#O24 [#3]",
+            "fontSize": 19,
+            "textAlign": "right",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 70,
+            "height": 490,
+            "width": 520,
+            "borderWidth": 1
+          },
+          "printElementType": { "title": "矩形", "type": "rect" }
+        },
+
+        {
+          "options": { "left": 30, "top": 134, "height": 1, "width": 520, "borderWidth": 1 },
+          "printElementType": { "title": "横线", "type": "hline" }
+        },
+        {
+          "options": { "left": 30, "top": 230, "height": 1, "width": 520, "borderWidth": 1 },
+          "printElementType": { "title": "横线", "type": "hline" }
+        },
+        {
+          "options": { "left": 30, "top": 294, "height": 1, "width": 520, "borderWidth": 1 },
+          "printElementType": { "title": "横线", "type": "hline" }
+        },
+        {
+          "options": { "left": 30, "top": 467, "height": 1, "width": 520, "borderWidth": 1 },
+          "printElementType": { "title": "横线", "type": "hline" }
+        },
+
+        {
+          "options": { "left": 130, "top": 70, "height": 64, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 290, "top": 70, "height": 64, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 390, "top": 70, "height": 64, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 130, "top": 134, "height": 96, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 130, "top": 230, "height": 64, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 130, "top": 294, "height": 173, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+        {
+          "options": { "left": 130, "top": 467, "height": 93, "width": 1, "borderWidth": 1 },
+          "printElementType": { "title": "竖线", "type": "vline" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 70,
+            "height": 64,
+            "width": 100,
+            "title": "顾客姓名",
+            "testData": "顾客姓名",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 130,
+            "top": 70,
+            "height": 64,
+            "width": 160,
+            "title": "姓名",
+            "field": "receiveUserName",
+            "testData": "张女士",
+            "fontSize": 21,
+            "textAlign": "left",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 290,
+            "top": 70,
+            "height": 64,
+            "width": 100,
+            "title": "顾客电话",
+            "testData": "顾客电话",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 390,
+            "top": 70,
+            "height": 64,
+            "width": 160,
+            "title": "电话",
+            "field": "receiveMobile",
+            "testData": "13800138000",
+            "fontSize": 21,
+            "fontWeight": "bold",
+            "textAlign": "left",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 134,
+            "height": 96,
+            "width": 100,
+            "title": "顾客地址",
+            "testData": "顾客地址",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 135,
+            "top": 134,
+            "height": 96,
+            "width": 410,
+            "title": "地址",
+            "field": "addressBlock",
+            "testData": "福建省厦门市集美区前山路147号",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "lineHeight": 29,
+            "textAlign": "left",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 230,
+            "height": 64,
+            "width": 100,
+            "title": "配送时间",
+            "testData": "配送时间",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 135,
+            "top": 230,
+            "height": 64,
+            "width": 410,
+            "title": "时间",
+            "field": "reachTimeText",
+            "testData": "预约配送 03月15日 下午",
+            "fontSize": 21,
+            "fontWeight": "bold",
+            "textAlign": "left",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 340,
+            "height": 36,
+            "width": 100,
+            "title": "商品描述",
+            "testData": "商品描述",
+            "fontSize": 19,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 30,
+            "top": 380,
+            "height": 36,
+            "width": 100,
+            "title": "参考照片",
+            "testData": "参考照片",
+            "fontSize": 19,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 145,
+            "top": 308,
+            "height": 147,
+            "width": 133,
+            "field": "productImage",
+            "src": "",
+            "fit": "cover"
+          },
+          "printElementType": { "title": "图片", "type": "image" }
+        },
+        {
+          "options": {
+            "left": 290,
+            "top": 330,
+            "height": 40,
+            "width": 240,
+            "title": "商品名",
+            "field": "productName",
+            "testData": "韩式抱抱桶",
+            "fontSize": 21,
+            "fontWeight": "bold",
+            "textAlign": "left",
+            "textContentVerticalAlign": "top",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 290,
+            "top": 390,
+            "height": 48,
+            "width": 240,
+            "title": "数量",
+            "field": "productCountText",
+            "testData": "共 1 个",
+            "fontSize": 27,
+            "fontWeight": "bold",
+            "textAlign": "left",
+            "textContentVerticalAlign": "top",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 467,
+            "height": 93,
+            "width": 100,
+            "title": "贺卡内容",
+            "testData": "贺卡内容",
+            "fontSize": 20,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 135,
+            "top": 467,
+            "height": 93,
+            "width": 410,
+            "title": "贺卡",
+            "field": "cardInfo",
+            "testData": "生日快乐,愿你被鲜花和温柔包围。",
+            "fontSize": 20,
+            "lineHeight": 29,
+            "textAlign": "left",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+
+        {
+          "options": {
+            "left": 30,
+            "top": 580,
+            "height": 36,
+            "width": 520,
+            "title": "客服提示",
+            "field": "serviceTip",
+            "testData": "如在制作,配送环节出现问题或疑问,欢迎随时致电: 400-000-0000",
+            "fontSize": 16,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        },
+        {
+          "options": {
+            "left": 222,
+            "top": 640,
+            "height": 133,
+            "width": 133,
+            "borderWidth": 3
+          },
+          "printElementType": { "title": "椭圆", "type": "oval" }
+        },
+        {
+          "options": {
+            "left": 222,
+            "top": 640,
+            "height": 133,
+            "width": 133,
+            "title": "货号",
+            "field": "sendNum",
+            "testData": "3",
+            "fontSize": 48,
+            "fontWeight": "bold",
+            "textAlign": "center",
+            "textContentVerticalAlign": "middle",
+            "hideTitle": true,
+            "fontFamily": "SimSun"
+          },
+          "printElementType": { "title": "文本", "type": "text" }
+        }
+      ],
+      "paperNumberLeft": 565,
+      "paperNumberTop": 819,
+      "paperNumberDisabled": true,
+      "paperNumberContinue": true,
+      "fontFamily": "SimSun",
+      "watermarkOptions": {
+        "content": "",
+        "rotate": 25,
+        "timestamp": false,
+        "format": "YYYY-MM-DD HH:mm",
+        "fillStyle": "rgba(184, 184, 184, 0.3)",
+        "fontSize": "14px",
+        "width": 200,
+        "height": 200
+      },
+      "panelLayoutOptions": {
+        "layoutType": "column",
+        "layoutRowGap": 0,
+        "layoutColumnGap": 0
+      }
+    }
+  ]
+}