SystemAttachmentCategory.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\model\system;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. /**
  6. * 附件目录
  7. * Class SystemAttachmentCategory
  8. * @package app\admin\model\system
  9. */
  10. class SystemAttachmentCategory extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'system_attachment_category';
  22. use ModelTrait;
  23. /**
  24. * 添加分类
  25. * @param $name
  26. * @param $att_size
  27. * @param $att_type
  28. * @param $att_dir
  29. * @param string $satt_dir
  30. * @param int $pid
  31. * @return SystemAttachmentCategory|\think\Model
  32. */
  33. public static function Add($name, $att_size, $att_type, $att_dir, $satt_dir = '', $pid = 0)
  34. {
  35. $data['name'] = $name;
  36. $data['att_dir'] = $att_dir;
  37. $data['satt_dir'] = $satt_dir;
  38. $data['att_size'] = $att_size;
  39. $data['att_type'] = $att_type;
  40. $data['time'] = time();
  41. $data['pid'] = $pid;
  42. return self::create($data);
  43. }
  44. /**
  45. * 获取分类图
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public static function getAll($name)
  52. {
  53. $model = new self;
  54. if ($name) $model = $model->where('name', 'LIKE', "%$name%");
  55. return self::tidyMenuTier($model->select(), 0);
  56. }
  57. public static function tidyMenuTier($menusList, $pid = 0, $navList = [])
  58. {
  59. foreach ($menusList as $k => $menu) {
  60. $menu = $menu->getData();
  61. if ($menu['pid'] == $pid) {
  62. unset($menusList[$k]);
  63. $menu['child'] = self::tidyMenuTier($menusList, $menu['id']);
  64. $navList[] = $menu;
  65. }
  66. }
  67. return $navList;
  68. }
  69. /**
  70. * 获取分类下拉列表
  71. * @param int $id
  72. * @return array
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. */
  77. public static function getCateList($id = 10000, $type = 0)
  78. {
  79. $model = new self();
  80. if ($id == 0)
  81. $model->where('pid', $id);
  82. if ($type == 1)
  83. return sort_list_tier($model->where('pid', 0)->select()->toArray());
  84. return sort_list_tier($model->select()->toArray());
  85. }
  86. /**
  87. * 获取单条信息
  88. * @param $att_id
  89. * @return mixed
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. */
  94. public static function getinfo($att_id)
  95. {
  96. $model = new self;
  97. $where['att_id'] = $att_id;
  98. return $model->where($where)->select()->toArray()[0];
  99. }
  100. }