Bladeren bron

海报优化

shish 2 maanden geleden
bovenliggende
commit
41b45aaa10
2 gewijzigde bestanden met toevoegingen van 61 en 124 verwijderingen
  1. 28 91
      app-ghs/controllers/ItemController.php
  2. 33 33
      common/components/PosterUtil.php

+ 28 - 91
app-ghs/controllers/ItemController.php

@@ -15,6 +15,7 @@ use common\components\dict;
 use common\components\imgUtil;
 use common\components\miniUtil;
 use common\components\noticeUtil;
+use common\components\PosterUtil;
 use common\components\stringUtil;
 use common\components\util;
 use bizGhs\product\classes\ProductClass;
@@ -931,17 +932,16 @@ class ItemController extends BaseController
         if (empty($cover)) {
             util::fail('获取失败');
         }
+        $cover = imgUtil::normalizeOssObjectPath($cover);
 
         $merchant = WxOpenClass::getMallWxInfo();
         $page = 'pages/item/detail';
         $ptStyle = dict::getDict('ptStyle', 'mall');
         $shop = $this->shop;
         $lsShopId = $shop->lsShopId ?? 0;
-        //scene不能超过32个字条
-        $scene = "id=" . $id . '&a=' . $lsShopId;
-        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
-        $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
-        $miniCodeBase64 = stringUtil::ossBase64($miniCode);
+        $scene = 'id=' . $id . '&a=' . $lsShopId;
+        $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
+        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
 
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
 
@@ -952,51 +952,20 @@ class ItemController extends BaseController
             $skMore = $item->skMore ?? 0;
             $price = bcadd($item->discountPrice, $skMore, 2);
         }
-        $newPrice = '¥' . floatval($price);
-        $priceBase64 = stringUtil::ossBase64($newPrice);
-
-        $name = $item->name ?? '';
-        $nameBase64 = stringUtil::ossBase64($name);
 
         $staff = $this->shopAdmin;
         $staffName = $staff->name ?? '';
-        $newStaffName = $staffName . ' 为您推荐';
-        $staffNameBase64 = stringUtil::ossBase64($newStaffName);
-
-        //花材主图
-        $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
-        $itemCoverBase64 = stringUtil::ossBase64($itemCover);
-
-        $logoBase64 = '';
-        if (in_array($this->mainId, [52, 1459, 13495])) {
-            $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            if ($this->mainId == 1459) {
-                $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            }
-            if ($this->mainId == 13495) {
-                $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            }
-            $logoBase64 = stringUtil::ossBase64($logo);
-        }
 
-        $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
-        //花材主图
-        $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
-        //小程序码
-        $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
-        if (!empty($logoBase64)) {
-            //logo
-            $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
-        }
-        //为你推荐
-        $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
-        //标题
-        $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
-        //价格
-        $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
+        $url = PosterUtil::buildMallItemPosterUrl($prefix, [
+            'cover' => $cover,
+            'miniCode' => $miniCode,
+            'priceText' => '¥' . floatval($price),
+            'name' => $item->name ?? '',
+            'staffText' => $staffName . ' 为您推荐',
+            'mainId' => $this->mainId,
+        ]);
 
-        $respond = ['imgUrl' => $url];
-        util::success($respond);
+        util::success(['imgUrl' => $url]);
     }
 
     //下载商品码,用于花市卖花 ssh 20240823
@@ -1056,15 +1025,14 @@ class ItemController extends BaseController
         if (empty($cover)) {
             util::fail('获取失败');
         }
+        $cover = imgUtil::normalizeOssObjectPath($cover);
+
         $merchant = WxOpenClass::getWxInfo();
         $page = 'admin/ghsProduct/detail';
         $ptStyle = dict::getDict('ptStyle', 'hd');
-
-        //小程序码,scene不能超过32个字条
-        $scene = "id=" . $id . '&sId=' . $this->shopId;
-        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
-        $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
-        $miniCodeBase64 = stringUtil::ossBase64($miniCode);
+        $scene = 'id=' . $id . '&sId=' . $this->shopId;
+        $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
+        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
 
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
 
@@ -1074,51 +1042,20 @@ class ItemController extends BaseController
         if ($item->discountPrice > 0) {
             $price = $item->discountPrice;
         }
-        $newPrice = '¥' . floatval($price);
-        $priceBase64 = stringUtil::ossBase64($newPrice);
-
-        $name = $item->name ?? '';
-        $nameBase64 = stringUtil::ossBase64($name);
 
         $staff = $this->shopAdmin;
         $staffName = $staff->name ?? '';
-        $newStaffName = $staffName . ' 为您推荐';
-        $staffNameBase64 = stringUtil::ossBase64($newStaffName);
-
-        //花材主图
-        $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
-        $itemCoverBase64 = stringUtil::ossBase64($itemCover);
-
-        $logoBase64 = '';
-        if (in_array($this->mainId, [52, 1459, 13495])) {
-            $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            if ($this->mainId == 1459) {
-                $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            }
-            if ($this->mainId == 13495) {
-                $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
-            }
-            $logoBase64 = stringUtil::ossBase64($logo);
-        }
 
-        $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
-        //花材主图
-        $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
-        //小程序码
-        $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
-        if (!empty($logoBase64)) {
-            //logo
-            $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
-        }
-        //为你推荐
-        $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
-        //标题
-        $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
-        //价格
-        $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
+        $url = PosterUtil::buildGhsHdItemPosterUrl($prefix, [
+            'cover' => $cover,
+            'miniCode' => $miniCode,
+            'priceText' => '¥' . floatval($price),
+            'name' => $item->name ?? '',
+            'staffText' => $staffName . ' 为您推荐',
+            'mainId' => $this->mainId,
+        ]);
 
-        $respond = ['imgUrl' => $url];
-        util::success($respond);
+        util::success(['imgUrl' => $url]);
     }
 
     //是否有C级价格大于B级的 ssh 20221204

+ 33 - 33
common/components/PosterUtil.php

@@ -45,9 +45,36 @@ class PosterUtil
     }
 
     /**
-     * 花束海报:主图 m_lfit 保留完整花束,底部价格/标题/扫码区层次更清晰
+     * 花束海报
      */
     public static function buildMallGoodsPosterUrl($prefix, array $options)
+    {
+        return self::buildMallSharePosterUrl($prefix, $options);
+    }
+
+    /**
+     * 花材海报(与花束同一套版式)
+     */
+    public static function buildMallItemPosterUrl($prefix, array $options)
+    {
+        return self::buildMallSharePosterUrl($prefix, $options);
+    }
+
+    /**
+     * 花农端花店采购海报(ghs 花材详情太阳码)
+     */
+    public static function buildGhsHdItemPosterUrl($prefix, array $options)
+    {
+        if (!isset($options['scanHint'])) {
+            $options['scanHint'] = '微信扫码采购';
+        }
+        return self::buildMallSharePosterUrl($prefix, $options);
+    }
+
+    /**
+     * 散客分享海报:主图 m_lfit、价格/标题/推荐人层次、扫码提示
+     */
+    private static function buildMallSharePosterUrl($prefix, array $options)
     {
         $cover = $options['cover'] ?? '';
         $miniCode = $options['miniCode'] ?? '';
@@ -56,10 +83,14 @@ class PosterUtil
         $staffText = $options['staffText'] ?? '';
         $mainId = (int)($options['mainId'] ?? 0);
         $flowerNum = (int)($options['flowerNum'] ?? 0);
+        $subtitle = trim((string)($options['subtitle'] ?? ''));
+        $scanHint = trim((string)($options['scanHint'] ?? '微信扫码下单'));
 
         $displayName = self::truncateText($name, 14);
         if ($flowerNum > 0 && $displayName !== '') {
             $displayName .= ' · ' . $flowerNum . '支';
+        } elseif ($subtitle !== '' && $displayName !== '') {
+            $displayName .= ' · ' . self::truncateText($subtitle, 8);
         }
 
         $coverWatermark = $cover . '?x-oss-process=image/resize,m_lfit,h_1020,w_700,limit_0';
@@ -77,38 +108,7 @@ class PosterUtil
         $url .= '/watermark,text_' . stringUtil::ossBase64($priceText) . ',g_sw,x_24,y_32,color_EE2C2C,type_' . self::FONT . ',size_56';
         $url .= '/watermark,text_' . stringUtil::ossBase64($displayName) . ',g_sw,x_24,y_102,color_333333,type_' . self::FONT . ',size_36';
         $url .= '/watermark,text_' . stringUtil::ossBase64($staffText) . ',g_sw,x_24,y_148,color_999999,type_' . self::FONT . ',size_26';
-        $url .= '/watermark,text_' . stringUtil::ossBase64('微信扫码下单') . ',g_se,x_44,y_292,color_888888,type_' . self::FONT . ',size_24';
-
-        return $url;
-    }
-
-    /**
-     * 花材海报:方图裁切,保持原有布局
-     */
-    public static function buildMallItemPosterUrl($prefix, array $options)
-    {
-        $cover = $options['cover'] ?? '';
-        $miniCode = $options['miniCode'] ?? '';
-        $priceText = $options['priceText'] ?? '';
-        $name = $options['name'] ?? '';
-        $staffText = $options['staffText'] ?? '';
-        $mainId = (int)($options['mainId'] ?? 0);
-
-        $coverWatermark = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
-        $qrWatermark = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
-
-        $url = $prefix . self::BASE_TEMPLATE . '?x-oss-process=image';
-        $url .= '/watermark,image_' . stringUtil::ossBase64($coverWatermark) . ',g_nw,x_0,y_0';
-        $url .= '/watermark,image_' . stringUtil::ossBase64($qrWatermark) . ',g_se';
-
-        $logoB64 = self::buildHyxhLogoWatermark($mainId);
-        if ($logoB64 !== '') {
-            $url .= '/watermark,image_' . $logoB64 . ',g_se,x_65,y_65';
-        }
-
-        $url .= '/watermark,text_' . stringUtil::ossBase64($staffText) . ',g_sw,x_18,y_235,color_8B8989,type_' . self::FONT . ',size_30';
-        $url .= '/watermark,text_' . stringUtil::ossBase64(self::truncateText($name, 16)) . ',g_sw,x_18,y_145';
-        $url .= '/watermark,text_' . stringUtil::ossBase64($priceText) . ',g_sw,x_18,y_50,color_EE2C2C,type_' . self::FONT . ',size_50';
+        $url .= '/watermark,text_' . stringUtil::ossBase64($scanHint) . ',g_se,x_44,y_292,color_888888,type_' . self::FONT . ',size_24';
 
         return $url;
     }