SystemConfig.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 'insurance_agreement'=>'保单协议'
  19. ];
  20. const Field_textarea = 0,Filed_richText = 1,Field_Json = 2,
  21. Field_Switch = 3,Field_Time = 4,Field_File = 5,
  22. Field_Checkbox = 6,Field_Json_Array = 7,Field_Image = 8;
  23. private static $_fieldType = [
  24. self::Field_textarea =>'纯文本',
  25. self::Filed_richText =>'富文本',
  26. self::Field_Json =>'JSON',
  27. self::Field_Switch =>'开关',
  28. self::Field_Time =>'时间',
  29. self::Field_File =>'文件',
  30. self::Field_Checkbox =>'选择框',
  31. self::Field_Json_Array =>'数组JSON',
  32. self::Field_Image =>'图片',
  33. ];
  34. protected static function getType(){
  35. return self::$_fieldType;
  36. }
  37. protected static function getGroup(){
  38. return self::$groups;
  39. }
  40. /**
  41. * @param String $group
  42. * @param String $key
  43. * @param String $default
  44. * @return array|String
  45. */
  46. public static function get(string $group, string $key = '', string $default = "")
  47. {
  48. $query = self::where('group', $group);
  49. if ($key) {
  50. $res = $query->where('key', $key)->first(['value'])->value ?? $default;
  51. return $res;
  52. } else {
  53. $res = $query->get(['key', 'value']);
  54. $arr = [];
  55. foreach ($res as $index => $item) {
  56. $arr[$item['key']] = $item['value'];
  57. }
  58. return $arr;
  59. }
  60. }
  61. /**
  62. * @param String $group
  63. * @param String $key
  64. * @param String $value
  65. * @return int
  66. */
  67. public static function set(string $group, string $key, string $value)
  68. {
  69. return self::where([['group', $group], ['key', $key]])->update(['value' => $value]);
  70. }
  71. }