SettingModel.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\common\model;
  3. class SettingModel extends BaseModel
  4. {
  5. // 设置表名
  6. protected $name = 'setting';
  7. // 短信配置
  8. const SMS = [
  9. 'sms_type',
  10. 'sms_chuanglan_appkey',
  11. 'sms_chuanglan_secret',
  12. 'sms_mas_url',
  13. 'sms_mas_ecName',
  14. 'sms_mas_apId',
  15. 'sms_mas_secretKey',
  16. 'sms_mas_sign',
  17. ];
  18. const SMS_TYPE = [
  19. 'chuanglan' => '创蓝',
  20. 'mas' => '移动MAS',
  21. 'ali' => '阿里云短信',
  22. ];
  23. const SYSTEM = [
  24. 'site_name',
  25. ];
  26. public static function getConfigValue($code)
  27. {
  28. $res = [];
  29. if (is_array($code)) {
  30. $list = self::where('code', 'in', $code)->select();
  31. if ($list->isEmpty()) {
  32. return [];
  33. }
  34. foreach ($list as $v) {
  35. $res[$v['code']] = $v['value'];
  36. }
  37. } elseif (is_string($code)) {
  38. $info = self::where('code', $code)->find();
  39. if (empty($info)) {
  40. return '';
  41. }
  42. $res = $info['value'];
  43. }
  44. return $res;
  45. }
  46. public static function setConfigValue($code, $value = '')
  47. {
  48. if (is_array($code)) {
  49. foreach ($code as $k => $v) {
  50. self::setConfigValueSingle($k, $v);
  51. }
  52. } elseif (is_string($code)) {
  53. self::setConfigValueSingle($code, $value);
  54. }
  55. }
  56. public static function setConfigValueSingle($code, $value = '')
  57. {
  58. $info = self::where('code', $code)->find();
  59. if (empty($info)) {
  60. self::create(['code' => $code, 'value' => $value]);
  61. } else {
  62. $info->value = $value;
  63. $info->save();
  64. }
  65. }
  66. }