| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace common\components;
- /**
- * 散客分享海报(OSS 图片水印合成)
- */
- class PosterUtil
- {
- const BASE_TEMPLATE = 'poster/1234.jpg';
- const FONT = 'd3F5LW1pY3JvaGVp';
- /**
- * 海报标题过长时截断,避免压住底部文案区
- */
- public static function truncateText($text, $maxLen = 14)
- {
- $text = trim((string)$text);
- if ($text === '') {
- return '';
- }
- if (mb_strlen($text, 'UTF-8') > $maxLen) {
- return mb_substr($text, 0, $maxLen, 'UTF-8') . '…';
- }
- return $text;
- }
- /**
- * 和炫鲜花等门店角标
- */
- public static function buildHyxhLogoWatermark($mainId)
- {
- if (!in_array((int)$mainId, [52, 1459, 13495], true)) {
- return '';
- }
- $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_72,w_72';
- if ($mainId == 1459) {
- $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_72,w_72';
- }
- if ($mainId == 13495) {
- $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_72,w_72';
- }
- return stringUtil::ossBase64($logo);
- }
- /**
- * 花束海报
- */
- 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'] ?? '';
- $priceText = $options['priceText'] ?? '';
- $name = $options['name'] ?? '';
- $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';
- $qrWatermark = $miniCode . '?x-oss-process=image/resize,m_fill,h_220,w_220';
- $url = $prefix . self::BASE_TEMPLATE . '?x-oss-process=image';
- $url .= '/watermark,image_' . stringUtil::ossBase64($coverWatermark) . ',g_north,x_25,y_8';
- $url .= '/watermark,image_' . stringUtil::ossBase64($qrWatermark) . ',g_se,x_36,y_32';
- $logoB64 = self::buildHyxhLogoWatermark($mainId);
- if ($logoB64 !== '') {
- $url .= '/watermark,image_' . $logoB64 . ',g_se,x_210,y_48';
- }
- $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($scanHint) . ',g_se,x_44,y_292,color_888888,type_' . self::FONT . ',size_24';
- return $url;
- }
- }
|