BaseSettingsModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use App\Models\BaseModel;
  4. /**
  5. * @description 配置列表
  6. * @author system;
  7. * @version 1.0
  8. * @date 2017-05-31 04:56:09
  9. *
  10. */
  11. class BaseSettingsModel extends BaseModel
  12. {
  13. /**
  14. * 数据表名
  15. *
  16. * @var string
  17. *
  18. */
  19. protected $table = 'base_settings';
  20. /**
  21. 主键
  22. */
  23. protected $primaryKey = 'id';
  24. //分页
  25. protected $perPage = PAGE_NUMS;
  26. /**
  27. * 可以被集体附值的表的字段
  28. *
  29. * @var string
  30. */
  31. protected $fillable = [
  32. 'appid',
  33. 'key',
  34. 'value',
  35. 'sort',
  36. 'category',
  37. 'pid',
  38. 'status'
  39. ];
  40. public static function _tree($data, $pid = 0, $level = 0) {
  41. $result = [];
  42. foreach ($data as $k => $v) {
  43. if ($v->pid == $pid) {
  44. $node = [
  45. 'level' => $level,
  46. 'data' => $v,
  47. 'children' => self::_tree($data, $v->id, $level + 1),
  48. ];
  49. $result[] = $node;
  50. }
  51. }
  52. return $result;
  53. }
  54. public static function tree() {
  55. return self::_tree(self::all(), 0, 0);
  56. }
  57. }