| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- namespace app\index\controller;
- use app\index\service\CategoryService;
- use app\index\service\IpService;
- use app\index\service\JiamengService;
- use app\index\service\PageService;
- use cmf\controller\HomeBaseController;
- use think\Db;
- class JiamengController extends HomeBaseController
- {
- public function index()
- {
- return $this->fetch();
- }
- public function home(){
- //二级分类
- $param = $this->request->param();
- isset($param['enname']) or $this->error('需要父分类');
- $curarr = Db::name('category')->where('enname',$param['enname'])->find();
- if($curarr['parent_id']>0){
- $this->error('不是一级分类');
- }
- $sonarr = Db::name('category')->where('parent_id',$curarr['id'])->order('list_order')->limit(10)->select();
- $this->assign('sonarr',$sonarr);
- return $this->fetch();
- }
- /**
- * 列表
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function lists(){
- $param = $this->request->param();
- $enname = isset($param['enname'])? trim($param['enname']) : '';
- $pcid = isset($param['pcid'])? intval($param['pcid']) : 0;
- echo $enname.'++';
- if($enname || $pcid){
- $where = [];
- if($enname){
- $where['enname'] = $enname;
- }
- if($pcid){
- $where['id'] = $pcid;
- }
- $cateData = Db::name('category')->where($where)->value('id');
- $seo_title = str_replace('|',$cateData['catname'],$cateData['seo_title']);
- $seo_keywords = str_replace('|',$cateData['catname'],$cateData['seo_keywords']);
- $seo_desc = str_replace('|',$cateData['catname'],$cateData['seo_desc']);
- $this->assign('seo_title',$seo_title);
- $this->assign('seo_keywords',$seo_keywords);
- $this->assign('seo_desc',$seo_desc);
- }
- $param['pageType'] = 1;
- $result = JiamengService::getList($param);
- $page = $result->render();
- // 参数
- $touziarr = config('params.touziLevels');
- $areaList = config('params.areaList');
- $cateList = CategoryService::getCates();
- // 获取最新品牌
- $brandNews = JiamengService::getNewList(10);
- //加盟排行
- $paihang = JiamengService::getHotList(18);
- $param = [
- 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
- 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
- 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
- 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
- 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
- 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
- ];
- $result = $result? $result->toArray() : [];
- $lists = isset($result['data'])? $result['data'] : [];
- foreach ($lists as &$item){
- $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
- $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
- $areaId = isset($item['area_id'])? intval($item['area_id']) : 0;
- $item['area_name'] = isset($areaList[$areaId]) ? $areaList[$areaId] : '';
- }
- $this->assign('page',$page);
- $this->assign('data',$result);
- $this->assign('lists', $lists);
- $this->assign('paihang',$paihang);
- $this->assign('param',$param);
- $this->assign('brandNews',$brandNews);
- $this->assign('touziarr',$touziarr);
- $this->assign('areaList',$areaList);
- $this->assign('cateList',$cateList);
- return $this->fetch('list');
- }
- /**
- * 搜索
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function search(){
- $param = $this->request->param();
- $result = JiamengService::getList($param);
- $page = $result->render();
- // 参数
- $touziarr = config('params.touziLevels');
- $areaList = config('params.areaList');
- $cateList = CategoryService::getCates();
- // 获取最新品牌
- $brandNews = JiamengService::getNewList(10);
- //加盟排行
- $paihang = JiamengService::getHotList(18);
- $param = [
- 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
- 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
- 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
- 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
- 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
- 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
- ];
- $result = $result? $result->toArray() : [];
- $lists = isset($result['data'])? $result['data'] : [];
- foreach ($lists as &$item){
- $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
- $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
- }
- $this->assign('page',$page);
- $this->assign('data',$result);
- $this->assign('lists', $lists);
- $this->assign('paihang',$paihang);
- $this->assign('param',$param);
- $this->assign('brandNews',$brandNews);
- $this->assign('touziarr',$touziarr);
- $this->assign('areaList',$areaList);
- $this->assign('cateList',$cateList);
- return $this->fetch();
- }
- /**
- * 详情
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function show(){
- $param = $this->request->param();
- isset($param['id']) or $this->error('需要id');
- $info = Db::name('jiameng')->where('id',$param['id'])->find();
- //内容
- $content = Db::name('jiameng_data')->where('id',$param['id'])->find();
- $info['content'] = $content['content'];
- $info['youshi'] = $content['youshi'];
- $info['tiaojian'] = $content['tiaojian'];
- $info['liucheng'] = $content['liucheng'];
- $info['jm_support'] = isset($info['jm_support']) && $info['jm_support']? explode(',', $info['jm_support']) : [];
- $catinfo = Db::name('category')->where('id',$info['catid'])->find();
-
- $parinfo = Db::name('category')->where('id',$catinfo['parent_id'])->find();
- $touziarr = config('params.touziLevels');
- //热门行业
- $hot_cate = Db::name('category')->where('parent_id',$parinfo['id'])->order('list_order')->limit(12)->select();
- //排行
- $paihang = Db::name('jiameng')->field('id,title,logo,touzi_level,mendian,hits')->where('catid',$info['catid'])->order('hits desc')->limit(5)->select();
- //动态
- $about_news = Db::name('news')->field('id,title,thumb,create_time')->where('ncatid',1)->order('id desc')->limit(6)->select();
- $brand_news = Db::name('news')->field('id,title,create_time')->where('catid',$info['catid'])->order('id desc')->limit(6)->select();
- //热门加盟
- $hot_jm = Db::name('jiameng')->field('id,title,hits')->where('catid',$info['catid'])->order('hits desc')->limit(20)->select();
- //最新加盟
- $zx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->order('create_time desc')->limit(20)->select();
- //精选加盟
- $jx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->orderRaw('rand()')->limit(20)->select();
- //seo
- $seo_title = str_replace('|',$info['title'],$catinfo['seo_title']);
- $seo_keywords = str_replace('|',$info['title'],$catinfo['seo_keywords']);
- $seo_desc = mb_substr($info['content'],0,200,'utf8');
- $seo_desc = strip_tags($seo_desc);
- $link_cate_name = $parinfo['enname'];
- // $this->assign('link_cate_name',$link_cate_name);
- $this->assign('seo_title',$seo_title);
- $this->assign('seo_keywords',$seo_keywords);
- $this->assign('seo_desc',$seo_desc);
- $this->assign('hot_jm',$hot_jm);
- $this->assign('zx_jm',$zx_jm);
- $this->assign('jx_jm',$jx_jm);
- $this->assign('about_news',$about_news);
- $this->assign('brand_news',$brand_news);
- $this->assign('paihang',$paihang);
- $this->assign('hot_cate',$hot_cate);
- $this->assign('touziarr',$touziarr);
- $this->assign('catinfo',$catinfo);
- $this->assign('parinfo',$parinfo);
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function message(){
- $param = $this->request->param();
- // isset($param['name'])&&$param['name']!='' or $this->error('请填写姓名');
- isset($param['mobile'])&&$param['mobile']!='' or $this->error('请填写手机号');
- $param['create_time'] = time();
- $param['ip'] = get_client_ip();
- $param['address'] = IpService::getAddress(get_client_ip());
- $todaytime = strtotime(date('Y-m-d'));
- if(strlen($param['content'])>300){
- $this->error('字符长度不超过300个');
- }
- if(isset($param['tzed']) && $param['tzed']<=0){
- $this->error('请选择投资额度');
- }
- $param['content'] = $this->strFilter($param['content']);
- $param['name'] = $this->strFilter($param['name']);
- $param['mobile'] = $this->strFilter($param['mobile']);
- $param['tzed'] = $this->strFilter($param['tzed']);
- $param['area'] = $this->strFilter($param['area']);
- $param['wechat'] = $this->strFilter($param['wechat']);
- // print_r($param);exit;
- //判断是否已超过10次 今天这个ip是否留言过
- $sum = Db::name('message')->where('ip',$param['ip'])->where('create_time','gt',$todaytime)->count();
- if($sum>0){
- $this->error('今日留言已超过1次,明天再来吧!');
- }
- //判断手机号本周内是否留过
- // 当前日期
- $sdefaultDate = date("Y-m-d");
- // $first =1 表示每周星期一为开始日期 0表示每周日为开始日期
- $first=1;
- // 获取当前周的第几天 周日是0 周一到周六是 1 - 6
- $w = date('w', strtotime($sdefaultDate));
- // 获取本周开始日期,如果$w是0,则表示周日,减去 6 天
- $week_start=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
- $sum = Db::name('message')->where('mobile',$param['mobile'])->where('create_time','gt',$week_start)->count();
- if($sum>0){
- $this->error('您的手机号在本周内已预留过,下周再来吧!');
- }
- $res = Db::name('message')->insert($param);
- if($res){
- $this->success('咨询成功');
- }else{
- $this->error('咨询失败');
- }
- }
- public function strFilter($str){
- $str = str_replace('`', '', $str);
- $str = str_replace('·', '', $str);
- $str = str_replace('~', '', $str);
- $str = str_replace('!', '', $str);
- $str = str_replace('!', '', $str);
- $str = str_replace('@', '', $str);
- $str = str_replace('#', '', $str);
- $str = str_replace('$', '', $str);
- $str = str_replace('¥', '', $str);
- $str = str_replace('%', '', $str);
- $str = str_replace('^', '', $str);
- $str = str_replace('……', '', $str);
- $str = str_replace('&', '', $str);
- $str = str_replace('*', '', $str);
- $str = str_replace('(', '', $str);
- $str = str_replace(')', '', $str);
- $str = str_replace('(', '', $str);
- $str = str_replace(')', '', $str);
- $str = str_replace('-', '', $str);
- $str = str_replace('_', '', $str);
- $str = str_replace('——', '', $str);
- $str = str_replace('+', '', $str);
- $str = str_replace('=', '', $str);
- $str = str_replace('|', '', $str);
- $str = str_replace('\\', '', $str);
- $str = str_replace('[', '', $str);
- $str = str_replace(']', '', $str);
- $str = str_replace('【', '', $str);
- $str = str_replace('】', '', $str);
- $str = str_replace('{', '', $str);
- $str = str_replace('}', '', $str);
- $str = str_replace(';', '', $str);
- $str = str_replace(';', '', $str);
- $str = str_replace(':', '', $str);
- $str = str_replace(':', '', $str);
- $str = str_replace('\'', '', $str);
- $str = str_replace('"', '', $str);
- $str = str_replace('“', '', $str);
- $str = str_replace('”', '', $str);
- $str = str_replace(',', '', $str);
- $str = str_replace(',', '', $str);
- $str = str_replace('<', '', $str);
- $str = str_replace('>', '', $str);
- $str = str_replace('《', '', $str);
- $str = str_replace('》', '', $str);
- $str = str_replace('.', '', $str);
- $str = str_replace('。', '', $str);
- $str = str_replace('/', '', $str);
- $str = str_replace('、', '', $str);
- $str = str_replace('?', '', $str);
- $str = str_replace('?', '', $str);
- return trim($str);
- }
- }
- ?>
|