FileLists.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\tenantapi\lists\file;
  15. use app\tenantapi\lists\BaseAdminDataLists;
  16. use app\tenantapi\logic\FileLogic;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\file\TenantFile;
  19. use app\common\service\FileService;
  20. /**
  21. * 文件列表
  22. * Class FileLists
  23. * @package app\tenantapi\lists\file
  24. */
  25. class FileLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 文件搜索条件
  29. * @return \string[][]
  30. * @author 段誉
  31. * @date 2021/12/29 14:27
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['type', 'source'],
  37. '%like%' => ['name']
  38. ];
  39. }
  40. /**
  41. * @notes 额外查询处理
  42. * @return array
  43. * @author 段誉
  44. * @date 2024/2/7 10:26
  45. */
  46. public function queryWhere(): array
  47. {
  48. $where = [];
  49. // 如果cid为0则为未分组
  50. if("0" === $this->params['cid']){
  51. $where[] = ['cid', '=', '0'];
  52. }
  53. if (!empty($this->params['cid'])) {
  54. $cateChild = FileLogic::getCateIds($this->params['cid']);
  55. $cateChild[] = (int)$this->params['cid'];
  56. $where[] = ['cid', 'in', $cateChild];
  57. }
  58. return $where;
  59. }
  60. /**
  61. * @notes 获取文件列表
  62. * @return array
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\DbException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @author 段誉
  67. * @date 2021/12/29 14:27
  68. */
  69. public function lists(): array
  70. {
  71. $lists = (new TenantFile())->field(['id,cid,type,name,uri,create_time'])
  72. ->order('id', 'desc')
  73. ->where($this->searchWhere)
  74. ->where($this->queryWhere())
  75. // ->where('source', FileEnum::SOURCE_ADMIN)
  76. ->limit($this->limitOffset, $this->limitLength)
  77. ->select()
  78. ->toArray();
  79. foreach ($lists as &$item) {
  80. $item['url'] = FileService::getFileUrl($item['uri']);
  81. }
  82. return $lists;
  83. }
  84. /**
  85. * @notes 获取文件数量
  86. * @return int
  87. * @author 段誉
  88. * @date 2021/12/29 14:29
  89. */
  90. public function count(): int
  91. {
  92. return (new TenantFile())->where($this->searchWhere)
  93. ->where($this->queryWhere())
  94. // ->where('source', FileEnum::SOURCE_ADMIN)
  95. ->count();
  96. }
  97. }