BaseConfig.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * Class System_Config
  6. *
  7. * @package App
  8. * @property string $group 配置组名
  9. * @property string $name 名称
  10. * @property string $key 配置名
  11. * @property string|null $value 说明
  12. * @property string|null $comment 说明
  13. * @property int|null $sort 排序
  14. * @property int $expiration
  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. * @mixin \Eloquent
  26. */
  27. class BaseConfig extends Model
  28. {
  29. //
  30. protected $table = "base_config";
  31. protected $guarded = [];
  32. 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. 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. return self::$_fieldType;
  56. }
  57. /**
  58. * @param String $group
  59. * @param String $key
  60. * @param String $default
  61. * @return array|String
  62. */
  63. public static function get(string $group, string $key = '', string $default = "")
  64. {
  65. $query = self::where('group', $group);
  66. if ($key) {
  67. $res = $query->where('key', $key)->first(['value'])->value ?? $default;
  68. return $res;
  69. } else {
  70. $res = $query->get(['key', 'value']);
  71. $arr = [];
  72. foreach ($res as $index => $item) {
  73. $arr[$item['key']] = $item['value'];
  74. }
  75. return $arr;
  76. }
  77. }
  78. /**
  79. * @param String $group
  80. * @param String $key
  81. * @param String $value
  82. * @return int
  83. */
  84. public static function set(string $group, string $key, string $value)
  85. {
  86. return self::where([['group', $group], ['key', $key]])->update(['value' => $value]);
  87. }
  88. }