SmsConfigLogic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\notice;
  20. use app\common\enum\SmsEnum;
  21. use app\common\logic\BaseLogic;
  22. use app\common\service\ConfigService;
  23. /**
  24. * 短信配置逻辑层
  25. * Class SmsConfigLogic
  26. * @package app\adminapi\logic\notice
  27. */
  28. class SmsConfigLogic extends BaseLogic
  29. {
  30. /**
  31. * @notes 获取短信配置
  32. * @return array
  33. * @author Tab
  34. * @date 2021/8/19 11:54
  35. */
  36. public static function getConfig()
  37. {
  38. $config = [
  39. 'ali' => ConfigService::get('sms', 'ali'),
  40. 'tencent' => ConfigService::get('sms', 'tencent'),
  41. ];
  42. return $config;
  43. }
  44. /**
  45. * @notes 短信配置
  46. * @param $params
  47. * @return bool
  48. * @author Tab
  49. * @date 2021/8/19 14:31
  50. */
  51. public static function setConfig($params)
  52. {
  53. $type = $params['type'];
  54. unset($params['type']);
  55. $params['name'] = self::getNameDesc(strtoupper($type));
  56. ConfigService::set('sms', $type, $params);
  57. $default = ConfigService::get('sms', 'engine', false);
  58. if($params['status'] == 1 && $default === false) {
  59. // 启用当前短信配置 并 设置当前短信配置为默认
  60. ConfigService::set('sms', 'engine', strtoupper($type));
  61. return true;
  62. }
  63. if($params['status'] == 1 && $default != strtoupper($type)) {
  64. // 找到默认短信配置
  65. $defaultConfig = ConfigService::get('sms', strtolower($default));
  66. // 状态置为禁用 并 更新
  67. $defaultConfig['status'] = 0;
  68. ConfigService::set('sms', strtolower($default), $defaultConfig);
  69. // 设置当前短信配置为默认
  70. ConfigService::set('sms', 'engine', strtoupper($type));
  71. return true;
  72. }
  73. }
  74. /**
  75. * @notes 查看短信配置详情
  76. * @param $params
  77. * @return array|int|mixed|string
  78. * @author Tab
  79. * @date 2021/8/19 13:59
  80. */
  81. public static function detail($params)
  82. {
  83. return ConfigService::get('sms', $params['type']);
  84. }
  85. /**
  86. * @notes 获取短信平台名称
  87. * @param $value
  88. * @return string
  89. * @author Tab
  90. * @date 2021/8/19 14:19
  91. */
  92. public static function getNameDesc($value)
  93. {
  94. $desc = [
  95. 'ALI' => '阿里云短信',
  96. 'TENCENT' => '腾讯云短信',
  97. ];
  98. return $desc[$value] ?? '';
  99. }
  100. }