diff --git a/app/admin/controller/Config.php b/app/admin/controller/Config.php index baea861..a850583 100755 --- a/app/admin/controller/Config.php +++ b/app/admin/controller/Config.php @@ -23,29 +23,20 @@ class Config extends Base public function weixinpay(Request $request) { $config = getConfig('weixinpay_setting'); - if (empty($config)) { - // 兼容旧数据,如果新配置为空,则尝试获取旧配置并转换格式 - $old_config = getConfig('weixinpay'); - if (!empty($old_config)) { - $config = [ - 'merchants' => [ - [ - 'name' => '默认商户', - 'mch_id' => $old_config['mch_id'] ?? '', - 'keys' => $old_config['keys'] ?? '', - 'order_prefix' => $old_config['order_prefix'] ?? 'MYH', - 'weight' => 1 - ] - ] - ]; - } - } - View::assign("key", "weixinpay_setting"); View::assign("data", $config); return View::fetch('Config/weixinpay'); } + //支付宝支付 + public function alipay(Request $request) + { + $config = getConfig('alipay_setting'); + View::assign("key", "alipay_setting"); + View::assign("data", $config); + return View::fetch('Config/alipay'); + } + //签到设置 public function sign(Request $request) { @@ -79,10 +70,6 @@ class Config extends Base { // 获取小程序配置 $config = getConfig('miniprogram_setting'); - - // 获取旧的微信小程序配置,用于兼容 - $wechat_setting = getConfig('wechat_setting'); - // 获取所有微信支付商户信息 $merchants = []; $weixinpay_setting = getConfig('weixinpay_setting'); @@ -95,13 +82,49 @@ class Config extends Base ]; } } - View::assign("data", $config); - View::assign("wechat_setting", $wechat_setting); 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) { @@ -184,6 +207,39 @@ class Config extends Base ($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 = []; @@ -234,6 +290,12 @@ class Config extends Base ($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('修改成功'); diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 0ed0663..83c3cb2 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -272,14 +272,16 @@ Route::rule('admin_operationlog', 'Admins/admin_operationlog', 'GET|POST'); Route::rule('admin_goods_log', 'Admins/admin_goods_log', 'GET|POST'); #============================ -#Config.网站配置 +#Config.php配置 #============================ Route::get('base', 'Config/base'); -Route::get('sign', 'Config/sign');//签到设置 Route::get('weixinpay', 'Config/weixinpay'); +Route::get('alipay', 'Config/alipay'); +Route::get('sign', 'Config/sign'); Route::get('uploadsFile', 'Config/uploads'); //上传设置 Route::get('systemconfig', 'Config/systemconfig'); //系统设置 -Route::get('miniprogram', 'Config/miniprogram'); //微信小程序配置 +Route::get('miniprogram', 'Config/miniprogram'); //微信小程序 +Route::get('h5', 'Config/h5'); //H5页面配置 Route::post('update', 'Config/update'); Route::get('wechatofficialaccount', 'Config/wechatofficialaccount'); diff --git a/app/admin/view/Config/alipay.html b/app/admin/view/Config/alipay.html new file mode 100644 index 0000000..f0b6a5b --- /dev/null +++ b/app/admin/view/Config/alipay.html @@ -0,0 +1,231 @@ +{include file="Public:header2"/} +
+ +