ArticleLists.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\lists\ListsExcelInterface;
  21. use app\common\lists\ListsSearchInterface;
  22. use app\common\model\Article;
  23. use app\common\model\ArticleCategory;
  24. class ArticleLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
  25. {
  26. /**
  27. * @notes 设置导出字段
  28. * @return string[]
  29. * @author Tab
  30. * @date 2021/7/30 15:37
  31. */
  32. public function setExcelFields(): array
  33. {
  34. return [
  35. 'title' => '标题',
  36. 'cid_desc' => '分类',
  37. 'is_show_desc' => '文章状态',
  38. 'visit' => '浏览量',
  39. 'sort' => '排序',
  40. 'create_time' => '创建时间',
  41. ];
  42. }
  43. /**
  44. * @notes 设置默认表名
  45. * @return string
  46. * @author Tab
  47. * @date 2021/7/30 15:37
  48. */
  49. public function setFileName(): string
  50. {
  51. return '商城咨询列表';
  52. }
  53. /**
  54. * @notes 设置搜索
  55. * @return \string[][]
  56. * @author Tab
  57. * @date 2021/7/14 9:48
  58. */
  59. public function setSearch(): array
  60. {
  61. return [
  62. '=' => [ 'cid'],
  63. '%like%' => ['title']
  64. ];
  65. }
  66. /**
  67. * @notes 文章/帮助列表
  68. * @return array
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @author Tab
  73. * @date 2021/7/14 9:48
  74. */
  75. public function lists(): array
  76. {
  77. $lists = Article::field('id,title,image,cid,is_show,is_show as is_show_desc,visit,sort,create_time')
  78. ->where($this->searchWhere)
  79. ->order('sort desc,id desc')
  80. ->limit($this->limitOffset, $this->limitLength)
  81. ->select()
  82. ->toArray();
  83. $categoryList = ArticleCategory::column('name','id');
  84. foreach ($lists as $key => $list){
  85. $lists[$key]['cid_desc'] = $categoryList[$list['cid']] ?? '';
  86. }
  87. return $lists;
  88. }
  89. /**
  90. * @notes 文章/帮助总记录数
  91. * @return int
  92. * @author Tab
  93. * @date 2021/7/14 9:48
  94. */
  95. public function count(): int
  96. {
  97. return Article::where($this->searchWhere)->count();
  98. }
  99. }