You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

388 lines
15 KiB

8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Home;
  3. use App\Http\Controllers\Home\CommonController;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Http\Request;
  6. class IndexController extends CommonController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. //首页
  13. public function index()
  14. {
  15. //商品列表
  16. $where['status'] = 0;
  17. $data['goods_list'] = object_to_array(DB::table('goods')->where($where)->select('id','title','price','litpic','description','shipping_fee','market_price','goods_number','sale')->take(30)->orderBy('pubdate','desc')->get());
  18. $data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid'=>0,'status'=>1])->select('id','name')->take(30)->orderBy('listorder','asc')->get());
  19. $data['slide_list'] = object_to_array(DB::table('slide')->where(['group_id'=>0,'type'=>0,'is_show'=>0])->take(30)->orderBy('listorder','asc')->get());
  20. $data['ztad_list'] = object_to_array(DB::table('slide')->where(['group_id'=>1,'type'=>0,'is_show'=>0])->take(30)->orderBy('listorder','asc')->get());
  21. return view('home.index.index',$data);
  22. }
  23. //商品列表页
  24. public function goodslist(Request $request)
  25. {
  26. $typeid = $request->input('id', '');
  27. $page = $request->input('page', '');
  28. //推荐
  29. if($request->input('tuijian', '') != ''){$where['tuijian'] = $request->input('tuijian');}
  30. if($request->input('brand_id', '') != ''){$where['brand_id'] = $request->input('brand_id');DB::table('goods_brand')->where(array('id'=>$where['brand_id']))->increment('click', 1);}
  31. $pagenow = $page;
  32. $post = '';
  33. if($typeid)
  34. {
  35. $where['typeid'] = $typeid;
  36. $post = object_to_array(DB::table('goods_type')->where('id', $typeid)->first(), 1);
  37. }
  38. $data['post'] = $post;
  39. $goods = DB::table("goods");
  40. if(isset($where)){$goods = $goods->where($where);}
  41. if($request->input('keyword', '') != ''){$goods = $goods->where('title', 'like', '%'.$request->input('keyword').'%');}
  42. $counts = $goods->count();
  43. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  44. $pagesize = sysconfig('CMS_PAGESIZE');$page=0;
  45. if($counts % $pagesize){//取总数据量除以每页数的余数
  46. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  47. }else{$pages = $counts/$pagesize;}
  48. if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;}
  49. $data['page'] = $page;
  50. $data['pages'] = $pages;
  51. $data['counts'] = $counts;
  52. $start = $page*$pagesize;
  53. //排序
  54. if($request->input('orderby', null) != null)
  55. {
  56. switch ($request->input('orderby'))
  57. {
  58. case 1:
  59. $goods = $goods->orderBy('sale','desc'); //销量从高到低
  60. break;
  61. case 2:
  62. $goods = $goods->orderBy('comments','desc'); //评论从高到低
  63. break;
  64. case 3:
  65. $goods = $goods->orderBy('price','desc'); //价格从高到低
  66. break;
  67. case 4:
  68. $goods = $goods->orderBy('price','asc'); //价格从低到高
  69. break;
  70. case 5:
  71. $timestamp = time();
  72. $goods = $goods->where('promote_start_date','<=',$timestamp)->where('promote_end_date','>=',$timestamp); //促销商品
  73. break;
  74. default:
  75. $goods = $goods->orderBy('pubdate','desc'); //最新
  76. }
  77. }
  78. $posts = object_to_array($goods->skip($start)->take($pagesize)->get());
  79. $data['posts'] = $posts; //获取列表
  80. $data['pagenav'] = '';if($nextpage<=$pages && $nextpage>0){$data['pagenav'] = $this->listpageurl(route('home_goodslist'),$_SERVER['QUERY_STRING'],$nextpage);}
  81. $data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid'=>0,'status'=>1])->select('id','name')->take(30)->orderBy('listorder','asc')->get());
  82. $data['id'] = $typeid;
  83. return view('home.index.goodslist', $data);
  84. }
  85. //商品详情页
  86. public function goods($id)
  87. {
  88. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  89. $post = object_to_array(DB::table('goods')->where(['id'=>$id,'status'=>0])->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['type_name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name');
  90. if($post)
  91. {
  92. $data['post'] = $post;
  93. }
  94. else
  95. {
  96. return redirect()->route('page404');
  97. }
  98. $data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get());
  99. DB::table('goods')->where(array('id'=>$id))->increment('click', 1);
  100. return view('home.index.goods', $data);
  101. }
  102. //商品列表页
  103. public function brandList(Request $request)
  104. {
  105. $data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status'=>0])->take(30)->orderBy('listorder','asc')->get());
  106. return view('home.index.brandList', $data);
  107. }
  108. //网址组装
  109. public function listpageurl($http_host,$query_string,$page=0)
  110. {
  111. $res = '';
  112. foreach(explode("&",$query_string) as $row)
  113. {
  114. if($row)
  115. {
  116. $canshu = explode("=",$row);
  117. $res[$canshu[0]] = $canshu[1];
  118. }
  119. }
  120. if(isset($res['page']))
  121. {
  122. unset($res['page']);
  123. }
  124. if($page==1 || $page==0){}else{$res['page'] = $page;}
  125. if($res){$res = $http_host.'?'.http_build_query($res);}
  126. return $res;
  127. }
  128. //列表页
  129. public function category($cat, $page=0)
  130. {
  131. $pagenow = $page;
  132. if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');}
  133. if(cache("catid$cat")){$post = cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));}
  134. $data['post'] = $post;
  135. $subcat="";$sql="";
  136. $post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get());
  137. if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}}
  138. $subcat=$subcat."typeid=".$cat;
  139. $sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit;
  140. $data['sql'] = $sql;
  141. $counts = DB::table("article")->whereRaw($sql)->count();
  142. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);}
  143. $pagesize = sysconfig('CMS_PAGESIZE');$page=0;
  144. if($counts % $pagesize){//取总数据量除以每页数的余数
  145. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  146. }else{$pages = $counts/$pagesize;}
  147. if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;}
  148. $data['page'] = $page;
  149. $data['pages'] = $pages;
  150. $data['counts'] = $counts;
  151. $start = $page*$pagesize;
  152. $data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表
  153. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表
  154. if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}}
  155. return view('home.index.'.$post['templist'], $data);
  156. }
  157. //文章列表页
  158. public function arclist(Request $request)
  159. {
  160. $cat = $request->input('id', '');
  161. $page = $request->input('page', '');
  162. $pagenow = $page;
  163. $post = '';
  164. if($cat)
  165. {
  166. $where['typeid'] = $cat;
  167. $post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);
  168. }
  169. $data['post'] = $post;
  170. $article = DB::table("article");
  171. if(isset($where)){$article = $article->where($where);}
  172. $counts = $article->count();
  173. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);}
  174. $pagesize = sysconfig('CMS_PAGESIZE');$page=0;
  175. if($counts % $pagesize){//取总数据量除以每页数的余数
  176. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  177. }else{$pages = $counts/$pagesize;}
  178. if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;}
  179. $data['page'] = $page;
  180. $data['pages'] = $pages;
  181. $data['counts'] = $counts;
  182. $start = $page*$pagesize;
  183. $posts = object_to_array($article->skip($start)->take($pagesize)->get());
  184. $data['posts'] = $posts; //获取列表
  185. $data['pagenav'] = '';if($nextpage<=$pages && $nextpage>0){$data['pagenav'] = $this->listpageurl(route('home_arclist'),$_SERVER['QUERY_STRING'],$nextpage);}
  186. $data['arctype_list'] = object_to_array(DB::table('arctype')->where(['pid'=>0,'is_show'=>0])->select('id','name')->take(30)->orderBy('listorder','asc')->get());
  187. $data['id'] = $cat;
  188. return view('home.index.arclist', $data);
  189. }
  190. //文章详情页
  191. public function detail($id)
  192. {
  193. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  194. if(cache("detailid$id")){$post = cache("detailid$id");}else{$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name');cache(["detailid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));}
  195. if($post)
  196. {
  197. $cat = $post['typeid'];
  198. $post['body'] = ReplaceKeyword($post['body']);
  199. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  200. $data['post'] = $post;
  201. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  202. }
  203. else
  204. {
  205. return redirect()->route('page404');
  206. }
  207. if(cache("catid$cat")){$post=cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));}
  208. return view('home.index.'.$post['temparticle'], $data);
  209. }
  210. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  211. public function tag($tag, $page=0)
  212. {
  213. $pagenow = $page;
  214. if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');}
  215. $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1);
  216. $data['post'] = $post;
  217. $counts=DB::table("taglist")->where('tid',$tag)->count('aid');
  218. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  219. $pagesize=sysconfig('CMS_PAGESIZE');$page=0;
  220. if($counts % $pagesize){//取总数据量除以每页数的余数
  221. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  222. }else{$pages = $counts/$pagesize;}
  223. if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;}
  224. $data['page'] = $page;
  225. $data['pages'] = $pages;
  226. $data['counts'] = $counts;
  227. $start=$page*$pagesize;
  228. $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  229. foreach($posts as $row)
  230. {
  231. $aid[] = $row["aid"];
  232. }
  233. $aid = isset($aid)?implode(',',$aid):"";
  234. if($aid!="")
  235. {
  236. if($post['template']=='tag2')
  237. {
  238. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
  239. }
  240. else
  241. {
  242. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
  243. }
  244. }
  245. else
  246. {
  247. $data['posts'] = ''; //获取列表
  248. }
  249. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
  250. if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}}
  251. return view('home.index.'.$post['template'], $data);
  252. }
  253. //标签页
  254. public function tags()
  255. {
  256. return view('home.index.tags');
  257. }
  258. //搜索页
  259. public function search($keyword)
  260. {
  261. if(empty($keyword))
  262. {
  263. echo '请输入正确的关键词';exit;
  264. }
  265. if(strstr($keyword,"&")) exit;
  266. $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get());
  267. $data['keyword']= $keyword;
  268. return view('home.index.search', $data);
  269. }
  270. //单页面
  271. public function page($id)
  272. {
  273. $data = [];
  274. if(!empty($id) && preg_match('/[a-z0-9]+/',$id))
  275. {
  276. $map['filename']=$id;
  277. if(cache("pageid$id")){$post=cache("pageid$id");}else{$post = object_to_array(DB::table('page')->where($map)->first(), 1);cache("pageid$id", $post, 2592000);cache(["pageid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));}
  278. if($post)
  279. {
  280. $data['post'] = $post;
  281. }
  282. else
  283. {
  284. return redirect()->route('page404');
  285. }
  286. }
  287. else
  288. {
  289. return redirect()->route('page404');
  290. }
  291. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  292. return view('home.index.'.$post['template'], $data);
  293. }
  294. //sitemap页面
  295. public function sitemap()
  296. {
  297. return view('home.index.sitemap');
  298. }
  299. //404页面
  300. public function page404()
  301. {
  302. return view('home.404');
  303. }
  304. //测试页面
  305. public function test()
  306. {return view('home.index.test');
  307. //return base_path('resources/org');
  308. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  309. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  310. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  311. //set_exception_handler('myException');
  312. //return uniqid();
  313. //return \App\Common\Helper::formatPrice(1.2346);
  314. }
  315. }