SettingModel.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ];
  13. const SMS_TYPE = [
  14. 'chuanglan\\Chuanglan' => '创蓝'
  15. ];
  16. const SYSTEM = [
  17. 'site_name',
  18. ];
  19. public static function getConfigValue($code)
  20. {
  21. $res = [];
  22. if (is_array($code)) {
  23. $list = self::where('code', 'in', $code)->select();
  24. if ($list->isEmpty()) {
  25. return [];
  26. }
  27. foreach ($list as $v) {
  28. $res[$v['code']] = $v['value'];
  29. }
  30. } elseif (is_string($code)) {
  31. $info = self::where('code', $code)->find();
  32. if (empty($info)) {
  33. return '';
  34. }
  35. $res = $info['value'];
  36. }
  37. return $res;
  38. }
  39. public static function setConfigValue($code, $value = '')
  40. {
  41. if (is_array($code)) {
  42. foreach ($code as $k => $v) {
  43. self::setConfigValueSingle($k, $v);
  44. }
  45. } elseif (is_string($code)) {
  46. self::setConfigValueSingle($code, $value);
  47. }
  48. }
  49. public static function setConfigValueSingle($code, $value = '')
  50. {
  51. $info = self::where('code', $code)->find();
  52. if (empty($info)) {
  53. self::create(['code' => $code, 'value' => $value]);
  54. } else {
  55. $info->value = $value;
  56. $info->save();
  57. }
  58. }
  59. }