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.

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