BaseConfig.php 3.1 KB

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