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.

210 lines
7.2 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
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use App\Http\Controllers\Weixin\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 jump()
  14. {
  15. return view('weixin.index.jump');
  16. }
  17. //首页
  18. public function index()
  19. {
  20. //banner轮播图
  21. $postdata = array(
  22. 'limit' => 5,
  23. 'offset' => 0
  24. );
  25. $url = env('APP_API_URL')."/slide_list";
  26. $slide_list = curl_request($url,$postdata,'GET');
  27. $data['slide_list'] = $slide_list['data']['list'];
  28. //最新资讯
  29. $postdata = array(
  30. 'limit' => 5,
  31. 'offset' => 0
  32. );
  33. $url = env('APP_API_URL')."/article_list";
  34. $article_list = curl_request($url,$postdata,'GET');
  35. $data['article_list'] = $article_list['data']['list'];
  36. //商品列表
  37. $postdata = array(
  38. 'limit' => 10,
  39. 'offset' => 0
  40. );
  41. $url = env('APP_API_URL')."/goods_list";
  42. $goods_list = curl_request($url,$postdata,'GET');
  43. $data['goods_list'] = $goods_list['data']['list'];
  44. return view('weixin.index.index',$data);
  45. }
  46. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  47. public function tag($tag, $page=0)
  48. {
  49. $pagenow = $page;
  50. if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');}
  51. $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1);
  52. $data['post'] = $post;
  53. $counts=DB::table("taglist")->where('tid',$tag)->count('aid');
  54. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  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. $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  65. foreach($posts as $row)
  66. {
  67. $aid[] = $row["aid"];
  68. }
  69. $aid = isset($aid)?implode(',',$aid):"";
  70. if($aid!="")
  71. {
  72. if($post['template']=='tag2')
  73. {
  74. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
  75. }
  76. else
  77. {
  78. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
  79. }
  80. }
  81. else
  82. {
  83. $data['posts'] = ''; //获取列表
  84. }
  85. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
  86. if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}}
  87. return view('weixin.index.'.$post['template'], $data);
  88. }
  89. //标签页
  90. public function tags()
  91. {
  92. return view('weixin.index.tags');
  93. }
  94. //搜索页
  95. public function search()
  96. {
  97. return view('weixin.index.search');
  98. }
  99. //单页面
  100. public function page($id)
  101. {
  102. $data = [];
  103. if(!empty($id) && preg_match('/[a-z0-9]+/',$id))
  104. {
  105. $map['filename']=$id;
  106. 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));}
  107. if($post)
  108. {
  109. $data['post'] = $post;
  110. }
  111. else
  112. {
  113. return redirect()->route('page404');
  114. }
  115. }
  116. else
  117. {
  118. return redirect()->route('page404');
  119. }
  120. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  121. return view('weixin.index.'.$post['template'], $data);
  122. }
  123. //商品列表页
  124. public function goodslist(Request $request)
  125. {
  126. if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');}
  127. if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');}
  128. if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');}
  129. if($request->input('status', '') != ''){$data['status'] = $request->input('status');}
  130. if($request->input('is_promote', '') != ''){$data['is_promote'] = $request->input('is_promote');}
  131. if($request->input('orderby', '') != ''){$data['orderby'] = $request->input('orderby');}
  132. if($request->input('max_price', '') != ''){$data['max_price'] = $request->input('max_price');}else{$data['max_price'] = 99999;}
  133. if($request->input('min_price', '') != ''){$data['min_price'] = $request->input('min_price');}else{$data['min_price'] = 0;}
  134. return view('weixin.index.goodslist', $data);
  135. }
  136. //商品详情页
  137. public function goods($id)
  138. {
  139. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  140. $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');
  141. if($post)
  142. {
  143. $cat = $post['typeid'];
  144. $post['body'] = ReplaceKeyword($post['body']);
  145. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  146. $data['post'] = $post;
  147. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  148. }
  149. else
  150. {
  151. return redirect()->route('page404');
  152. }
  153. $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);
  154. return view('weixin.index.'.$post['temparticle'], $data);
  155. }
  156. //sitemap页面
  157. public function sitemap()
  158. {
  159. return view('weixin.index.sitemap');
  160. }
  161. //404页面
  162. public function page404()
  163. {
  164. return view('weixin.404');
  165. }
  166. //测试页面
  167. public function test()
  168. {return view('weixin.index.test');
  169. //return base_path('resources/org');
  170. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  171. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  172. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  173. //set_exception_handler('myException');
  174. //return uniqid();
  175. //return \App\Common\Helper::formatPrice(1.2346);
  176. }
  177. }