123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- <?php
- namespace app\common\Enum;
- /**
- * 渠道枚举类
- */
- class ChannelEnum
- {
- // ============ 渠道类型 ============
- const CHANNEL_WECHAT_OFFICIAL_ACCOUNT = 'WechatOfficialAccount'; // 微信公众号
- const CHANNEL_WECHAT_MINI_PROGRAM = 'WechatMiniProgram'; // 微信小程序
- const CHANNEL_IOS_APP = 'IOSApp'; // iOS APP
- const CHANNEL_ANDROID_APP = 'AndroidApp'; // Android APP
- const CHANNEL_H5 = 'H5'; // H5
- const CHANNEL_DOUYIN_MINI_PROGRAM = 'DouyinMiniProgram'; // 抖音小程序
- const CHANNEL_PC = 'PC'; // PC
- const CHANNEL_QQ_MINI_PROGRAM = 'QQMiniProgram'; // QQ小程序
- const CHANNEL_ALIPAY_MINI_PROGRAM = 'AlipayMiniProgram'; // 支付宝小程序
- // ============ 渠道分组 ============
- const GROUP_WECHAT = 'Wechat'; // 微信生态
- const GROUP_MOBILE_APP = 'MobileApp'; // 移动应用
- const GROUP_WEB = 'Web'; // 网页端
- const GROUP_MINI_PROGRAM = 'MiniProgram'; // 小程序
- /**
- * 获取渠道映射
- */
- public static function getChannelMap()
- {
- return [
- // self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => '微信公众号',
- self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
- self::CHANNEL_IOS_APP => 'iOS APP',
- self::CHANNEL_ANDROID_APP => 'Android APP',
- //self::CHANNEL_H5 => 'H5',
- self::CHANNEL_DOUYIN_MINI_PROGRAM => '抖音小程序',
- // self::CHANNEL_PC => 'PC',
- // self::CHANNEL_QQ_MINI_PROGRAM => 'QQ小程序',
- // self::CHANNEL_ALIPAY_MINI_PROGRAM => '支付宝小程序',
- ];
- }
- /**
- * 获取渠道分组映射
- */
- public static function getChannelGroupMap()
- {
- return [
- self::GROUP_WECHAT => '微信生态',
- self::GROUP_MOBILE_APP => '移动应用',
- self::GROUP_WEB => '网页端',
- self::GROUP_MINI_PROGRAM => '小程序',
- ];
- }
- /**
- * 获取按分组组织的渠道
- */
- public static function getChannelsByGroup()
- {
- return [
- self::GROUP_WECHAT => [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => '微信公众号',
- self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
- ],
- self::GROUP_MOBILE_APP => [
- self::CHANNEL_IOS_APP => 'iOS APP',
- self::CHANNEL_ANDROID_APP => 'Android APP',
- ],
- self::GROUP_WEB => [
- self::CHANNEL_H5 => 'H5',
- self::CHANNEL_PC => 'PC',
- ],
- self::GROUP_MINI_PROGRAM => [
- self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
- self::CHANNEL_DOUYIN_MINI_PROGRAM => '抖音小程序',
- self::CHANNEL_QQ_MINI_PROGRAM => 'QQ小程序',
- self::CHANNEL_ALIPAY_MINI_PROGRAM => '支付宝小程序',
- ],
- ];
- }
- /**
- * 获取渠道标识映射(用于API接口)
- */
- public static function getChannelCodeMap()
- {
- return [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => 'WechatOfficialAccount',
- self::CHANNEL_WECHAT_MINI_PROGRAM => 'WechatMiniProgram',
- self::CHANNEL_IOS_APP => 'IOSApp',
- self::CHANNEL_ANDROID_APP => 'AndroidApp',
- self::CHANNEL_H5 => 'H5',
- self::CHANNEL_DOUYIN_MINI_PROGRAM => 'DouyinMiniProgram',
- self::CHANNEL_PC => 'PC',
- self::CHANNEL_QQ_MINI_PROGRAM => 'QQMiniProgram',
- self::CHANNEL_ALIPAY_MINI_PROGRAM => 'AlipayMiniProgram',
- ];
- }
- /**
- * 获取渠道文本
- */
- public static function getChannelText($channel)
- {
- $map = self::getChannelMap();
- return $map[$channel] ?? '未知渠道';
- }
- /**
- * 获取渠道标识
- */
- public static function getChannelCode($channel)
- {
- $map = self::getChannelCodeMap();
- return $map[$channel] ?? 'unknown';
- }
- /**
- * 根据渠道标识获取渠道ID
- */
- public static function getChannelByCode($code)
- {
- $map = array_flip(self::getChannelCodeMap());
- return $map[$code] ?? null;
- }
- /**
- * 验证渠道是否有效
- */
- public static function isValidChannel($channel)
- {
- return array_key_exists($channel, self::getChannelMap());
- }
- /**
- * 判断是否为微信生态渠道
- */
- public static function isWechatChannel($channel)
- {
- return in_array($channel, [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
- self::CHANNEL_WECHAT_MINI_PROGRAM,
- ]);
- }
- /**
- * 判断是否为小程序渠道
- */
- public static function isMiniProgramChannel($channel)
- {
- return in_array($channel, [
- self::CHANNEL_WECHAT_MINI_PROGRAM,
- self::CHANNEL_DOUYIN_MINI_PROGRAM,
- self::CHANNEL_QQ_MINI_PROGRAM,
- self::CHANNEL_ALIPAY_MINI_PROGRAM,
- ]);
- }
- /**
- * 判断是否为移动端渠道
- */
- public static function isMobileChannel($channel)
- {
- return in_array($channel, [
- self::CHANNEL_IOS_APP,
- self::CHANNEL_ANDROID_APP,
- self::CHANNEL_H5,
- self::CHANNEL_WECHAT_MINI_PROGRAM,
- self::CHANNEL_DOUYIN_MINI_PROGRAM,
- self::CHANNEL_QQ_MINI_PROGRAM,
- self::CHANNEL_ALIPAY_MINI_PROGRAM,
- ]);
- }
- /**
- * 判断是否为桌面端渠道
- */
- public static function isDesktopChannel($channel)
- {
- return in_array($channel, [
- self::CHANNEL_PC,
- ]);
- }
- /**
- * 获取渠道支持的功能
- */
- public static function getChannelFeatures($channel)
- {
- $features = [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => false,
- 'push' => true,
- ],
- self::CHANNEL_WECHAT_MINI_PROGRAM => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- self::CHANNEL_IOS_APP => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- self::CHANNEL_ANDROID_APP => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- self::CHANNEL_H5 => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => false,
- ],
- self::CHANNEL_DOUYIN_MINI_PROGRAM => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- self::CHANNEL_PC => [
- 'payment' => true,
- 'share' => false,
- 'location' => false,
- 'camera' => false,
- 'push' => false,
- ],
- self::CHANNEL_QQ_MINI_PROGRAM => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- self::CHANNEL_ALIPAY_MINI_PROGRAM => [
- 'payment' => true,
- 'share' => true,
- 'location' => true,
- 'camera' => true,
- 'push' => true,
- ],
- ];
- return $features[$channel] ?? [];
- }
- /**
- * 检查渠道是否支持某个功能
- */
- public static function channelSupportsFeature($channel, $feature)
- {
- $features = self::getChannelFeatures($channel);
- return $features[$feature] ?? false;
- }
- // ============ 支付方式枚举 ============
- /**
- * 获取支付方式映射
- */
- public static function getPaymentMap()
- {
- return PayEnum::getPayMethodList();
- }
- /**
- * 获取渠道支持的支付方式
- */
- public static function getChannelSupportedPayments($channel)
- {
- $channelPayments = [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE,
- PayEnum::METHOD_COD,
- ],
- self::CHANNEL_WECHAT_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- //PayEnum::METHOD_ALIPAY,
- //PayEnum::METHOD_BALANCE,
- //PayEnum::METHOD_COD,
- ],
- self::CHANNEL_DOUYIN_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- // PayEnum::METHOD_BALANCE,
- // PayEnum::METHOD_COD,
- PayEnum::METHOD_DOUYIN,
- ],
- self::CHANNEL_IOS_APP => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- //PayEnum::METHOD_BALANCE,
- //PayEnum::METHOD_COD,
- ],
- self::CHANNEL_ANDROID_APP => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- //PayEnum::METHOD_BALANCE,
- //PayEnum::METHOD_COD,
- ],
- self::CHANNEL_PC => [
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE,
- PayEnum::METHOD_OFFLINE,
- PayEnum::METHOD_COD,
- ],
- self::CHANNEL_QQ_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE,
- PayEnum::METHOD_COD,
- ],
- self::CHANNEL_ALIPAY_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE,
- PayEnum::METHOD_COD,
- ],
- ];
- return $channelPayments[$channel] ?? [PayEnum::METHOD_BALANCE];
- }
- /**
- * 检查渠道是否支持指定支付方式
- */
- public static function channelSupportsPayment($channel, $payment)
- {
- $supportedPayments = self::getChannelSupportedPayments($channel);
- return in_array($payment, $supportedPayments);
- }
- /**
- * 获取渠道推荐的支付方式(按优先级排序)
- */
- public static function getChannelRecommendedPayments($channel)
- {
- $recommendedPayments = [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_BALANCE,
- ],
- self::CHANNEL_WECHAT_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_BALANCE,
- ],
- self::CHANNEL_IOS_APP => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE
- ],
- self::CHANNEL_ANDROID_APP => [
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_BALANCE
- ],
- self::CHANNEL_PC => [
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_OFFLINE,
- PayEnum::METHOD_BALANCE
- ],
- self::CHANNEL_QQ_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_BALANCE
- ],
- self::CHANNEL_ALIPAY_MINI_PROGRAM => [
- PayEnum::METHOD_WECHAT,
- PayEnum::METHOD_ALIPAY,
- PayEnum::METHOD_BALANCE
- ],
- ];
- return $recommendedPayments[$channel] ?? [PayEnum::METHOD_BALANCE];
- }
- /**
- * 获取支付方式的渠道兼容性
- */
- public static function getPaymentChannelCompatibility($payment)
- {
- $compatibility = [
- PayEnum::METHOD_WECHAT => [
- 'supported' => [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
- self::CHANNEL_WECHAT_MINI_PROGRAM,
- self::CHANNEL_IOS_APP,
- self::CHANNEL_ANDROID_APP,
- self::CHANNEL_H5,
- ],
- 'recommended' => [
- self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
- self::CHANNEL_WECHAT_MINI_PROGRAM,
- ],
- ],
- PayEnum::METHOD_ALIPAY => [
- 'supported' => [
- self::CHANNEL_IOS_APP,
- self::CHANNEL_ANDROID_APP,
- self::CHANNEL_H5,
- self::CHANNEL_PC,
- self::CHANNEL_DOUYIN_MINI_PROGRAM,
- self::CHANNEL_ALIPAY_MINI_PROGRAM,
- ],
- 'recommended' => [
- self::CHANNEL_ALIPAY_MINI_PROGRAM,
- self::CHANNEL_PC,
- self::CHANNEL_H5,
- ],
- ],
- PayEnum::METHOD_BALANCE => [
- 'supported' => array_keys(self::getChannelMap()),
- 'recommended' => array_keys(self::getChannelMap()),
- ],
- PayEnum::METHOD_OFFLINE => [
- 'supported' => [self::CHANNEL_PC],
- 'recommended' => [self::CHANNEL_PC],
- ],
- ];
- return $compatibility[$payment] ?? ['supported' => [], 'recommended' => []];
- }
- }
|