255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'backend_url' => '后台管理域名', 'h5_url' => 'h5域名', 'api_url' => 'api域名', 'static_url' => '静态资源域名', 'is_custom_host' => '是否自定义域名:1:是:0:否', 'ssl_path' => '证书目录', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'status' => '状态', ]; } public static function setData(array $params) { try { if (empty($params['mall_id'])) throw new Exception('商城id不能为空'); $model = self::findOne(['mall_id' => $params['mall_id']]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); \Yii::$app->cache->set(self::getCacheKey($model['mall_id']), $model->toArray()); return $model; } catch (Exception $e) { self::$static_error = $e->getMessage(); return false; } } public static function getCacheKey($mall_id){ return RedisKeyEnum::suffix(RedisKeyEnum::MALL_HOST,$mall_id,true); } public static function getHost($mall_id, $type) { $is_http = function ($url) { $parsedUrl = parse_url($url); return isset($parsedUrl['scheme']) && strtolower($parsedUrl['scheme']) === 'https'; }; $mall_host = \Yii::$app->cache->get(self::getCacheKey($mall_id)); if(empty($mall_host)){ $mall_host = self::findOne(['mall_id' => $mall_id]); if(empty($mall_host)){ return \Yii::$app->services->setting->platform->get('system.'.$type); } \Yii::$app->cache->set(self::getCacheKey($mall_id), $mall_host->toArray()); } if (!empty($mall_host['is_custom_host']) && !empty($mall_host[$type])) { $host = $is_http($mall_host[$type]) ? $mall_host[$type] : 'https://' . $mall_host[$type]; } else { $host = \Yii::$app->services->setting->platform->get('system.'.$type); } return $host; } }