SystemConfig.php 2.0 KB

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