SystemConfig.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * Class System_Config
  6. * @package App
  7. */
  8. class SystemConfig extends Model
  9. {
  10. //
  11. protected $table = "system_config";
  12. protected $guarded = [];
  13. static $groups = [
  14. 'ali_config'=>'阿里云',
  15. 'docter_config'=>'医生',
  16. 'user_config'=>'用户',
  17. 'schedule_config'=>'排班'
  18. ];
  19. const Field_textarea = 0,Filed_richText = 1,Field_Json = 2,
  20. Field_Switch = 3,Field_Time = 4,Field_File = 5,
  21. Field_Checkbox = 6,Field_Json_Array = 7,Field_Image = 8;
  22. private static $_fieldType = [
  23. self::Field_textarea =>'纯文本',
  24. self::Filed_richText =>'富文本',
  25. self::Field_Json =>'JSON',
  26. self::Field_Switch =>'开关',
  27. self::Field_Time =>'时间',
  28. self::Field_File =>'文件',
  29. self::Field_Checkbox =>'选择框',
  30. self::Field_Json_Array =>'数组JSON',
  31. self::Field_Image =>'图片',
  32. ];
  33. protected static function getType(){
  34. return self::$_fieldType;
  35. }
  36. protected static function getGroup(){
  37. return self::$groups;
  38. }
  39. /**
  40. * @param String $group
  41. * @param String $key
  42. * @param String $default
  43. * @return array|String
  44. */
  45. public static function get(string $group, string $key = '', string $default = "")
  46. {
  47. $query = self::where('group', $group);
  48. if ($key) {
  49. $res = $query->where('key', $key)->first(['value'])->value ?? $default;
  50. return $res;
  51. } else {
  52. $res = $query->get(['key', 'value']);
  53. $arr = [];
  54. foreach ($res as $index => $item) {
  55. $arr[$item['key']] = $item['value'];
  56. }
  57. return $arr;
  58. }
  59. }
  60. /**
  61. * @param String $group
  62. * @param String $key
  63. * @param String $value
  64. * @return int
  65. */
  66. public static function set(string $group, string $key, string $value)
  67. {
  68. return self::where([['group', $group], ['key', $key]])->update(['value' => $value]);
  69. }
  70. }