'微信公众号', 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' => []]; } }