BaseConfig.php 2.1 KB

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