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.

485 lines
18 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
7 years ago
7 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
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
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 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
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
7 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. $postdata = array(
  17. 'tuijian' => 1,
  18. 'status' => 0,
  19. 'limit' => 6,
  20. 'offset' => 0
  21. );
  22. $url = env('APP_API_URL')."/goods_list";
  23. $res = curl_request($url,$postdata,'GET');
  24. $data['tjlist'] = $res['data']['list'];
  25. //商品列表
  26. $pagesize = 15;
  27. $offset = 0;
  28. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  29. $postdata = array(
  30. 'status' => 0,
  31. 'limit' => $pagesize,
  32. 'offset' => $offset
  33. );
  34. $url = env('APP_API_URL')."/goods_list";
  35. $res = curl_request($url,$postdata,'GET');
  36. $data['list'] = $res['data']['list'];
  37. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  38. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  39. {
  40. $html = '';
  41. if($res['data']['list'])
  42. {
  43. foreach($res['data']['list'] as $k => $v)
  44. {
  45. $html .= '<li><a href="'.route('home_goods',array('id'=>$v['id'])).'" target="_blank"><img src="'.$v['litpic'].'" alt="'.$v['title'].'">';
  46. $html .= '<p class="title">'.$v['title'].'</p>';
  47. $html .= '<p class="desc"><span class="price-point"><i></i>库存('.$v['goods_number'].')</span> '.$v['description'].'</p>';
  48. $html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">'.ceil($v['price']).'</span></em></div>';
  49. $html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥'.$v['market_price'].'</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>'.$v['sale'].'</em> 件已付款</div></div></div></div></div></a></li>';
  50. /* if($v['is_promote_goods']>0)
  51. {
  52. $html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>';
  53. }
  54. $html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>';
  55. $html .= '</li>'; */
  56. }
  57. }
  58. exit(json_encode($html));
  59. }
  60. //商品分类列表
  61. $postdata = array(
  62. 'pid' => 0,
  63. 'limit' => 15,
  64. 'offset' => 0
  65. );
  66. $url = env('APP_API_URL')."/goodstype_list";
  67. $res = curl_request($url,$postdata,'GET');
  68. $data['goodstype_list'] = $res['data']['list'];
  69. //banner轮播图
  70. $postdata = array(
  71. 'type' => 0,
  72. 'limit' => 5,
  73. 'offset' => 0
  74. );
  75. $url = env('APP_API_URL')."/slide_list";
  76. $res = curl_request($url,$postdata,'GET');
  77. $data['slide_list'] = $res['data']['list'];
  78. return view('home.index.index',$data);
  79. }
  80. //商品列表页
  81. public function goodslist(Request $request)
  82. {
  83. if($request->input('typeid', null) != null){$postdata['typeid'] = $request->input('typeid');}
  84. if($request->input('orderby', null) != null){$postdata['orderby'] = $request->input('orderby');}
  85. if($request->input('tuijian', null) != null){$postdata['tuijian'] = $request->input('tuijian');}
  86. $pagesize = 15;
  87. $offset = 0;
  88. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  89. //商品列表
  90. $postdata['limit'] = $pagesize;
  91. $postdata['offset'] = $offset;
  92. $url = env('APP_API_URL')."/goods_list";
  93. $res = curl_request($url,$postdata,'GET');
  94. $data['list'] = $res['data']['list'];
  95. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  96. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  97. {
  98. $html = '';
  99. if($res['data']['list'])
  100. {
  101. foreach($res['data']['list'] as $k => $v)
  102. {
  103. $html .= '<li><a href="'.route('home_goods',array('id'=>$v['id'])).'" target="_blank"><img src="'.$v['litpic'].'" alt="'.$v['title'].'">';
  104. $html .= '<p class="title">'.$v['title'].'</p>';
  105. $html .= '<p class="desc"><span class="price-point"><i></i>库存('.$v['goods_number'].')</span> '.$v['description'].'</p>';
  106. $html .= '<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen">'.ceil($v['price']).'</span></em></div>';
  107. $html .= '<div class="dock"><div class="dock-price"><del class="orig-price">¥'.$v['market_price'].'</del> <span class="benefit">包邮</span></div><div class="prompt"><div class="sold-num"><em>'.$v['sale'].'</em> 件已付款</div></div></div></div></div></a></li>';
  108. /* if($v['is_promote_goods']>0)
  109. {
  110. $html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>';
  111. }
  112. $html .= $v['title'].'</p><div class="goods_price">¥<b>'.$v['price'].'</b><span class="fr">'.$v['sale'].'人付款</span></div></div></a>';
  113. $html .= '</li>'; */
  114. }
  115. }
  116. exit(json_encode($html));
  117. }
  118. //商品分类列表
  119. $postdata = array(
  120. 'pid' => 0,
  121. 'limit' => 15,
  122. 'offset' => 0
  123. );
  124. $url = env('APP_API_URL')."/goodstype_list";
  125. $res = curl_request($url,$postdata,'GET');
  126. $data['goodstype_list'] = $res['data']['list'];
  127. return view('home.index.goodslist', $data);
  128. }
  129. //商品详情页
  130. public function goods($id)
  131. {
  132. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  133. $where['id'] = $id;
  134. $where['status'] = 0;
  135. $data['post'] = logic('Goods')->getOne($where);
  136. if(!$data['post']){return redirect()->route('page404');}
  137. $data['tj_list'] = DB::table('goods')->where(['tuijian'=>1,'status'=>0])->orderBy('id', 'desc')->get();
  138. return view('home.index.goods', $data);
  139. }
  140. //商品列表页
  141. public function brandList(Request $request)
  142. {
  143. $data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status'=>0])->take(30)->orderBy('listorder','asc')->get());
  144. return view('home.index.brandList', $data);
  145. }
  146. //网址组装
  147. public function listpageurl($http_host,$query_string,$page=0)
  148. {
  149. $res = '';
  150. foreach(explode("&",$query_string) as $row)
  151. {
  152. if($row)
  153. {
  154. $canshu = explode("=",$row);
  155. $res[$canshu[0]] = $canshu[1];
  156. }
  157. }
  158. if(isset($res['page']))
  159. {
  160. unset($res['page']);
  161. }
  162. if($page==1 || $page==0){}else{$res['page'] = $page;}
  163. if($res){$res = $http_host.'?'.http_build_query($res);}
  164. return $res;
  165. }
  166. //列表页
  167. public function category(Request $request)
  168. {
  169. $pagesize = 10;
  170. $offset = 0;
  171. //文章分类
  172. $postdata = array(
  173. 'id' => $cat
  174. );
  175. $url = env('APP_API_URL')."/arctype_detail";
  176. $arctype_detail = curl_request($url,$postdata,'GET');
  177. $data['post'] = $arctype_detail['data'];
  178. dd($data['post']);
  179. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  180. //文章列表
  181. $postdata2['limit'] = $limit;
  182. $postdata2['offset'] = $offset;
  183. if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');}
  184. $url = env('APP_API_URL')."/article_list";
  185. $res = curl_request($url,$postdata2,'GET');
  186. $data['list'] = $res['data']['list'];
  187. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  188. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  189. {
  190. $html = '';
  191. if($res['data']['list'])
  192. {
  193. foreach($res['data']['list'] as $k => $v)
  194. {
  195. $html .= '<li><a href="'.$v['article_detail_url'].'">'.$v['title'].'</a><p>'.$v['pubdate'].'</p></li>';
  196. }
  197. }
  198. exit(json_encode($html));
  199. }
  200. return view('home.index.'.$data['post']['templist'], $data);
  201. }
  202. //文章列表页
  203. public function arclist(Request $request)
  204. {
  205. $pagesize = 10;
  206. $offset = 0;
  207. //文章分类
  208. if($request->input('typeid', null) != null)
  209. {
  210. $postdata = array(
  211. 'id' => $request->input('typeid')
  212. );
  213. $url = env('APP_API_URL')."/arctype_detail";
  214. $arctype_detail = curl_request($url,$postdata,'GET');
  215. $data['post'] = $arctype_detail['data'];
  216. }
  217. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  218. //文章列表
  219. $postdata2 = array(
  220. 'limit' => $pagesize,
  221. 'offset' => $offset
  222. );
  223. if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');}
  224. $url = env('APP_API_URL')."/article_list";
  225. $res = curl_request($url,$postdata2,'GET');
  226. $data['list'] = $res['data']['list'];
  227. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  228. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  229. {
  230. $html = '';
  231. if($res['data']['list'])
  232. {
  233. foreach($res['data']['list'] as $k => $v)
  234. {
  235. $html .= '<div class="list">';
  236. if(!empty($v['litpic']))
  237. {
  238. $html .= '<a class="limg" href="'.get_front_url(array("id"=>$v['id'],"catid"=>$v['typeid'],"type"=>'content')).'"><img alt="'.$v['title'].'" src="'.$v['litpic'].'"></a>';
  239. }
  240. $html .= '<strong class="tit"><a href="'.get_front_url(array("id"=>$v['id'],"catid"=>$v['typeid'],"type"=>'content')).'">'.$v['title'].'</a></strong><p>'.mb_strcut($v['description'],0,150,'UTF-8').'..</p>';
  241. $html .= '<div class="info"><span class="fl">';
  242. $taglist=taglist($v['id']);
  243. if($taglist)
  244. {
  245. foreach($taglist as $row)
  246. {
  247. $html .= '<a href="'.get_front_url(array("tagid"=>$row['id'],"type"=>'tags')).'">'.$row['tag'].'</a>';
  248. }
  249. }
  250. $html .= '<em>'.date("m-d H:i",$v['pubdate']).'</em></span><span class="fr"><em>'.$v['click'].'</em>人阅读</span></div><div class="cl"></div></div>';
  251. }
  252. }
  253. exit(json_encode($html));
  254. }
  255. return view('home.index.arclist', $data);
  256. }
  257. //文章详情页
  258. public function detail($id)
  259. {
  260. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  261. 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));}
  262. if($post)
  263. {
  264. $cat = $post['typeid'];
  265. $post['body'] = ReplaceKeyword($post['body']);
  266. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  267. $data['post'] = $post;
  268. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  269. }
  270. else
  271. {
  272. return redirect()->route('page404');
  273. }
  274. 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));}
  275. return view('home.index.'.$post['temparticle'], $data);
  276. }
  277. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  278. public function tag($tag, $page=0)
  279. {
  280. $pagenow = $page;
  281. if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');}
  282. $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1);
  283. $data['post'] = $post;
  284. $counts=DB::table("taglist")->where('tid',$tag)->count('aid');
  285. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  286. $pagesize=sysconfig('CMS_PAGESIZE');$page=0;
  287. if($counts % $pagesize){//取总数据量除以每页数的余数
  288. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  289. }else{$pages = $counts/$pagesize;}
  290. 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;}
  291. $data['page'] = $page;
  292. $data['pages'] = $pages;
  293. $data['counts'] = $counts;
  294. $start=$page*$pagesize;
  295. $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  296. foreach($posts as $row)
  297. {
  298. $aid[] = $row["aid"];
  299. }
  300. $aid = isset($aid)?implode(',',$aid):"";
  301. if($aid!="")
  302. {
  303. if($post['template']=='tag2')
  304. {
  305. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
  306. }
  307. else
  308. {
  309. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
  310. }
  311. }
  312. else
  313. {
  314. $data['posts'] = ''; //获取列表
  315. }
  316. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
  317. if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}}
  318. return view('home.index.'.$post['template'], $data);
  319. }
  320. //标签页
  321. public function tags()
  322. {
  323. return view('home.index.tags');
  324. }
  325. //搜索页
  326. public function search($keyword)
  327. {
  328. if(empty($keyword))
  329. {
  330. echo '请输入正确的关键词';exit;
  331. }
  332. if(strstr($keyword,"&")) exit;
  333. $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get());
  334. $data['keyword']= $keyword;
  335. return view('home.index.search', $data);
  336. }
  337. //单页面
  338. public function page($id)
  339. {
  340. $data = [];
  341. if(!empty($id) && preg_match('/[a-z0-9]+/',$id))
  342. {
  343. $map['filename']=$id;
  344. 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));}
  345. if($post)
  346. {
  347. $data['post'] = $post;
  348. }
  349. else
  350. {
  351. return redirect()->route('page404');
  352. }
  353. }
  354. else
  355. {
  356. return redirect()->route('page404');
  357. }
  358. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  359. return view('home.index.'.$post['template'], $data);
  360. }
  361. //sitemap页面
  362. public function sitemap()
  363. {
  364. return view('home.index.sitemap');
  365. }
  366. //404页面
  367. public function page404()
  368. {
  369. return view('home.404');
  370. }
  371. //验证消息的确来自微信服务器
  372. public function checksignature()
  373. {
  374. $signature = $_GET["signature"];
  375. $timestamp = $_GET["timestamp"];
  376. $nonce = $_GET["nonce"];
  377. $echoStr = $_GET["echostr"];
  378. $token = 'fanli';
  379. $tmpArr = array($token, $timestamp, $nonce);
  380. sort($tmpArr, SORT_STRING);
  381. $tmpStr = implode( $tmpArr );
  382. $tmpStr = sha1( $tmpStr );
  383. if( $tmpStr == $signature ){
  384. exit($echoStr);
  385. }else{
  386. return false;
  387. }
  388. }
  389. //测试页面
  390. public function test()
  391. {return view('home.index.test');
  392. //return base_path('resources/org');
  393. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  394. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  395. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  396. //set_exception_handler('myException');
  397. //return uniqid();
  398. //return \App\Common\Helper::formatPrice(1.2346);
  399. }
  400. }