InfoLists.php 3.9 KB

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