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.

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