|
|
@@ -56,15 +56,35 @@ class MainController extends BaseController
|
|
|
util::success(['info' => $main]);
|
|
|
}
|
|
|
|
|
|
- //采购商城海报 ssh 20230217
|
|
|
+ /**
|
|
|
+ * 职责:生成并获取采购商城太阳码海报
|
|
|
+ * 入参:HTTP GET (参数可选:env_version)
|
|
|
+ * 返回:太阳码海报图片的完整 OSS 地址 JSON
|
|
|
+ * 副作用:当没有缓存时,会触发向微信 API 请求并同步上传生成的图片至阿里 OSS。
|
|
|
+ * 关键边界:引入了店员+环境+门店级别的最终海报数据 Redis 强缓存(3天有效期),避免每次高频无端向微信和 OSS 发起同步请求。
|
|
|
+ */
|
|
|
public function actionGetMallPoster()
|
|
|
{
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $adminId = $this->shopAdminId;
|
|
|
+ $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
|
|
|
+
|
|
|
+ // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
|
|
|
+ // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
|
|
|
+ $posterCacheKey = "wx_mini_purchase_mall_poster_url_{$shopId}_{$adminId}_{$envVersion}";
|
|
|
+ $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
|
|
|
+ if (!empty($cachedPoster)) {
|
|
|
+ $respond = json_decode($cachedPoster, true);
|
|
|
+ if (!empty($respond['imgUrl'])) {
|
|
|
+ util::success($respond); // 缓存直接命中,毫秒级快速返回!
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$merchant = WxOpenClass::getWxInfo();
|
|
|
$page = 'pagesPurchase/ghsProduct';
|
|
|
$ptStyle = dict::getDict('ptStyle', 'hd');
|
|
|
//scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
|
|
|
- $scene = "sId={$this->shopId}&id=0&gId=" . $this->shopAdminId;
|
|
|
- $envVersion = miniUtil::normalizeMiniEnvVersion(Yii::$app->request->get('env_version', 'release'));
|
|
|
+ $scene = "sId={$shopId}&id=0&gId=" . $adminId;
|
|
|
$imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
|
|
|
$titleBase64 = stringUtil::ossBase64('扫码买花');
|
|
|
$prefix = imgUtil::getPrefix();
|
|
|
@@ -73,6 +93,10 @@ class MainController extends BaseController
|
|
|
$url .= '/watermark,image_' . $goodsMiniCodeBase64 . ',g_north,x_0,y_40';
|
|
|
$url .= '/watermark,text_' . $titleBase64 . ',g_north,x_0,y_530,size_50';
|
|
|
$respond = ['imgUrl' => $url];
|
|
|
+
|
|
|
+ // ==================== 【性能优化】保存最终拼接和生成结果到 Redis 中,过期时间 3 天 ====================
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$posterCacheKey, 86400 * 3, json_encode($respond)]);
|
|
|
+
|
|
|
util::success($respond);
|
|
|
}
|
|
|
|