ChannelEnum.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <?php
  2. namespace app\common\Enum;
  3. /**
  4. * 渠道枚举类
  5. */
  6. class ChannelEnum
  7. {
  8. // ============ 渠道类型 ============
  9. const CHANNEL_WECHAT_OFFICIAL_ACCOUNT = 'WechatOfficialAccount'; // 微信公众号
  10. const CHANNEL_WECHAT_MINI_PROGRAM = 'WechatMiniProgram'; // 微信小程序
  11. const CHANNEL_IOS_APP = 'IOSApp'; // iOS APP
  12. const CHANNEL_ANDROID_APP = 'AndroidApp'; // Android APP
  13. const CHANNEL_H5 = 'H5'; // H5
  14. const CHANNEL_DOUYIN_MINI_PROGRAM = 'DouyinMiniProgram'; // 抖音小程序
  15. const CHANNEL_PC = 'PC'; // PC
  16. const CHANNEL_QQ_MINI_PROGRAM = 'QQMiniProgram'; // QQ小程序
  17. const CHANNEL_ALIPAY_MINI_PROGRAM = 'AlipayMiniProgram'; // 支付宝小程序
  18. // ============ 渠道分组 ============
  19. const GROUP_WECHAT = 'Wechat'; // 微信生态
  20. const GROUP_MOBILE_APP = 'MobileApp'; // 移动应用
  21. const GROUP_WEB = 'Web'; // 网页端
  22. const GROUP_MINI_PROGRAM = 'MiniProgram'; // 小程序
  23. /**
  24. * 获取渠道映射
  25. */
  26. public static function getChannelMap()
  27. {
  28. return [
  29. // self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => '微信公众号',
  30. self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
  31. self::CHANNEL_IOS_APP => 'iOS APP',
  32. self::CHANNEL_ANDROID_APP => 'Android APP',
  33. //self::CHANNEL_H5 => 'H5',
  34. self::CHANNEL_DOUYIN_MINI_PROGRAM => '抖音小程序',
  35. // self::CHANNEL_PC => 'PC',
  36. // self::CHANNEL_QQ_MINI_PROGRAM => 'QQ小程序',
  37. // self::CHANNEL_ALIPAY_MINI_PROGRAM => '支付宝小程序',
  38. ];
  39. }
  40. /**
  41. * 获取渠道分组映射
  42. */
  43. public static function getChannelGroupMap()
  44. {
  45. return [
  46. self::GROUP_WECHAT => '微信生态',
  47. self::GROUP_MOBILE_APP => '移动应用',
  48. self::GROUP_WEB => '网页端',
  49. self::GROUP_MINI_PROGRAM => '小程序',
  50. ];
  51. }
  52. /**
  53. * 获取按分组组织的渠道
  54. */
  55. public static function getChannelsByGroup()
  56. {
  57. return [
  58. self::GROUP_WECHAT => [
  59. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => '微信公众号',
  60. self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
  61. ],
  62. self::GROUP_MOBILE_APP => [
  63. self::CHANNEL_IOS_APP => 'iOS APP',
  64. self::CHANNEL_ANDROID_APP => 'Android APP',
  65. ],
  66. self::GROUP_WEB => [
  67. self::CHANNEL_H5 => 'H5',
  68. self::CHANNEL_PC => 'PC',
  69. ],
  70. self::GROUP_MINI_PROGRAM => [
  71. self::CHANNEL_WECHAT_MINI_PROGRAM => '微信小程序',
  72. self::CHANNEL_DOUYIN_MINI_PROGRAM => '抖音小程序',
  73. self::CHANNEL_QQ_MINI_PROGRAM => 'QQ小程序',
  74. self::CHANNEL_ALIPAY_MINI_PROGRAM => '支付宝小程序',
  75. ],
  76. ];
  77. }
  78. /**
  79. * 获取渠道标识映射(用于API接口)
  80. */
  81. public static function getChannelCodeMap()
  82. {
  83. return [
  84. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => 'WechatOfficialAccount',
  85. self::CHANNEL_WECHAT_MINI_PROGRAM => 'WechatMiniProgram',
  86. self::CHANNEL_IOS_APP => 'IOSApp',
  87. self::CHANNEL_ANDROID_APP => 'AndroidApp',
  88. self::CHANNEL_H5 => 'H5',
  89. self::CHANNEL_DOUYIN_MINI_PROGRAM => 'DouyinMiniProgram',
  90. self::CHANNEL_PC => 'PC',
  91. self::CHANNEL_QQ_MINI_PROGRAM => 'QQMiniProgram',
  92. self::CHANNEL_ALIPAY_MINI_PROGRAM => 'AlipayMiniProgram',
  93. ];
  94. }
  95. /**
  96. * 获取渠道文本
  97. */
  98. public static function getChannelText($channel)
  99. {
  100. $map = self::getChannelMap();
  101. return $map[$channel] ?? '未知渠道';
  102. }
  103. /**
  104. * 获取渠道标识
  105. */
  106. public static function getChannelCode($channel)
  107. {
  108. $map = self::getChannelCodeMap();
  109. return $map[$channel] ?? 'unknown';
  110. }
  111. /**
  112. * 根据渠道标识获取渠道ID
  113. */
  114. public static function getChannelByCode($code)
  115. {
  116. $map = array_flip(self::getChannelCodeMap());
  117. return $map[$code] ?? null;
  118. }
  119. /**
  120. * 验证渠道是否有效
  121. */
  122. public static function isValidChannel($channel)
  123. {
  124. return array_key_exists($channel, self::getChannelMap());
  125. }
  126. /**
  127. * 判断是否为微信生态渠道
  128. */
  129. public static function isWechatChannel($channel)
  130. {
  131. return in_array($channel, [
  132. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
  133. self::CHANNEL_WECHAT_MINI_PROGRAM,
  134. ]);
  135. }
  136. /**
  137. * 判断是否为小程序渠道
  138. */
  139. public static function isMiniProgramChannel($channel)
  140. {
  141. return in_array($channel, [
  142. self::CHANNEL_WECHAT_MINI_PROGRAM,
  143. self::CHANNEL_DOUYIN_MINI_PROGRAM,
  144. self::CHANNEL_QQ_MINI_PROGRAM,
  145. self::CHANNEL_ALIPAY_MINI_PROGRAM,
  146. ]);
  147. }
  148. /**
  149. * 判断是否为移动端渠道
  150. */
  151. public static function isMobileChannel($channel)
  152. {
  153. return in_array($channel, [
  154. self::CHANNEL_IOS_APP,
  155. self::CHANNEL_ANDROID_APP,
  156. self::CHANNEL_H5,
  157. self::CHANNEL_WECHAT_MINI_PROGRAM,
  158. self::CHANNEL_DOUYIN_MINI_PROGRAM,
  159. self::CHANNEL_QQ_MINI_PROGRAM,
  160. self::CHANNEL_ALIPAY_MINI_PROGRAM,
  161. ]);
  162. }
  163. /**
  164. * 判断是否为桌面端渠道
  165. */
  166. public static function isDesktopChannel($channel)
  167. {
  168. return in_array($channel, [
  169. self::CHANNEL_PC,
  170. ]);
  171. }
  172. /**
  173. * 获取渠道支持的功能
  174. */
  175. public static function getChannelFeatures($channel)
  176. {
  177. $features = [
  178. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
  179. 'payment' => true,
  180. 'share' => true,
  181. 'location' => true,
  182. 'camera' => false,
  183. 'push' => true,
  184. ],
  185. self::CHANNEL_WECHAT_MINI_PROGRAM => [
  186. 'payment' => true,
  187. 'share' => true,
  188. 'location' => true,
  189. 'camera' => true,
  190. 'push' => true,
  191. ],
  192. self::CHANNEL_IOS_APP => [
  193. 'payment' => true,
  194. 'share' => true,
  195. 'location' => true,
  196. 'camera' => true,
  197. 'push' => true,
  198. ],
  199. self::CHANNEL_ANDROID_APP => [
  200. 'payment' => true,
  201. 'share' => true,
  202. 'location' => true,
  203. 'camera' => true,
  204. 'push' => true,
  205. ],
  206. self::CHANNEL_H5 => [
  207. 'payment' => true,
  208. 'share' => true,
  209. 'location' => true,
  210. 'camera' => true,
  211. 'push' => false,
  212. ],
  213. self::CHANNEL_DOUYIN_MINI_PROGRAM => [
  214. 'payment' => true,
  215. 'share' => true,
  216. 'location' => true,
  217. 'camera' => true,
  218. 'push' => true,
  219. ],
  220. self::CHANNEL_PC => [
  221. 'payment' => true,
  222. 'share' => false,
  223. 'location' => false,
  224. 'camera' => false,
  225. 'push' => false,
  226. ],
  227. self::CHANNEL_QQ_MINI_PROGRAM => [
  228. 'payment' => true,
  229. 'share' => true,
  230. 'location' => true,
  231. 'camera' => true,
  232. 'push' => true,
  233. ],
  234. self::CHANNEL_ALIPAY_MINI_PROGRAM => [
  235. 'payment' => true,
  236. 'share' => true,
  237. 'location' => true,
  238. 'camera' => true,
  239. 'push' => true,
  240. ],
  241. ];
  242. return $features[$channel] ?? [];
  243. }
  244. /**
  245. * 检查渠道是否支持某个功能
  246. */
  247. public static function channelSupportsFeature($channel, $feature)
  248. {
  249. $features = self::getChannelFeatures($channel);
  250. return $features[$feature] ?? false;
  251. }
  252. // ============ 支付方式枚举 ============
  253. /**
  254. * 获取支付方式映射
  255. */
  256. public static function getPaymentMap()
  257. {
  258. return PayEnum::getPayMethodList();
  259. }
  260. /**
  261. * 获取渠道支持的支付方式
  262. */
  263. public static function getChannelSupportedPayments($channel)
  264. {
  265. $channelPayments = [
  266. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
  267. PayEnum::METHOD_WECHAT,
  268. PayEnum::METHOD_ALIPAY,
  269. PayEnum::METHOD_BALANCE,
  270. PayEnum::METHOD_COD,
  271. ],
  272. self::CHANNEL_WECHAT_MINI_PROGRAM => [
  273. PayEnum::METHOD_WECHAT,
  274. //PayEnum::METHOD_ALIPAY,
  275. //PayEnum::METHOD_BALANCE,
  276. //PayEnum::METHOD_COD,
  277. ],
  278. self::CHANNEL_DOUYIN_MINI_PROGRAM => [
  279. PayEnum::METHOD_WECHAT,
  280. PayEnum::METHOD_ALIPAY,
  281. // PayEnum::METHOD_BALANCE,
  282. // PayEnum::METHOD_COD,
  283. PayEnum::METHOD_DOUYIN,
  284. ],
  285. self::CHANNEL_IOS_APP => [
  286. PayEnum::METHOD_WECHAT,
  287. PayEnum::METHOD_ALIPAY,
  288. //PayEnum::METHOD_BALANCE,
  289. //PayEnum::METHOD_COD,
  290. ],
  291. self::CHANNEL_ANDROID_APP => [
  292. PayEnum::METHOD_WECHAT,
  293. PayEnum::METHOD_ALIPAY,
  294. //PayEnum::METHOD_BALANCE,
  295. //PayEnum::METHOD_COD,
  296. ],
  297. self::CHANNEL_PC => [
  298. PayEnum::METHOD_ALIPAY,
  299. PayEnum::METHOD_BALANCE,
  300. PayEnum::METHOD_OFFLINE,
  301. PayEnum::METHOD_COD,
  302. ],
  303. self::CHANNEL_QQ_MINI_PROGRAM => [
  304. PayEnum::METHOD_WECHAT,
  305. PayEnum::METHOD_ALIPAY,
  306. PayEnum::METHOD_BALANCE,
  307. PayEnum::METHOD_COD,
  308. ],
  309. self::CHANNEL_ALIPAY_MINI_PROGRAM => [
  310. PayEnum::METHOD_WECHAT,
  311. PayEnum::METHOD_ALIPAY,
  312. PayEnum::METHOD_BALANCE,
  313. PayEnum::METHOD_COD,
  314. ],
  315. ];
  316. return $channelPayments[$channel] ?? [PayEnum::METHOD_BALANCE];
  317. }
  318. /**
  319. * 检查渠道是否支持指定支付方式
  320. */
  321. public static function channelSupportsPayment($channel, $payment)
  322. {
  323. $supportedPayments = self::getChannelSupportedPayments($channel);
  324. return in_array($payment, $supportedPayments);
  325. }
  326. /**
  327. * 获取渠道推荐的支付方式(按优先级排序)
  328. */
  329. public static function getChannelRecommendedPayments($channel)
  330. {
  331. $recommendedPayments = [
  332. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT => [
  333. PayEnum::METHOD_WECHAT,
  334. PayEnum::METHOD_BALANCE,
  335. ],
  336. self::CHANNEL_WECHAT_MINI_PROGRAM => [
  337. PayEnum::METHOD_WECHAT,
  338. PayEnum::METHOD_BALANCE,
  339. ],
  340. self::CHANNEL_IOS_APP => [
  341. PayEnum::METHOD_WECHAT,
  342. PayEnum::METHOD_ALIPAY,
  343. PayEnum::METHOD_BALANCE
  344. ],
  345. self::CHANNEL_ANDROID_APP => [
  346. PayEnum::METHOD_ALIPAY,
  347. PayEnum::METHOD_WECHAT,
  348. PayEnum::METHOD_BALANCE
  349. ],
  350. self::CHANNEL_PC => [
  351. PayEnum::METHOD_ALIPAY,
  352. PayEnum::METHOD_OFFLINE,
  353. PayEnum::METHOD_BALANCE
  354. ],
  355. self::CHANNEL_QQ_MINI_PROGRAM => [
  356. PayEnum::METHOD_WECHAT,
  357. PayEnum::METHOD_BALANCE
  358. ],
  359. self::CHANNEL_ALIPAY_MINI_PROGRAM => [
  360. PayEnum::METHOD_WECHAT,
  361. PayEnum::METHOD_ALIPAY,
  362. PayEnum::METHOD_BALANCE
  363. ],
  364. ];
  365. return $recommendedPayments[$channel] ?? [PayEnum::METHOD_BALANCE];
  366. }
  367. /**
  368. * 获取支付方式的渠道兼容性
  369. */
  370. public static function getPaymentChannelCompatibility($payment)
  371. {
  372. $compatibility = [
  373. PayEnum::METHOD_WECHAT => [
  374. 'supported' => [
  375. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
  376. self::CHANNEL_WECHAT_MINI_PROGRAM,
  377. self::CHANNEL_IOS_APP,
  378. self::CHANNEL_ANDROID_APP,
  379. self::CHANNEL_H5,
  380. ],
  381. 'recommended' => [
  382. self::CHANNEL_WECHAT_OFFICIAL_ACCOUNT,
  383. self::CHANNEL_WECHAT_MINI_PROGRAM,
  384. ],
  385. ],
  386. PayEnum::METHOD_ALIPAY => [
  387. 'supported' => [
  388. self::CHANNEL_IOS_APP,
  389. self::CHANNEL_ANDROID_APP,
  390. self::CHANNEL_H5,
  391. self::CHANNEL_PC,
  392. self::CHANNEL_DOUYIN_MINI_PROGRAM,
  393. self::CHANNEL_ALIPAY_MINI_PROGRAM,
  394. ],
  395. 'recommended' => [
  396. self::CHANNEL_ALIPAY_MINI_PROGRAM,
  397. self::CHANNEL_PC,
  398. self::CHANNEL_H5,
  399. ],
  400. ],
  401. PayEnum::METHOD_BALANCE => [
  402. 'supported' => array_keys(self::getChannelMap()),
  403. 'recommended' => array_keys(self::getChannelMap()),
  404. ],
  405. PayEnum::METHOD_OFFLINE => [
  406. 'supported' => [self::CHANNEL_PC],
  407. 'recommended' => [self::CHANNEL_PC],
  408. ],
  409. ];
  410. return $compatibility[$payment] ?? ['supported' => [], 'recommended' => []];
  411. }
  412. }