JiamengController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace app\index\controller;
  3. use app\index\service\CategoryService;
  4. use app\index\service\IpService;
  5. use app\index\service\JiamengService;
  6. use app\index\service\PageService;
  7. use cmf\controller\HomeBaseController;
  8. use think\Db;
  9. class JiamengController extends HomeBaseController
  10. {
  11. public function index()
  12. {
  13. return $this->fetch();
  14. }
  15. public function home(){
  16. //二级分类
  17. $param = $this->request->param();
  18. isset($param['enname']) or $this->error('需要父分类');
  19. $curarr = Db::name('category')->where('enname',$param['enname'])->find();
  20. if($curarr['parent_id']>0){
  21. $this->error('不是一级分类');
  22. }
  23. $sonarr = Db::name('category')->where('parent_id',$curarr['id'])->order('list_order')->limit(10)->select();
  24. $this->assign('sonarr',$sonarr);
  25. return $this->fetch();
  26. }
  27. /**
  28. * 列表
  29. * @return mixed
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. public function lists(){
  35. $param = $this->request->param();
  36. $enname = isset($param['enname'])? trim($param['enname']) : '';
  37. $pcid = isset($param['pcid'])? intval($param['pcid']) : 0;
  38. echo $enname.'++';
  39. if($enname || $pcid){
  40. $where = [];
  41. if($enname){
  42. $where['enname'] = $enname;
  43. }
  44. if($pcid){
  45. $where['id'] = $pcid;
  46. }
  47. $cateData = Db::name('category')->where($where)->value('id');
  48. $seo_title = str_replace('|',$cateData['catname'],$cateData['seo_title']);
  49. $seo_keywords = str_replace('|',$cateData['catname'],$cateData['seo_keywords']);
  50. $seo_desc = str_replace('|',$cateData['catname'],$cateData['seo_desc']);
  51. $this->assign('seo_title',$seo_title);
  52. $this->assign('seo_keywords',$seo_keywords);
  53. $this->assign('seo_desc',$seo_desc);
  54. }
  55. $param['pageType'] = 1;
  56. $result = JiamengService::getList($param);
  57. $page = $result->render();
  58. // 参数
  59. $touziarr = config('params.touziLevels');
  60. $areaList = config('params.areaList');
  61. $cateList = CategoryService::getCates();
  62. // 获取最新品牌
  63. $brandNews = JiamengService::getNewList(10);
  64. //加盟排行
  65. $paihang = JiamengService::getHotList(18);
  66. $param = [
  67. 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
  68. 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
  69. 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
  70. 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
  71. 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
  72. 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
  73. ];
  74. $result = $result? $result->toArray() : [];
  75. $lists = isset($result['data'])? $result['data'] : [];
  76. foreach ($lists as &$item){
  77. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  78. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  79. $areaId = isset($item['area_id'])? intval($item['area_id']) : 0;
  80. $item['area_name'] = isset($areaList[$areaId]) ? $areaList[$areaId] : '';
  81. }
  82. $this->assign('page',$page);
  83. $this->assign('data',$result);
  84. $this->assign('lists', $lists);
  85. $this->assign('paihang',$paihang);
  86. $this->assign('param',$param);
  87. $this->assign('brandNews',$brandNews);
  88. $this->assign('touziarr',$touziarr);
  89. $this->assign('areaList',$areaList);
  90. $this->assign('cateList',$cateList);
  91. return $this->fetch('list');
  92. }
  93. /**
  94. * 搜索
  95. * @return mixed
  96. * @throws \think\db\exception\DataNotFoundException
  97. * @throws \think\db\exception\ModelNotFoundException
  98. * @throws \think\exception\DbException
  99. */
  100. public function search(){
  101. $param = $this->request->param();
  102. $result = JiamengService::getList($param);
  103. $page = $result->render();
  104. // 参数
  105. $touziarr = config('params.touziLevels');
  106. $areaList = config('params.areaList');
  107. $cateList = CategoryService::getCates();
  108. // 获取最新品牌
  109. $brandNews = JiamengService::getNewList(10);
  110. //加盟排行
  111. $paihang = JiamengService::getHotList(18);
  112. $param = [
  113. 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
  114. 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
  115. 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
  116. 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
  117. 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
  118. 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
  119. ];
  120. $result = $result? $result->toArray() : [];
  121. $lists = isset($result['data'])? $result['data'] : [];
  122. foreach ($lists as &$item){
  123. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  124. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  125. }
  126. $this->assign('page',$page);
  127. $this->assign('data',$result);
  128. $this->assign('lists', $lists);
  129. $this->assign('paihang',$paihang);
  130. $this->assign('param',$param);
  131. $this->assign('brandNews',$brandNews);
  132. $this->assign('touziarr',$touziarr);
  133. $this->assign('areaList',$areaList);
  134. $this->assign('cateList',$cateList);
  135. return $this->fetch();
  136. }
  137. /**
  138. * 详情
  139. * @return mixed
  140. * @throws \think\db\exception\DataNotFoundException
  141. * @throws \think\db\exception\ModelNotFoundException
  142. * @throws \think\exception\DbException
  143. */
  144. public function show(){
  145. $param = $this->request->param();
  146. isset($param['id']) or $this->error('需要id');
  147. $info = Db::name('jiameng')->where('id',$param['id'])->find();
  148. //内容
  149. $content = Db::name('jiameng_data')->where('id',$param['id'])->find();
  150. $info['content'] = $content['content'];
  151. $info['youshi'] = $content['youshi'];
  152. $info['tiaojian'] = $content['tiaojian'];
  153. $info['liucheng'] = $content['liucheng'];
  154. $info['jm_support'] = isset($info['jm_support']) && $info['jm_support']? explode(',', $info['jm_support']) : [];
  155. $catinfo = Db::name('category')->where('id',$info['catid'])->find();
  156. $parinfo = Db::name('category')->where('id',$catinfo['parent_id'])->find();
  157. $touziarr = config('params.touziLevels');
  158. //热门行业
  159. $hot_cate = Db::name('category')->where('parent_id',$parinfo['id'])->order('list_order')->limit(12)->select();
  160. //排行
  161. $paihang = Db::name('jiameng')->field('id,title,logo,touzi_level,mendian,hits')->where('catid',$info['catid'])->order('hits desc')->limit(5)->select();
  162. //动态
  163. $about_news = Db::name('news')->field('id,title,thumb,create_time')->where('ncatid',1)->order('id desc')->limit(6)->select();
  164. $brand_news = Db::name('news')->field('id,title,create_time')->where('catid',$info['catid'])->order('id desc')->limit(6)->select();
  165. //热门加盟
  166. $hot_jm = Db::name('jiameng')->field('id,title,hits')->where('catid',$info['catid'])->order('hits desc')->limit(20)->select();
  167. //最新加盟
  168. $zx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->order('create_time desc')->limit(20)->select();
  169. //精选加盟
  170. $jx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->orderRaw('rand()')->limit(20)->select();
  171. //seo
  172. $seo_title = str_replace('|',$info['title'],$catinfo['seo_title']);
  173. $seo_keywords = str_replace('|',$info['title'],$catinfo['seo_keywords']);
  174. $seo_desc = mb_substr($info['content'],0,200,'utf8');
  175. $seo_desc = strip_tags($seo_desc);
  176. $link_cate_name = $parinfo['enname'];
  177. // $this->assign('link_cate_name',$link_cate_name);
  178. $this->assign('seo_title',$seo_title);
  179. $this->assign('seo_keywords',$seo_keywords);
  180. $this->assign('seo_desc',$seo_desc);
  181. $this->assign('hot_jm',$hot_jm);
  182. $this->assign('zx_jm',$zx_jm);
  183. $this->assign('jx_jm',$jx_jm);
  184. $this->assign('about_news',$about_news);
  185. $this->assign('brand_news',$brand_news);
  186. $this->assign('paihang',$paihang);
  187. $this->assign('hot_cate',$hot_cate);
  188. $this->assign('touziarr',$touziarr);
  189. $this->assign('catinfo',$catinfo);
  190. $this->assign('parinfo',$parinfo);
  191. $this->assign('info',$info);
  192. return $this->fetch();
  193. }
  194. public function message(){
  195. $param = $this->request->param();
  196. // isset($param['name'])&&$param['name']!='' or $this->error('请填写姓名');
  197. isset($param['mobile'])&&$param['mobile']!='' or $this->error('请填写手机号');
  198. $param['create_time'] = time();
  199. $param['ip'] = get_client_ip();
  200. $param['address'] = IpService::getAddress(get_client_ip());
  201. $todaytime = strtotime(date('Y-m-d'));
  202. if(strlen($param['content'])>300){
  203. $this->error('字符长度不超过300个');
  204. }
  205. if(isset($param['tzed']) && $param['tzed']<=0){
  206. $this->error('请选择投资额度');
  207. }
  208. $param['content'] = $this->strFilter($param['content']);
  209. $param['name'] = $this->strFilter($param['name']);
  210. $param['mobile'] = $this->strFilter($param['mobile']);
  211. $param['tzed'] = $this->strFilter($param['tzed']);
  212. $param['area'] = $this->strFilter($param['area']);
  213. $param['wechat'] = $this->strFilter($param['wechat']);
  214. // print_r($param);exit;
  215. //判断是否已超过10次 今天这个ip是否留言过
  216. $sum = Db::name('message')->where('ip',$param['ip'])->where('create_time','gt',$todaytime)->count();
  217. if($sum>0){
  218. $this->error('今日留言已超过1次,明天再来吧!');
  219. }
  220. //判断手机号本周内是否留过
  221. // 当前日期
  222. $sdefaultDate = date("Y-m-d");
  223. // $first =1 表示每周星期一为开始日期 0表示每周日为开始日期
  224. $first=1;
  225. // 获取当前周的第几天 周日是0 周一到周六是 1 - 6
  226. $w = date('w', strtotime($sdefaultDate));
  227. // 获取本周开始日期,如果$w是0,则表示周日,减去 6 天
  228. $week_start=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
  229. $sum = Db::name('message')->where('mobile',$param['mobile'])->where('create_time','gt',$week_start)->count();
  230. if($sum>0){
  231. $this->error('您的手机号在本周内已预留过,下周再来吧!');
  232. }
  233. $res = Db::name('message')->insert($param);
  234. if($res){
  235. $this->success('咨询成功');
  236. }else{
  237. $this->error('咨询失败');
  238. }
  239. }
  240. public function strFilter($str){
  241. $str = str_replace('`', '', $str);
  242. $str = str_replace('·', '', $str);
  243. $str = str_replace('~', '', $str);
  244. $str = str_replace('!', '', $str);
  245. $str = str_replace('!', '', $str);
  246. $str = str_replace('@', '', $str);
  247. $str = str_replace('#', '', $str);
  248. $str = str_replace('$', '', $str);
  249. $str = str_replace('¥', '', $str);
  250. $str = str_replace('%', '', $str);
  251. $str = str_replace('^', '', $str);
  252. $str = str_replace('……', '', $str);
  253. $str = str_replace('&', '', $str);
  254. $str = str_replace('*', '', $str);
  255. $str = str_replace('(', '', $str);
  256. $str = str_replace(')', '', $str);
  257. $str = str_replace('(', '', $str);
  258. $str = str_replace(')', '', $str);
  259. $str = str_replace('-', '', $str);
  260. $str = str_replace('_', '', $str);
  261. $str = str_replace('——', '', $str);
  262. $str = str_replace('+', '', $str);
  263. $str = str_replace('=', '', $str);
  264. $str = str_replace('|', '', $str);
  265. $str = str_replace('\\', '', $str);
  266. $str = str_replace('[', '', $str);
  267. $str = str_replace(']', '', $str);
  268. $str = str_replace('【', '', $str);
  269. $str = str_replace('】', '', $str);
  270. $str = str_replace('{', '', $str);
  271. $str = str_replace('}', '', $str);
  272. $str = str_replace(';', '', $str);
  273. $str = str_replace(';', '', $str);
  274. $str = str_replace(':', '', $str);
  275. $str = str_replace(':', '', $str);
  276. $str = str_replace('\'', '', $str);
  277. $str = str_replace('"', '', $str);
  278. $str = str_replace('“', '', $str);
  279. $str = str_replace('”', '', $str);
  280. $str = str_replace(',', '', $str);
  281. $str = str_replace(',', '', $str);
  282. $str = str_replace('<', '', $str);
  283. $str = str_replace('>', '', $str);
  284. $str = str_replace('《', '', $str);
  285. $str = str_replace('》', '', $str);
  286. $str = str_replace('.', '', $str);
  287. $str = str_replace('。', '', $str);
  288. $str = str_replace('/', '', $str);
  289. $str = str_replace('、', '', $str);
  290. $str = str_replace('?', '', $str);
  291. $str = str_replace('?', '', $str);
  292. return trim($str);
  293. }
  294. }
  295. ?>