'微信小程序', 'DouyinMiniProgram' => '抖音小程序', ]; public function _initialize() { parent::_initialize(); } /** * 查看平台配置 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { $list = []; // 获取所有平台配置 $configs = PlatformService::getAllPlatformConfigs(); foreach ($configs as $platform => $config) { $list[] = [ 'platform' => $platform, 'name' => $config['title'], 'status' => $config['status'] ? '启用' : '禁用', 'count' => count($config['config']), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ]; } $result = array( "total" => count($list), "rows" => $list ); return json($result); } return $this->view->fetch(); } /** * 微信小程序配置 */ public function wechat_mini_program() { $group = 'shop.platform.WechatMiniProgram'; return $this->platformConfig($group, '微信小程序配置'); } /** * 抖音小程序配置 */ public function douyin_mini_program() { $group = 'shop.platform.DouyinMiniProgram'; return $this->platformConfig($group, '抖音小程序配置'); } /** * 平台配置通用方法 */ private function platformConfig($group, $title) { if ($this->request->isPost()) { $params = $this->request->post(); // 验证参数 if (!isset($params['config']) || !is_array($params['config'])) { $this->error('参数错误'); } try { $result = PlatformService::setConfigsByGroup($params['config'], $group); if ($result) { $this->success('配置保存成功'); } else { $this->error('配置保存失败'); } } catch (Exception $e) { $this->error($e->getMessage()); } } // 获取当前平台配置 $configs = PlatformService::getConfigByGroup($group); $this->view->assign('configs', $configs); $this->view->assign('group', $group); $this->view->assign('title', $title); return $this->view->fetch('config'); } /** * 初始化平台配置 */ public function init_config() { if ($this->request->isPost()) { $platform = $this->request->post('platform'); if (!$platform) { $this->error('请选择平台'); } try { $result = PlatformService::initPlatformConfig($platform); if ($result) { $this->success('平台配置初始化成功'); } else { $this->error('平台配置初始化失败'); } } catch (Exception $e) { $this->error($e->getMessage()); } } return $this->view->fetch(); } /** * 清除配置缓存 */ public function clear() { PlatformService::clearConfigCache(); $this->success('缓存清除成功'); } /** * 获取配置信息 */ public function get_config() { $name = $this->request->param('name'); if (!$name) { $this->error('参数错误'); } $config = PlatformService::getConfigValue($name); return json([ 'code' => 1, 'msg' => '获取成功', 'data' => $config ]); } /** * 设置配置信息 */ public function set_config() { if ($this->request->isPost()) { $name = $this->request->post('name'); $value = $this->request->post('value'); if (!$name) { $this->error('参数错误'); } try { $result = PlatformService::setConfigValue($name, $value); if ($result) { $this->success('配置设置成功'); } else { $this->error('配置设置失败'); } } catch (Exception $e) { $this->error($e->getMessage()); } } } }