FileLists.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\lists;
  20. use app\common\enum\FileEnum;
  21. use app\common\lists\ListsSearchInterface;
  22. use app\common\model\File;
  23. use app\common\service\FileService;
  24. use app\common\service\UrlService;
  25. class FileLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 文件搜索条件
  29. * @return array
  30. * @author 张无忌
  31. * @date 2021/7/29 18:11
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['type', 'cid'],
  37. '%like%' => ['name']
  38. ];
  39. }
  40. /**
  41. * @notes 获取文件列表
  42. * @return array
  43. * @throws @\think\db\exception\DataNotFoundException
  44. * @throws @\think\db\exception\DbException
  45. * @throws @\think\db\exception\ModelNotFoundException
  46. * @author 张无忌
  47. * @date 2021/7/29 18:11
  48. */
  49. public function lists(): array
  50. {
  51. $lists = (new File())->field(['id,cid,type,name,uri'])
  52. ->order('id desc')
  53. ->where($this->searchWhere)
  54. ->where(['source'=>FileEnum::SOURCE_BACKSTAGE])
  55. ->limit($this->limitOffset, $this->limitLength)
  56. ->select()
  57. ->toArray();
  58. foreach ($lists as &$item) {
  59. $item['url'] = $item['uri'];
  60. $item['uri'] = FileService::getFileUrl($item['uri']);
  61. }
  62. return $lists;
  63. }
  64. /**
  65. * @notes 获取文件数量
  66. * @return int
  67. * @author 张无忌
  68. * @date 2021/7/29 18:11
  69. */
  70. public function count(): int
  71. {
  72. return (new File())->where($this->searchWhere)->where(['source'=>FileEnum::SOURCE_BACKSTAGE])->count();
  73. }
  74. }