1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-17 07:45:29 +08:00
2019-12-13 00:10:10 +08:00

117 lines
3.0 KiB
PHP

<?php
namespace App\Http\Admin\Services;
use App\Caches\Config as ConfigCache;
use App\Repos\Config as ConfigRepo;
class Config extends Service
{
public function getSectionConfig($section)
{
$configRepo = new ConfigRepo();
$items = $configRepo->findBySection($section);
$result = new \stdClass();
if ($items->count() > 0) {
foreach ($items as $item) {
$result->{$item->item_key} = $item->item_value;
}
}
return $result;
}
public function updateSectionConfig($section, $config)
{
$configRepo = new ConfigRepo();
foreach ($config as $key => $value) {
$item = $configRepo->findItem($section, $key);
if ($item) {
$item->item_value = trim($value);
$item->update();
}
}
$configCache = new ConfigCache();
$configCache->delete();
}
public function updateStorageConfig($section, $config)
{
$protocol = ['http://', 'https://'];
if (isset($config['bucket_domain'])) {
$config['bucket_domain'] = str_replace($protocol, '', $config['bucket_domain']);
}
if (isset($config['ci_domain'])) {
$config['ci_domain'] = str_replace($protocol, '', $config['ci_domain']);
}
$this->updateSectionConfig($section, $config);
}
public function updateVodConfig($section, $config)
{
$this->updateSectionConfig($section, $config);
}
public function updateLiveConfig($section, $config)
{
$protocol = ['http://', 'https://'];
if (isset($config['push_domain'])) {
$config['push_domain'] = str_replace($protocol, '', $config['push_domain']);
}
if (isset($config['pull_domain'])) {
$config['pull_domain'] = str_replace($protocol, '', $config['pull_domain']);
}
if (isset($config['ptt'])) {
$ptt = $config['ptt'];
$keys = array_keys($ptt['id']);
$myPtt = [];
foreach ($keys as $key) {
$myPtt[$key] = [
'id' => $ptt['id'][$key],
'bit_rate' => $ptt['bit_rate'][$key],
'summary' => $ptt['summary'][$key],
'height' => $ptt['height'][$key],
];
}
$config['pull_trans_template'] = kg_json_encode($myPtt);
}
$this->updateSectionConfig($section, $config);
}
public function updateSmserConfig($section, $config)
{
$template = $config['template'];
$keys = array_keys($template['id']);
$myTemplate = [];
foreach ($keys as $key) {
$myTemplate[$key] = [
'id' => $template['id'][$key],
'content' => $template['content'][$key],
];
}
$config['template'] = kg_json_encode($myTemplate);
$this->updateSectionConfig($section, $config);
}
}