SettingModel.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\common\model;
  3. class SettingModel extends BaseModel
  4. {
  5. // 设置表名
  6. protected $name = 'setting';
  7. // 短信配置
  8. const SMS = [
  9. 'sms_chuanglan_appkey',
  10. 'sms_chuanglan_secret',
  11. 'sms_type',
  12. 'sms_verify_expire',
  13. ];
  14. const SYSTEM = [
  15. 'site_name',
  16. ];
  17. const SMS_TYPE = [
  18. ['value' => '\\chuanglan\\Chuanglan', 'text' => '创蓝短信'],
  19. ];
  20. const TALENT = [
  21. 'talent_level_1',
  22. 'talent_level_2',
  23. 'talent_level_3',
  24. 'talent_level_4',
  25. 'talent_level_5',
  26. 'talent_level_6',
  27. 'talent_level_7',
  28. 'talent_industry_trade',
  29. 'talent_industry_goods',
  30. 'talent_industry_clothing',
  31. 'talent_industry_drug',
  32. 'talent_industry_medical',
  33. 'talent_industry_hotel',
  34. 'talent_industry_traffic',
  35. 'talent_industry_other',
  36. 'talent_age_1',
  37. 'talent_age_2',
  38. 'talent_age_3',
  39. 'talent_age_4',
  40. 'talent_education_1',
  41. 'talent_education_2',
  42. 'talent_education_3',
  43. 'talent_total',
  44. ];
  45. public static function getConfigValue($code)
  46. {
  47. $res = [];
  48. if (is_array($code)) {
  49. $list = self::where('code', 'in', $code)->select();
  50. if ($list->isEmpty()) {
  51. return [];
  52. }
  53. foreach ($list as $v) {
  54. $res[$v['code']] = $v['value'];
  55. }
  56. } elseif (is_string($code)) {
  57. $info = self::where('code', $code)->find();
  58. if (empty($info)) {
  59. return '';
  60. }
  61. $res = $info['value'];
  62. }
  63. return $res;
  64. }
  65. public static function setConfigValue($code, $value = '')
  66. {
  67. if (is_array($code)) {
  68. foreach ($code as $k => $v) {
  69. self::setConfigValueSingle($k, $v);
  70. }
  71. } elseif (is_string($code)) {
  72. self::setConfigValueSingle($code, $value);
  73. }
  74. }
  75. public static function setConfigValueSingle($code, $value = '')
  76. {
  77. $info = self::where('code', $code)->find();
  78. if (empty($info)) {
  79. self::create(['code' => $code, 'value' => $value]);
  80. } else {
  81. $info->value = $value;
  82. $info->save();
  83. }
  84. }
  85. }