FileLists.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\adminapi\lists\file;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\adminapi\logic\FileLogic;
  17. use app\common\enum\FileEnum;
  18. use app\common\lists\ListsSearchInterface;
  19. use app\common\model\file\File;
  20. use app\common\model\file\FileCate;
  21. use app\common\service\FileService;
  22. /**
  23. * 文件列表
  24. * Class FileLists
  25. * @package app\adminapi\lists\file
  26. */
  27. class FileLists extends BaseAdminDataLists implements ListsSearchInterface
  28. {
  29. /**
  30. * @notes 文件搜索条件
  31. * @return \string[][]
  32. * @author 段誉
  33. * @date 2021/12/29 14:27
  34. */
  35. public function setSearch(): array
  36. {
  37. return [
  38. '=' => ['type', 'source'],
  39. '%like%' => ['name']
  40. ];
  41. }
  42. /**
  43. * @notes 额外查询处理
  44. * @return array
  45. * @author 段誉
  46. * @date 2024/2/7 10:26
  47. */
  48. public function queryWhere(): array
  49. {
  50. $where = [];
  51. if (!empty($this->params['cid'])) {
  52. $cateChild = FileLogic::getCateIds($this->params['cid']);
  53. array_push($cateChild, $this->params['cid']);
  54. $where[] = ['cid', 'in', $cateChild];
  55. }
  56. return $where;
  57. }
  58. /**
  59. * @notes 获取文件列表
  60. * @return array
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @author 段誉
  65. * @date 2021/12/29 14:27
  66. */
  67. public function lists(): array
  68. {
  69. $lists = (new File())->field(['id,cid,type,name,uri,create_time'])
  70. ->order('id', 'desc')
  71. ->where($this->searchWhere)
  72. ->where($this->queryWhere())
  73. // ->where('source', FileEnum::SOURCE_ADMIN)
  74. ->limit($this->limitOffset, $this->limitLength)
  75. ->select()
  76. ->toArray();
  77. foreach ($lists as &$item) {
  78. $item['url'] = FileService::getFileUrl($item['uri']);
  79. }
  80. return $lists;
  81. }
  82. /**
  83. * @notes 获取文件数量
  84. * @return int
  85. * @author 段誉
  86. * @date 2021/12/29 14:29
  87. */
  88. public function count(): int
  89. {
  90. return (new File())->where($this->searchWhere)
  91. ->where($this->queryWhere())
  92. // ->where('source', FileEnum::SOURCE_ADMIN)
  93. ->count();
  94. }
  95. }