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.

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