InfoLists.php 3.5 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\shopapi\lists;
  20. use app\common\enum\AccountLogEnum;
  21. use app\common\lists\ListsSearchInterface;
  22. use app\common\model\Article;
  23. use app\common\model\Info;
  24. use app\common\model\Banner;
  25. class InfoLists extends BaseShopDataLists
  26. {
  27. public function setSearchWhere(){
  28. $where[]=['is_show','=',1];
  29. $params = $this->params;
  30. if(isset($params['type']) && $params['type']<>''){
  31. $where[] = ['type','=',$params['type']];
  32. }
  33. if(isset($params['cid']) && $params['cid']<>''){
  34. $where[] = ['cid','=',$params['cid']];
  35. }
  36. return $where;
  37. }
  38. /**
  39. * @notes 宣传信息列表
  40. * @return array
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @author Tab
  45. * @date 2021/7/14 9:48
  46. */
  47. public function lists(): array
  48. {
  49. $lists = Info::field('id,type,cid,title,synopsis,image,address,phone,latitude,longitude,sort,is_show,create_time')
  50. ->where(['is_show'=>1])
  51. ->where($this->setSearchWhere())
  52. ->append(['category','type_desc','is_show_desc'])
  53. ->order([
  54. 'sort' => 'desc',
  55. 'id' => 'desc'
  56. ])
  57. ->limit($this->limitOffset, $this->limitLength)
  58. ->select()
  59. ->toArray();
  60. $length = count($lists);
  61. if($length>0){
  62. $cate_id = array_unique(array_column($lists,'cid'));
  63. $zeros=[0];
  64. $cate_is_Arr = array_diff($cate_id,$zeros);
  65. $newlist = [];
  66. if(!empty($cate_is_Arr)){
  67. foreach ($cate_is_Arr as $v){
  68. foreach($lists as $lv){
  69. if($v==$lv['cid']){
  70. $newlist[$v][]=$lv;
  71. }
  72. }
  73. }
  74. $lists = $newlist;
  75. }
  76. }
  77. $data['info_list'] = $lists;
  78. $params = $this->params;
  79. $banner_where=[];
  80. if(isset($params['type']) && $params['type']<>''){
  81. $banner_where[] = ['type','=',$params['type']];
  82. }
  83. $banner_list = Banner::where($banner_where)->select()->toArray();
  84. $data['banner_list'] = $banner_list;
  85. return $data;
  86. }
  87. /**
  88. * @notes 文章/帮助总记录数
  89. * @return int
  90. * @author Tab
  91. * @date 2021/7/14 9:48
  92. */
  93. public function count(): int
  94. {
  95. return Info::where($this->setSearchWhere())->count();
  96. }
  97. }