$merchant) { $merchants[$index] = [ 'id' => $index, 'name' => $merchant['name'], 'mch_id' => $merchant['mch_id'] ]; } } View::assign("data", $config); View::assign("merchants", $merchants); return View::fetch('Config/miniprogram'); } //H5页面 public function h5(Request $request) { // 获取H5页面配置 $config = getConfig('h5_setting'); // 获取所有微信支付商户信息 $wxmerchants = []; $weixinpay_setting = getConfig('weixinpay_setting'); if (!empty($weixinpay_setting) && !empty($weixinpay_setting['merchants'])) { foreach ($weixinpay_setting['merchants'] as $index => $merchant) { $wxmerchants[$index] = [ 'id' => $index, 'name' => $merchant['name'], 'mch_id' => $merchant['mch_id'] ]; } } // 获取所有支付宝商户信息 $alimerchants = []; $alipay_setting = getConfig('alipay_setting'); if (!empty($alipay_setting) && !empty($alipay_setting['merchants'])) { foreach ($alipay_setting['merchants'] as $index => $merchant) { $alimerchants[$index] = [ 'id' => $index, 'name' => $merchant['name'], 'appId' => $merchant['appId'] ]; } } View::assign("data", $config); View::assign("wxmerchants", $wxmerchants); View::assign("alimerchants", $alimerchants); return View::fetch('Config/h5'); } //系统设置 public function systemconfig(Request $request) { $config = getConfig('systemconfig'); $user_config = getConfig('user_config'); $wechat_setting = getConfig('wechat_setting'); $app_setting = getConfig('app_setting'); $infinite_multiple = getConfig('infinite_multiple'); $wechatofficialaccount_setting = getConfig('wechatofficialaccount_setting'); $rank_setting = getConfig('rank_setting'); $system_test = getConfig('system_test'); $tencent_sms_config = getConfig('tencent_sms_config'); View::assign("key", "systemconfig"); View::assign("data", $config); View::assign("user_config", $user_config); View::assign("wechat_setting", $wechat_setting); View::assign("app_setting", $app_setting); View::assign("wechatofficialaccount_setting", $wechatofficialaccount_setting); View::assign("infinite_multiple", $infinite_multiple); View::assign("rank_setting", $rank_setting); View::assign("system_test", $system_test); View::assign("tencent_sms_config", $tencent_sms_config); return View::fetch('Config/systemconfig'); } //修改 public function update() { $data = input("post."); $data['update_time'] = time(); // 处理微信支付商户前缀验证 if ($data['key'] == 'weixinpay_setting' && isset($data['merchants']) && is_array($data['merchants'])) { // 检查前缀的唯一性 $prefixes = []; foreach ($data['merchants'] as $index => $merchant) { if (empty($merchant['order_prefix']) || strlen($merchant['order_prefix']) !== 3) { return $this->renderError('商户前缀必须是3位字符'); } if (in_array($merchant['order_prefix'], $prefixes)) { return $this->renderError('商户前缀"' . $merchant['order_prefix'] . '"重复,每个商户的前缀必须唯一'); } $prefixes[] = $merchant['order_prefix']; } } // 处理微信小程序配置 if ($data['key'] == 'miniprogram_setting' && isset($data['miniprograms']) && is_array($data['miniprograms'])) { // 检查是否有默认小程序 $hasDefault = false; $prefixes = []; foreach ($data['miniprograms'] as $index => $miniprogram) { if (isset($miniprogram['is_default']) && $miniprogram['is_default'] == 1) { $hasDefault = true; } // 验证订单前缀 if (!empty($miniprogram['order_prefix'])) { if (strlen($miniprogram['order_prefix']) != 2) { return $this->renderError('小程序"' . $miniprogram['name'] . '"的订单前缀必须是2位字符'); } if (in_array($miniprogram['order_prefix'], $prefixes)) { return $this->renderError('订单前缀"' . $miniprogram['order_prefix'] . '"重复,每个小程序的前缀必须唯一'); } $prefixes[] = $miniprogram['order_prefix']; } } if (!$hasDefault) { return $this->renderError('请至少设置一个默认小程序'); } // 清除旧的微信小程序配置缓存 $redis = new RedisHelper(); ($redis->getRedis())->del('config:miniprogram_setting'); } // 处理H5页面配置 if ($data['key'] == 'h5_setting' && isset($data['h5apps']) && is_array($data['h5apps'])) { // 检查是否有默认H5 $hasDefault = false; $prefixes = []; foreach ($data['h5apps'] as $index => $h5app) { if (isset($h5app['is_default']) && $h5app['is_default'] == 1) { $hasDefault = true; } // 验证订单前缀 if (!empty($h5app['order_prefix'])) { if (strlen($h5app['order_prefix']) != 2) { return $this->renderError('H5应用"' . $h5app['name'] . '"的订单前缀必须是2位字符'); } if (in_array($h5app['order_prefix'], $prefixes)) { return $this->renderError('订单前缀"' . $h5app['order_prefix'] . '"重复,每个H5应用的前缀必须唯一'); } $prefixes[] = $h5app['order_prefix']; } } if (!$hasDefault) { return $this->renderError('请至少设置一个默认H5应用'); } // 清除旧的H5配置缓存 $redis = new RedisHelper(); ($redis->getRedis())->del('config:h5_setting'); } // 处理同步地址数据格式 if ($data['key'] == 'systemconfig') { $syncAddresses = []; $addressNames = isset($data['sync_address_names']) ? $data['sync_address_names'] : []; $addressUrls = isset($data['sync_address_urls']) ? $data['sync_address_urls'] : []; // 移除原有数组 unset($data['sync_address_names']); unset($data['sync_address_urls']); // 构建新的数据格式 for ($i = 0; $i < count($addressUrls); $i++) { if (!empty($addressUrls[$i])) { $syncAddresses[] = [ 'name' => isset($addressNames[$i]) ? $addressNames[$i] : '', 'sync_address' => $addressUrls[$i] ]; } } // 使用新的格式设置同步地址 $data['sync_address'] = $syncAddresses; } if ($data['key'] == 'infinite_multiple') { //清除redis缓存:infinite_multiple $redis = new RedisHelper(); ($redis->getRedis())->del('config:infinite_multiple'); } if ($data['key'] == 'rank_setting') { //清除排行榜设置缓存 \app\common\helper\ConfigHelper::clearRankSettingsCache(); } if ($data['key'] == 'app_setting') { //清除redis缓存:app_setting $redis = new RedisHelper(); ($redis->getRedis())->del('config:app_setting'); } if ($data['key'] == 'system_test') { //清除redis缓存:system_test \app\common\helper\ConfigHelper::clearSystemTestCache(); } if ($data['key'] == 'tencent_sms_config') { //清除redis缓存:tencent_sms_config $redis = new RedisHelper(); ($redis->getRedis())->del('config:tencent_sms_config'); } if ($data['key'] == 'alipay_setting') { //清除redis缓存:alipay_setting $redis = new RedisHelper(); ($redis->getRedis())->del('config:alipay_setting'); } $result = setConfig($data['key'], $data); if ($result) { return $this->renderSuccess('修改成功'); } else { return $this->renderError('修改失败'); } } /** * 返回动态生成的JavaScript * @return Response */ public function dynamicJs() { // 解决跨域问题 header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET'); // 获取需要的配置数据 $config = getConfig('systemconfig'); // 构建JavaScript内容 $jsContent = "// 动态生成的JS文件\n"; $jsContent .= "const siteConfig = " . json_encode($config, JSON_UNESCAPED_UNICODE) . ";\n"; $jsContent .= "console.log('配置已加载');\n"; // 创建响应并设置Content-Type return Response::create($jsContent) ->contentType('application/javascript') ->header(['Content-Type' => 'application/javascript']); } /** * 直接输出JS内容的备用方法 */ public function getJs() { // 解决跨域问题 header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET'); header('Content-Type: application/javascript'); // 获取需要的配置数据 $config = getConfig('systemconfig'); // 直接输出JS内容 echo "// 动态生成的JS文件\n"; echo "const siteConfig = " . json_encode($config, JSON_UNESCAPED_UNICODE) . ";\n"; echo "console.log('配置已加载');\n"; exit; } } ?>