SettingModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model;
  3. class SettingModel extends BaseModel
  4. {
  5. // 设置表名
  6. protected $table = 'setting';
  7. // 短信配置
  8. const SMS = [
  9. 'sms_chuanglan_appkey',
  10. 'sms_chuanglan_secret',
  11. ];
  12. const SYSTEM = [
  13. 'site_name',
  14. ];
  15. public static function getConfigValue($code)
  16. {
  17. $res = [];
  18. if (is_array($code)) {
  19. $list = self::where('code', 'in', $code)->select();
  20. if ($list->isEmpty()) {
  21. return [];
  22. }
  23. foreach ($list as $v) {
  24. $res[$v['code']] = $v['value'];
  25. }
  26. } elseif (is_string($code)) {
  27. $info = self::where('code', $code)->find();
  28. if (empty($info)) {
  29. return '';
  30. }
  31. $res = $info['value'];
  32. }
  33. return $res;
  34. }
  35. public static function setConfigValue($code, $value = '')
  36. {
  37. if (is_array($code)) {
  38. foreach ($code as $k => $v) {
  39. self::setConfigValueSingle($k, $v);
  40. }
  41. } elseif (is_string($code)) {
  42. self::setConfigValueSingle($code, $value);
  43. }
  44. }
  45. public static function setConfigValueSingle($code, $value = '')
  46. {
  47. $info = self::where('code', $code)->find();
  48. if (empty($info)) {
  49. self::create(['code' => $code, 'value' => $value]);
  50. } else {
  51. $info->value = $value;
  52. $info->save();
  53. }
  54. }
  55. }