123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <?php
- namespace app\admin\controller\shop;
- use app\common\Service\ShopConfigService;
- use app\common\controller\Backend;
- use app\common\Enum\ChannelEnum;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- use app\common\Enum\StatusEnum;
- /**
- * 平台配置管理
- */
- class Platform extends Backend
- {
- /**
- * 获取平台配置映射(枚举常量 -> 显示配置)
- */
- private function getPlatformDisplayMap()
- {
- return [
- ChannelEnum::CHANNEL_WECHAT_MINI_PROGRAM => [
- 'key' => 'wechat_mini_program',
- 'name' => '微信小程序',
- 'desc' => '一键生成,连接微信庞大用户群及微信生态',
- 'icon' => '/assets/img/platfom/icon_we_chat_applet.png',
- 'class' => 'wechat-mini',
- 'btn_class' => 'btn-success'
- ],
- ChannelEnum::CHANNEL_DOUYIN_MINI_PROGRAM => [
- 'key' => 'douyin_mini_program',
- 'name' => '抖音小程序',
- 'desc' => '抖音小程序,抖音生态',
- 'icon' => '/assets/img/platfom/icon-douyin.png',
- 'class' => 'toutiao-mini',
- 'btn_class' => 'btn-warning'
- ],
- ChannelEnum::CHANNEL_IOS_APP => [
- 'key' => 'ios_app',
- 'name' => 'IOS APP',
- 'desc' => '支持IOS程序下载,助力品牌传播',
- 'icon' => '/assets/img/platfom/icon_uniapp.png',
- 'class' => 'app-platform',
- 'btn_class' => 'btn-info'
- ],
- ChannelEnum::CHANNEL_ANDROID_APP => [
- 'key' => 'android_app',
- 'name' => '安卓APP',
- 'desc' => '支持安卓程序下载,助力品牌传播',
- 'icon' => '/assets/img/platfom/icon_uniapp.png',
- 'class' => 'app-platform',
- 'btn_class' => 'btn-info'
- ],
- // ChannelEnum::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
- // 'key' => 'wechat_official_account',
- // 'name' => '微信公众号',
- // 'desc' => '借助海量流量,玩转微信生态',
- // 'icon' => '/assets/img/platfom/icon_we_chat.png',
- // 'class' => 'wechat-official',
- // 'btn_class' => 'btn-success'
- // ],
- // ChannelEnum::CHANNEL_H5 => [
- // 'key' => 'h5',
- // 'name' => '手机浏览器H5',
- // 'desc' => 'WAP移动端页面,广泛覆盖移动市场',
- // 'icon' => '/assets/img/platfom/icon_browser.png',
- // 'class' => 'mobile-h5',
- // 'btn_class' => 'btn-primary'
- // ],
- // ChannelEnum::CHANNEL_PC => [
- // 'key' => 'pc',
- // 'name' => 'PC商城',
- // 'desc' => '开启你的个人PC端的独立商城',
- // 'icon' => '/assets/img/platfom/icon_pc.png',
- // 'class' => 'pc-platform',
- // 'btn_class' => 'btn-info'
- // ],
- // ChannelEnum::CHANNEL_QQ_MINI_PROGRAM => [
- // 'key' => 'qq_mini_program',
- // 'name' => 'QQ小程序',
- // 'desc' => 'QQ小程序,连接QQ用户生态',
- // 'icon' => '/assets/img/platfom/icon_qq.png',
- // 'class' => 'qq-mini',
- // 'btn_class' => 'btn-primary'
- // ],
- // ChannelEnum::CHANNEL_ALIPAY_MINI_PROGRAM => [
- // 'key' => 'alipay_mini_program',
- // 'name' => '支付宝小程序',
- // 'desc' => '支付宝小程序,支付宝生态',
- // 'icon' => '/assets/img/platfom/icon_zhifubao.png',
- // 'class' => 'alipay-mini',
- // 'btn_class' => 'btn-success'
- // ]
- ];
- }
- /**
- * 获取所有支持的平台
- */
- private function getSupportedPlatforms()
- {
- return array_keys($this->getPlatformDisplayMap());
- }
- /**
- * 根据枚举常量获取平台Key
- */
- private function getPlatformKey($channelConstant)
- {
- $map = $this->getPlatformDisplayMap();
- return $map[$channelConstant]['key'] ?? null;
- }
- /**
- * 根据平台Key获取枚举常量
- */
- private function getChannelConstant($platformKey)
- {
- $map = $this->getPlatformDisplayMap();
- foreach ($map as $constant => $config) {
- if ($config['key'] === $platformKey) {
- return $constant;
- }
- }
- return null;
- }
-
- protected $model = null;
- protected $noNeedRight = ['select', 'selectpage_type', 'check_element_available'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\common\model\ShopConfig;
- $this->view->assign('statusList', StatusEnum::getMap());
- }
- /**
- * 平台状态
- */
- public function index()
- {
- if ($this->request->isAjax()) {
- // AJAX请求返回状态数据
- $status = [];
- $platformMap = $this->getPlatformDisplayMap();
-
- foreach ($platformMap as $channelConstant => $config) {
- $platformKey = $config['key'];
- $status[$platformKey] = ShopConfigService::getConfigField("shop.platform.{$platformKey}.status", false) ?: 0;
- }
-
- $this->success('操作成功', null, $status);
- } else {
- // 普通请求返回视图
- $status = [];
- $platformMap = $this->getPlatformDisplayMap();
-
- foreach ($platformMap as $channelConstant => $config) {
- $platformKey = $config['key'];
- $status[$platformKey] = ShopConfigService::getConfigField("shop.platform.{$platformKey}.status", false) ?: 0;
- }
-
- // 为每个平台预处理功能支持情况
- $platformFeatures = [];
- foreach ($platformMap as $channelConstant => $config) {
- $platformKey = $config['key'];
- $platformFeatures[$channelConstant] = [
- 'payment' => ChannelEnum::channelSupportsFeature($channelConstant, 'payment'),
- 'share' => ChannelEnum::channelSupportsFeature($channelConstant, 'share'),
- // 'push' => ChannelEnum::channelSupportsFeature($channelConstant, 'push'),
- ];
- }
-
- $this->view->assign('platformStatus', $status);
- $this->view->assign('platformList', $platformMap);
- $this->view->assign('platformFeatures', $platformFeatures);
- $this->view->assign('channelEnum', ChannelEnum::class);
- return $this->view->fetch();
- }
- }
- /**
- * 平台配置
- */
- public function edit($ids = null)
- {
- $platform = $this->request->param('platform');
- // 验证平台是否支持
- $channelConstant = $this->getChannelConstant($platform);
- if (!ChannelEnum::isValidChannel($channelConstant)) {
- $this->error('平台不支持');
- }
- if ($this->request->isAjax()) {
- $params = $this->request->param();
-
- // 兼容config和row两种参数名
- $config = isset($params['config']) ? $params['config'] : (isset($params['row']) ? $params['row'] : []);
-
- if (empty($config)) {
- $this->error('配置参数错误');
- }
- if (!isset($params['share']['methods'])) {
- $params['share']['methods'] = [];
- }
- if (!isset($params['payment']['methods'])) {
- $params['payment']['methods'] = [];
- }
- // echo "<pre>";
- // print_r($config);
- // echo "</pre>";
- // exit;
- // try {
- $configs = ShopConfigService::setConfigs('shop.platform.' . $platform, $config);
- $this->success('配置保存成功', null, ['platform' => $platform]);
- // } catch (\Exception $e) {
- // $this->error('配置保存失败:' . $e->getMessage());
- // }
- }
- $configs = ShopConfigService::getConfigs('shop.platform.' . $platform, false);
- $platformMap = $this->getPlatformDisplayMap();
- $platformConfig = null;
- $currentChannelConstant = null;
-
- // 获取当前平台的配置信息
- foreach ($platformMap as $channelConstant => $config) {
- if ($config['key'] === $platform) {
- $platformConfig = $config;
- $platformConfig['channel'] = $channelConstant;
- $currentChannelConstant = $channelConstant;
- break;
- }
- }
-
- // 预处理支付方式支持情况
- $supportedPayments = [];
- if ($currentChannelConstant) {
- $supportedPayments = [
- 'wechat' => ChannelEnum::channelSupportsPayment($currentChannelConstant, 'wechat'),
- 'alipay' => ChannelEnum::channelSupportsPayment($currentChannelConstant, 'alipay'),
- 'balance' => ChannelEnum::channelSupportsPayment($currentChannelConstant, 'balance'),
- 'offline' => ChannelEnum::channelSupportsPayment($currentChannelConstant, 'offline'),
- 'cod' => ChannelEnum::channelSupportsPayment($currentChannelConstant, 'cod'),
- ];
- }
-
- // 预处理功能支持情况
- $supportedFeatures = [];
- if ($currentChannelConstant) {
- $supportedFeatures = [
- 'payment' => ChannelEnum::channelSupportsFeature($currentChannelConstant, 'payment'),
- 'share' => ChannelEnum::channelSupportsFeature($currentChannelConstant, 'share'),
- 'push' => ChannelEnum::channelSupportsFeature($currentChannelConstant, 'push'),
- 'location' => ChannelEnum::channelSupportsFeature($currentChannelConstant, 'location'),
- 'camera' => ChannelEnum::channelSupportsFeature($currentChannelConstant, 'camera'),
- ];
- }
-
- // 获取当前平台支持的支付方式列表
- $supportedPaymentList = [];
- if ($currentChannelConstant) {
- $paymentCodes = ChannelEnum::getChannelSupportedPayments($currentChannelConstant);
- $paymentMap = ChannelEnum::getPaymentMap();
- foreach ($paymentCodes as $paymentCode) {
- $supportedPaymentList[$paymentCode] = $paymentMap[$paymentCode] ?? $paymentCode;
- }
- }
-
- $this->view->assign('configs', $configs);
- $this->view->assign('platform', $platform);
- $this->view->assign('platformConfig', $platformConfig);
- $this->view->assign('channelConstant', $currentChannelConstant);
- $this->view->assign('channelEnum', ChannelEnum::class);
- $this->view->assign('supportedPayments', $supportedPayments);
- $this->view->assign('supportedFeatures', $supportedFeatures);
- $this->view->assign('supportedPaymentList', $supportedPaymentList);
- $this->view->assign('group', 'shop.platform.' . $platform);
- return $this->view->fetch();
- }
- }
|