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.

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