SystemAttachmentCategory.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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)
  78. {
  79. $model = new self();
  80. if ($id == 0)
  81. $model->where('pid', $id);
  82. return sort_list_tier($model->select()->toArray());
  83. }
  84. /**
  85. * 获取单条信息
  86. * @param $att_id
  87. * @return mixed
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. * @throws \think\exception\DbException
  91. */
  92. public static function getinfo($att_id)
  93. {
  94. $model = new self;
  95. $where['att_id'] = $att_id;
  96. return $model->where($where)->select()->toArray()[0];
  97. }
  98. }