|
|
@@ -70,18 +70,36 @@ class MainController extends BaseController
|
|
|
util::success(['info' => $main]);
|
|
|
}
|
|
|
|
|
|
- //花束商城太阳 ssh 20210610
|
|
|
+ /**
|
|
|
+ * 职责:生成并获取花束商城太阳码海报及商城短链接
|
|
|
+ * 入参:HTTP GET (参数可选:env_version)
|
|
|
+ * 返回:太阳码海报图片的完整 OSS 地址以及短链接 URL
|
|
|
+ * 副作用:当没有缓存时,会触发向微信 API 请求并同步上传生成的图片至阿里 OSS。
|
|
|
+ * 关键边界:引入了店员+门店+环境级别的最终海报数据 Redis 强缓存(3天有效期),避免每次高频无端向微信和 OSS 发起同步请求。
|
|
|
+ */
|
|
|
public function actionGetMallPoster()
|
|
|
{
|
|
|
$shop = $this->shop;
|
|
|
$shopId = $this->shopId;
|
|
|
$pfShopId = $shop->pfShopId ?? 0;
|
|
|
+ $adminId = $this->shopAdminId;
|
|
|
+ $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
|
|
|
+
|
|
|
+ // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
|
|
|
+ // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
|
|
|
+ $posterCacheKey = "wx_mini_mall_poster_url_{$shopId}_{$adminId}_{$envVersion}";
|
|
|
+ $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
|
|
|
+ if (!empty($cachedPoster)) {
|
|
|
+ $respond = json_decode($cachedPoster, true);
|
|
|
+ if (!empty($respond['goodsUrl']) && !empty($respond['goodsLink'])) {
|
|
|
+ util::success($respond); // 缓存直接命中,毫秒级快速返回!
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$merchant = WxOpenClass::getMallWxInfo();
|
|
|
$goodsPage = 'pages/home/category';
|
|
|
$ptStyle = dict::getDict('ptStyle', 'mall');
|
|
|
- $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
|
|
|
- $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
|
|
|
+ $scene = 'a=' . $adminId . '&s=' . $shopId;
|
|
|
$goodsImgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $goodsPage, $scene, $ptStyle, $envVersion);
|
|
|
|
|
|
$sjName = $shop->merchantName ?? '';
|
|
|
@@ -115,6 +133,10 @@ class MainController extends BaseController
|
|
|
'goodsUrl' => $goodsUrl,
|
|
|
'goodsLink' => $goodsLink,
|
|
|
];
|
|
|
+
|
|
|
+ // ==================== 【性能优化】保存最终拼接和生成结果到 Redis 中,过期时间 3 天 ====================
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$posterCacheKey, 86400 * 3, json_encode($respond)]);
|
|
|
+
|
|
|
util::success($respond);
|
|
|
}
|
|
|
|