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.

269 lines
11 KiB

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
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
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
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
  1. <?php
  2. namespace App\Http\Controllers\Home;
  3. use App\Http\Controllers\Home\CommonController;
  4. use Illuminate\Support\Facades\DB;
  5. class IndexController extends CommonController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. //首页
  12. public function index()
  13. {
  14. return view('home.index.index');
  15. }
  16. //列表页
  17. public function category($cat, $page=0)
  18. {
  19. $pagenow = $page;
  20. if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');}
  21. 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));}
  22. $data['post'] = $post;
  23. $subcat="";$sql="";
  24. $post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get());
  25. if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}}
  26. $subcat=$subcat."typeid=".$cat;
  27. $sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit;
  28. $data['sql'] = $sql;
  29. $counts = DB::table("article")->whereRaw($sql)->count();
  30. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);}
  31. $pagesize = sysconfig('CMS_PAGESIZE');$page=0;
  32. if($counts % $pagesize){//取总数据量除以每页数的余数
  33. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  34. }else{$pages = $counts/$pagesize;}
  35. 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;}
  36. $data['page'] = $page;
  37. $data['pages'] = $pages;
  38. $data['counts'] = $counts;
  39. $start = $page*$pagesize;
  40. $data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表
  41. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表
  42. if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}}
  43. return view('home.index.'.$post['templist'], $data);
  44. }
  45. //文章详情页
  46. public function detail($id)
  47. {
  48. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  49. 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));}
  50. if($post)
  51. {
  52. $cat = $post['typeid'];
  53. $post['body'] = ReplaceKeyword($post['body']);
  54. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  55. $data['post'] = $post;
  56. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  57. }
  58. else
  59. {
  60. return redirect()->route('page404');
  61. }
  62. 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));}
  63. return view('home.index.'.$post['temparticle'], $data);
  64. }
  65. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  66. public function tag($tag, $page=0)
  67. {
  68. $pagenow = $page;
  69. if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');}
  70. $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1);
  71. $data['post'] = $post;
  72. $counts=DB::table("taglist")->where('tid',$tag)->count('aid');
  73. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  74. $pagesize=sysconfig('CMS_PAGESIZE');$page=0;
  75. if($counts % $pagesize){//取总数据量除以每页数的余数
  76. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  77. }else{$pages = $counts/$pagesize;}
  78. 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;}
  79. $data['page'] = $page;
  80. $data['pages'] = $pages;
  81. $data['counts'] = $counts;
  82. $start=$page*$pagesize;
  83. $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  84. foreach($posts as $row)
  85. {
  86. $aid[] = $row["aid"];
  87. }
  88. $aid = isset($aid)?implode(',',$aid):"";
  89. if($aid!="")
  90. {
  91. if($post['template']=='tag2')
  92. {
  93. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
  94. }
  95. else
  96. {
  97. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
  98. }
  99. }
  100. else
  101. {
  102. $data['posts'] = ''; //获取列表
  103. }
  104. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
  105. if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}}
  106. return view('home.index.'.$post['template'], $data);
  107. }
  108. //标签页
  109. public function tags()
  110. {
  111. return view('home.index.tags');
  112. }
  113. //搜索页
  114. public function search($keyword)
  115. {
  116. if(empty($keyword))
  117. {
  118. echo '请输入正确的关键词';exit;
  119. }
  120. if(strstr($keyword,"&")) exit;
  121. $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get());
  122. $data['keyword']= $keyword;
  123. return view('home.index.search', $data);
  124. }
  125. //单页面
  126. public function page($id)
  127. {
  128. $data = [];
  129. if(!empty($id) && preg_match('/[a-z0-9]+/',$id))
  130. {
  131. $map['filename']=$id;
  132. 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));}
  133. if($post)
  134. {
  135. $data['post'] = $post;
  136. }
  137. else
  138. {
  139. return redirect()->route('page404');
  140. }
  141. }
  142. else
  143. {
  144. return redirect()->route('page404');
  145. }
  146. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  147. return view('home.index.'.$post['template'], $data);
  148. }
  149. //商品列表页
  150. public function goodstype($cat, $page=0)
  151. {
  152. $pagenow = $page;
  153. if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');}
  154. $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');}
  155. $data['post'] = $post;
  156. $subcat="";
  157. $post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get());
  158. if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}}
  159. $subcat=$subcat."typeid=".$cat;
  160. $data['sql'] = $subcat;
  161. $counts = DB::table("goods")->whereRaw($subcat)->count();
  162. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);}
  163. $pagesize = sysconfig('CMS_PAGESIZE');$page=0;
  164. if($counts % $pagesize){//取总数据量除以每页数的余数
  165. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  166. }else{$pages = $counts/$pagesize;}
  167. 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;}
  168. $data['page'] = $page;
  169. $data['pages'] = $pages;
  170. $data['counts'] = $counts;
  171. $start = $page*$pagesize;
  172. $data['posts'] = arclist(array("table"=>"goods","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表
  173. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"goods")); //获取分页列表
  174. if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}}
  175. return view('home.index.'.$post['templist'], $data);
  176. }
  177. //商品详情页
  178. public function goods($id)
  179. {
  180. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  181. $post = object_to_array(DB::table('goods')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name');
  182. if($post)
  183. {
  184. $cat = $post['typeid'];
  185. $post['body'] = ReplaceKeyword($post['body']);
  186. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  187. $data['post'] = $post;
  188. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  189. }
  190. else
  191. {
  192. return redirect()->route('page404');
  193. }
  194. $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);
  195. return view('home.index.'.$post['temparticle'], $data);
  196. }
  197. //sitemap页面
  198. public function sitemap()
  199. {
  200. return view('home.index.sitemap');
  201. }
  202. //404页面
  203. public function page404()
  204. {
  205. return view('home.404');
  206. }
  207. //测试页面
  208. public function test()
  209. {return view('home.index.test');
  210. //return base_path('resources/org');
  211. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  212. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  213. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  214. //set_exception_handler('myException');
  215. //return uniqid();
  216. //return \App\Common\Helper::formatPrice(1.2346);
  217. }
  218. }