toArray() : [];
$recCates = $recCates? array_chunk($recCates, 3) : [];
// 最新招商
$brandNews = JiamengService::getNewList(10);
/* 轮播广告 */
//横幅广告位
$banner = AdvertService::getListBySlide(1, 6);
// 小图
$bannerMin = AdvertService::getListBySlide(2, 5);
// 特许加盟
$banner1 = AdvertService::getListBySlide(3, 1);
// 严选品牌上方广告
$banner2 = AdvertService::getListBySlide(4, 1);
// 品牌排行榜下方广告
$banner3 = AdvertService::getListBySlide(6, 1);
// 加盟动态下方广告
$banner4 = AdvertService::getListBySlide(5, 1);
/* 品牌栏位列表数据 */
// 今日之星
$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->toArray(), 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){
$dataList = NewsService::getListByCate($catid, 6);
$cateNews1[] = $dataList? $dataList->toArray() : [];
}
}
}
if($newsCates2){
foreach($newsCates2 as $k=>$v){
$catid = isset($v['id'])? intval($v['id']): 0;
if($catid){
$dataList = NewsService::getListByCate($catid, 7);
$cateNews2[] = $dataList? $dataList->toArray() : [];
}
}
}
// 热点新闻
$recNews = NewsService::getNewList(6);
// 加盟问答
$answerList = Db::name('know')->whereIn('status',[1,2])
->field('id,title,description')
->order('create_time desc')
->limit(13)
->select();
// $answerList = NewsService::getListByLevel(1, 13);
// 课堂列表
$courseList = NewsService::getListByLevel(1, 8);
// 参数
$cateList = CategoryService::getCates();
$cateList = $cateList? $cateList->toArray() : [];
$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 = MessageService::getList(['type'=> 1], 10);
$jmMessages = NewsService::getRandList(10);
// 友情链接
$links = LinkService::getList(['catname'=> 'index'], 50);
$endtime = microtime(true);
$time = (($endtime-$time)).'s';
echo '访问时间:'.$endtime."\n";
echo '访问时间:'.$time;
// 新增
$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
return $this->fetch();
}
public function ws()
{
return $this->fetch(':ws');
}
/**
* 投诉
*/
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) || true){
$dataList = CategoryService::getCates(500, -1, "enname as id, catname as title, '1' as 'type'");
$dataList = $dataList? $dataList->toArray() : [];
$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=> "".$domain."".date('Y-m-d')."daily1.0",
];
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}daily0.9";
}
if($urls){
$strUrls = ''.implode('',$urls).'';
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:*');
// end
}
}
?>