SystemAttachmentCategory.php 3.1 KB

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