InfoLists.php 3.4 KB

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