JiamengController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. if($enname || $pcid){
  39. $where = [];
  40. if($enname){
  41. $where['enname'] = $enname;
  42. }
  43. if($pcid){
  44. $where['id'] = $pcid;
  45. }
  46. $cateData = Db::name('category')->where($where)->value('id');
  47. $seo_title = str_replace('|',$cateData['catname'],$cateData['seo_title']);
  48. $seo_keywords = str_replace('|',$cateData['catname'],$cateData['seo_keywords']);
  49. $seo_desc = str_replace('|',$cateData['catname'],$cateData['seo_desc']);
  50. $this->assign('seo_title',$seo_title);
  51. $this->assign('seo_keywords',$seo_keywords);
  52. $this->assign('seo_desc',$seo_desc);
  53. }
  54. $param['pageType'] = 1;
  55. $result = JiamengService::getList($param);
  56. $page = $result->render();
  57. // 参数
  58. $touziarr = config('params.touziLevels');
  59. $areaList = config('params.areaList');
  60. $cateList = CategoryService::getCates();
  61. // 获取最新品牌
  62. $brandNews = JiamengService::getNewList(10);
  63. //加盟排行
  64. $paihang = JiamengService::getHotList(18);
  65. $param = [
  66. 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
  67. 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
  68. 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
  69. 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
  70. 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
  71. 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
  72. ];
  73. $result = $result? $result->toArray() : [];
  74. $lists = isset($result['data'])? $result['data'] : [];
  75. foreach ($lists as &$item){
  76. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  77. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  78. $areaId = isset($item['area_id'])? intval($item['area_id']) : 0;
  79. $item['area_name'] = isset($areaList[$areaId]) ? $areaList[$areaId] : '';
  80. }
  81. $this->assign('page',$page);
  82. $this->assign('data',$result);
  83. $this->assign('lists', $lists);
  84. $this->assign('paihang',$paihang);
  85. $this->assign('param',$param);
  86. $this->assign('brandNews',$brandNews);
  87. $this->assign('touziarr',$touziarr);
  88. $this->assign('areaList',$areaList);
  89. $this->assign('cateList',$cateList);
  90. return $this->fetch('list');
  91. }
  92. /**
  93. * 搜索
  94. * @return mixed
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. * @throws \think\exception\DbException
  98. */
  99. public function search(){
  100. $param = $this->request->param();
  101. $result = JiamengService::getList($param);
  102. $page = $result->render();
  103. // 参数
  104. $touziarr = config('params.touziLevels');
  105. $areaList = config('params.areaList');
  106. $cateList = CategoryService::getCates();
  107. // 获取最新品牌
  108. $brandNews = JiamengService::getNewList(10);
  109. //加盟排行
  110. $paihang = JiamengService::getHotList(18);
  111. $param = [
  112. 'kw'=> isset($param['kw'])? trim($param['kw']) : '',
  113. 'enname'=> isset($param['enname'])? trim($param['enname']) : '',
  114. 'catid'=> isset($param['catid'])? intval($param['catid']) : 0,
  115. 'pcid'=> isset($param['pcid'])? intval($param['pcid']) : 0,
  116. 'lv'=> isset($param['lv'])? intval($param['lv']) : '-1',
  117. 'aid'=> isset($param['aid'])? intval($param['aid']) : 0,
  118. ];
  119. $result = $result? $result->toArray() : [];
  120. $lists = isset($result['data'])? $result['data'] : [];
  121. foreach ($lists as &$item){
  122. $touziLevel = isset($item['touzi_level']) ? $item['touzi_level'] : '-1';
  123. $item['touzi_level_name'] = isset($touziarr[$touziLevel]) ? $touziarr[$touziLevel] : '';
  124. }
  125. $this->assign('page',$page);
  126. $this->assign('data',$result);
  127. $this->assign('lists', $lists);
  128. $this->assign('paihang',$paihang);
  129. $this->assign('param',$param);
  130. $this->assign('brandNews',$brandNews);
  131. $this->assign('touziarr',$touziarr);
  132. $this->assign('areaList',$areaList);
  133. $this->assign('cateList',$cateList);
  134. return $this->fetch();
  135. }
  136. /**
  137. * 详情
  138. * @return mixed
  139. * @throws \think\db\exception\DataNotFoundException
  140. * @throws \think\db\exception\ModelNotFoundException
  141. * @throws \think\exception\DbException
  142. */
  143. public function show(){
  144. $param = $this->request->param();
  145. isset($param['id']) or $this->error('需要id');
  146. $info = Db::name('jiameng')->where('id',$param['id'])->find();
  147. //内容
  148. $content = Db::name('jiameng_data')->where('id',$param['id'])->find();
  149. $info['content'] = $content['content'];
  150. $info['youshi'] = $content['youshi'];
  151. $info['tiaojian'] = $content['tiaojian'];
  152. $info['liucheng'] = $content['liucheng'];
  153. $info['jm_support'] = isset($info['jm_support']) && $info['jm_support']? explode(',', $info['jm_support']) : [];
  154. $catinfo = Db::name('category')->where('id',$info['catid'])->find();
  155. $parinfo = Db::name('category')->where('id',$catinfo['parent_id'])->find();
  156. $touziarr = config('params.touziLevels');
  157. //热门行业
  158. $hot_cate = Db::name('category')->where('parent_id',$parinfo['id'])->order('list_order')->limit(12)->select();
  159. //排行
  160. $paihang = Db::name('jiameng')->field('id,title,logo,touzi_level,mendian,hits')->where('catid',$info['catid'])->order('hits desc')->limit(5)->select();
  161. //动态
  162. $about_news = Db::name('news')->field('id,title,thumb,create_time')->where('ncatid',1)->order('id desc')->limit(6)->select();
  163. $brand_news = Db::name('news')->field('id,title,create_time')->where('catid',$info['catid'])->order('id desc')->limit(6)->select();
  164. //热门加盟
  165. $hot_jm = Db::name('jiameng')->field('id,title,hits')->where('catid',$info['catid'])->order('hits desc')->limit(20)->select();
  166. //最新加盟
  167. $zx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->order('create_time desc')->limit(20)->select();
  168. //精选加盟
  169. $jx_jm = Db::name('jiameng')->field('id,title')->where('catid',$info['catid'])->orderRaw('rand()')->limit(20)->select();
  170. //seo
  171. $seo_title = str_replace('|',$info['title'],$catinfo['seo_title']);
  172. $seo_keywords = str_replace('|',$info['title'],$catinfo['seo_keywords']);
  173. $seo_desc = mb_substr($info['content'],0,200,'utf8');
  174. $seo_desc = strip_tags($seo_desc);
  175. $link_cate_name = $parinfo['enname'];
  176. // $this->assign('link_cate_name',$link_cate_name);
  177. $this->assign('seo_title',$seo_title);
  178. $this->assign('seo_keywords',$seo_keywords);
  179. $this->assign('seo_desc',$seo_desc);
  180. $this->assign('hot_jm',$hot_jm);
  181. $this->assign('zx_jm',$zx_jm);
  182. $this->assign('jx_jm',$jx_jm);
  183. $this->assign('about_news',$about_news);
  184. $this->assign('brand_news',$brand_news);
  185. $this->assign('paihang',$paihang);
  186. $this->assign('hot_cate',$hot_cate);
  187. $this->assign('touziarr',$touziarr);
  188. $this->assign('catinfo',$catinfo);
  189. $this->assign('parinfo',$parinfo);
  190. $this->assign('info',$info);
  191. return $this->fetch();
  192. }
  193. public function message(){
  194. $param = $this->request->param();
  195. // isset($param['name'])&&$param['name']!='' or $this->error('请填写姓名');
  196. isset($param['mobile'])&&$param['mobile']!='' or $this->error('请填写手机号');
  197. $param['create_time'] = time();
  198. $param['ip'] = get_client_ip();
  199. $param['address'] = IpService::getAddress(get_client_ip());
  200. $todaytime = strtotime(date('Y-m-d'));
  201. if(strlen($param['content'])>300){
  202. $this->error('字符长度不超过300个');
  203. }
  204. if(isset($param['tzed']) && $param['tzed']<=0){
  205. $this->error('请选择投资额度');
  206. }
  207. $param['content'] = $this->strFilter($param['content']);
  208. $param['name'] = $this->strFilter($param['name']);
  209. $param['mobile'] = $this->strFilter($param['mobile']);
  210. $param['tzed'] = $this->strFilter($param['tzed']);
  211. $param['area'] = $this->strFilter($param['area']);
  212. $param['wechat'] = $this->strFilter($param['wechat']);
  213. // print_r($param);exit;
  214. //判断是否已超过10次 今天这个ip是否留言过
  215. $sum = Db::name('message')->where('ip',$param['ip'])->where('create_time','gt',$todaytime)->count();
  216. if($sum>0){
  217. $this->error('今日留言已超过1次,明天再来吧!');
  218. }
  219. //判断手机号本周内是否留过
  220. // 当前日期
  221. $sdefaultDate = date("Y-m-d");
  222. // $first =1 表示每周星期一为开始日期 0表示每周日为开始日期
  223. $first=1;
  224. // 获取当前周的第几天 周日是0 周一到周六是 1 - 6
  225. $w = date('w', strtotime($sdefaultDate));
  226. // 获取本周开始日期,如果$w是0,则表示周日,减去 6 天
  227. $week_start=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
  228. $sum = Db::name('message')->where('mobile',$param['mobile'])->where('create_time','gt',$week_start)->count();
  229. if($sum>0){
  230. $this->error('您的手机号在本周内已预留过,下周再来吧!');
  231. }
  232. $res = Db::name('message')->insert($param);
  233. if($res){
  234. $this->success('咨询成功');
  235. }else{
  236. $this->error('咨询失败');
  237. }
  238. }
  239. public function strFilter($str){
  240. $str = str_replace('`', '', $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. return trim($str);
  292. }
  293. }
  294. ?>