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.

286 lines
11 KiB

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