| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <?php
- namespace app\index\controller;
- use app\index\service\AdvertService;
- use app\index\service\CategoryService;
- use app\index\service\IpService;
- use app\index\service\JiamengService;
- use app\index\service\LinkService;
- use app\index\service\MessageService;
- use app\index\service\NewsCategoryService;
- use app\index\service\NewsService;
- use app\index\service\RedisService;
- use cmf\controller\HomeBaseController;
- use think\Db;
- class IndexController extends HomeBaseController
- {
- public function index()
- {
- $cacheKey = 'cache:index_pages:index_'.intval(cmf_is_mobile());
- $pageHtml = RedisService::get($cacheKey);
- if($pageHtml){
- return $pageHtml;
- }
- // 热门分类
- $recCates = CategoryService::getRecCates(6);
- $recCates = $recCates? array_chunk($recCates, 3) : [];
- // 最新招商
- $brandNews = JiamengService::getNewList(10);
- /* 轮播广告 */
- //横幅广告位
- $banner = AdvertService::getListBySlide(1, 6);
- // 小图
- $bannerMin = AdvertService::getListBySlide(2, 5);
- // 特许加盟
- $banners = AdvertService::getListBySlides([3,4,5,6], 1);
- $banner1 = isset($banners[3])? $banners[3] : [];
- // 严选品牌上方广告
- $banner2 = isset($banners[4])? $banners[4] : [];
- // 品牌排行榜下方广告
- $banner3 = isset($banners[6])? $banners[6] : [];
- // 加盟动态下方广告
- $banner4 = isset($banners[5])? $banners[5] : [];
- /* 品牌栏位列表数据 */
- // 今日之星
- $brand1 = JiamengService::getListByLevel(1,3);
- // 匹配精选
- $brand2 = JiamengService::getListByLevel(2);
- // 品牌推荐
- $brand3 = JiamengService::getListByLevel(3);
- // 品牌严选
- $brand4 = JiamengService::getListByLevel(4, 21);
- // 专题品牌
- $brand6 = JiamengService::getListByLevel(6, 10);
- // 品牌聚焦
- $brand7 = JiamengService::getListByLevel(7, 56);
- $brand7 = $brand7? array_chunk($brand7, 28, true) : [];
- // 最新品牌
- $brand8 = JiamengService::getNewList(12);
- /* 人气排行榜1 */
- $phb1 = JiamengService::getTopList('touzi_level <= 2');
- $phb2 = JiamengService::getTopList('touzi_level = 3');
- $phb3 = JiamengService::getTopList('touzi_level >= 4');
- /* 新闻资讯 */
- // 分类1
- $cateNews1 = $cateNews2 = [];
- $newsCates = NewsCategoryService::getCates(6);
- $newsCates1 = NewsCategoryService::getCatesListByIds([17,18,19]);
- $newsCates2 = NewsCategoryService::getCatesListByIds([1,4,20]);
- if($newsCates1){
- foreach($newsCates1 as $k=>$v){
- $catid = isset($v['id'])? intval($v['id']): 0;
- if($catid){
- $cateNews1[] = NewsService::getListByCate($catid, 6);
- }
- }
- }
- if($newsCates2){
- foreach($newsCates2 as $k=>$v){
- $catid = isset($v['id'])? intval($v['id']): 0;
- if($catid){
- $cateNews2[] = NewsService::getListByCate($catid, 7);
- }
- }
- }
- // 热点新闻
- $recNews = NewsService::getNewList(6);
- // 加盟问答
- $answerList = Db::name('know')->whereIn('status',[1,2])
- ->field('id,title,description')
- ->order('create_time desc')
- ->limit(13)
- ->select();
- // 课堂列表
- $courseList = NewsService::getListByLevel(1, 8);
- // 参数
- $cateList = CategoryService::getCates();
- $touziarr = config('params.touziLevels');
- // 分类品牌
- $cateBrands = [];
- $hotCates = $cateList? array_slice($cateList, 0, 6) : [];
- if($hotCates){
- foreach ($hotCates as $k => $cate){
- $catid = isset($cate['id'])? $cate['id'] : '';
- if($catid){
- $dataList = JiamengService::getList(['pcid'=> $catid], '',16);
- $cateBrands[] = $dataList? $dataList : [];
- }
- }
- }
- // 热门品牌
- $brandHot = JiamengService::getTopList([], 16);
- // 加盟动态
- $jmMessages = NewsService::getRandList(10);
- // 友情链接
- $links = LinkService::getList(['catname'=> 'index'], 50);
- // 新增
- $this->assign('banner',$banner);
- $this->assign('banner1',$banner1);
- $this->assign('banner2',$banner2);
- $this->assign('banner3',$banner3);
- $this->assign('banner4',$banner4);
- $this->assign('bannerMin',$bannerMin);
- $this->assign('brandNews',$brandNews);
- $this->assign('cateList',$cateList);
- $this->assign('touziarr',$touziarr);
- $this->assign('hotCates',$hotCates);
- $this->assign('cateBrands',$cateBrands);
- $this->assign('brandHot',$brandHot);
- $this->assign('newsCates1',$newsCates1);
- $this->assign('newsCates2',$newsCates2);
- $this->assign('cateNews1',$cateNews1);
- $this->assign('cateNews2',$cateNews2);
- $this->assign('cateNews2',$cateNews2);
- $this->assign('newsCates',$newsCates);
- $this->assign('recNews',$recNews);
- $this->assign('answerList',$answerList);
- $this->assign('jmMessages',$jmMessages);
- $this->assign('courseList',$courseList);
- $this->assign('recCates',$recCates);
- $this->assign('links',$links);
- // 品牌
- $this->assign('brand1',$brand1);
- $this->assign('brand2',$brand2);
- $this->assign('brand3',$brand3);
- $this->assign('brand4',$brand4);
- // $this->assign('brand5',$brand5);
- $this->assign('brand6',$brand6);
- $this->assign('brand7',$brand7);
- $this->assign('brand8',$brand8);
- // 品牌排行榜
- $this->assign('phb1',$phb1);
- $this->assign('phb2',$phb2);
- $this->assign('phb3',$phb3);
- // end
- $pageHtml = $this->fetch();
- // 页面缓存
- RedisService::set($cacheKey, $pageHtml , 24*3600);
- return $pageHtml;
- }
- /**
- * 投诉
- */
- public function complaint(){
- $param = $this->request->param();
- isset($param['mobile'])&&$param['mobile']!='' or $this->error('请填写手机号');
- $param['create_time'] = time();
- $param['ip'] = get_client_ip();
- $param['address'] = IpService::getAddress(get_client_ip());
- if(strlen($param['content'])>200){
- $this->error('字符长度不超过300个');
- }
- $param['content'] = strFilter($param['content']);
- $param['name'] = strFilter($param['name']);
- $param['mobile'] = strFilter($param['mobile']);
- $param['type'] = 2;
- //判断是否已超过10次 今天这个ip是否投诉过
- $sum = MessageService::getTodyCount(['ip'=> $param['ip'],'type'=> 2]);
- if($sum>0){
- $this->error('今日投诉已超过1次,明天再来吧!');
- }
- $res = Db::name('message')->insert($param);
- if($res){
- $this->success('投诉提交成功');
- }else{
- $this->error('投诉提交失败');
- }
- }
- /**
- * 网站地图
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function sitemap(){
- $page = input('p', 1);
- $cacheKey = 'cache:sitemap:list_';
- $datas = RedisService::get($cacheKey.$page);
- if(empty($datas)){
- $dataList = CategoryService::getCates(500, -1, "enname as id, catname as title, '1' as 'type'");
- $brands = JiamengService::getList(['status'=> 1], "j.id,j.title, '2' as 'type'", 1000);
- $brands = $brands? $brands->toArray() : [];
- $news = NewsService::getList(['status'=> 1], 1000,"id,title, '3' as 'type'");
- $news = $news? $news->toArray() : [];
- $dataList = isset($brands['data']) && $brands['data']? array_merge($dataList, $brands['data']) : $dataList;
- $dataList = isset($news['data']) && $news['data']? array_merge($dataList, $news['data']) : $dataList;
- // 生成XML文件
- if($dataList){
- $domain = request()->domain();
- $urls = [
- 0=> "<url><loc>".$domain."</loc><lastmod>".date('Y-m-d')."</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>",
- ];
- foreach ($dataList as $item){
- $type = isset($item['type'])? intval($item['type']) : 0;
- switch($type){
- case 1: $url = $domain.'/xm'.$item['id'].'/'; break;
- case 2: $url = $domain.'/b'.$item['id'].'/'; break;
- default: $url = $domain.'/news'.$item['id'].'/'; break;
- }
- $urls[] = "<url><loc>{$url}</loc><changefreq>daily</changefreq><priority>0.9</priority></url>";
- }
- if($urls){
- $strUrls = '<?xml version="1.0" encoding="utf-8"?><urlset>'.implode('',$urls).'</urlset>';
- file_put_contents('./sitemap.xml', $strUrls);
- }
- }
- $result = $dataList? array_chunk($dataList, 500) : [];
- if($result){
- foreach ($result as $k => $list){
- RedisService::set($cacheKey.($k+1), $dataList, 30*3600);
- }
- $datas = isset($result[$page-1])? $result[$page-1] : [];
- }
- }
- $nextPage = $page+1;
- $this->assign('datas', $datas);
- $this->assign('lastPage', $page-1>0? ($page-1) : 1);
- $this->assign('nextPage', RedisService::get($cacheKey.$nextPage)? $nextPage : 0);
- return $this->fetch('../sitemap');
- }
- public function clearCache(){
- // 清楚Redis缓存
- RedisService::delByKeys('cache:*');
- exit('清除成功');
- // end
- }
- }
- ?>
|