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.

470 lines
17 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
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
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. $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');
  134. if($post)
  135. {
  136. $data['post'] = $post;
  137. }
  138. else
  139. {
  140. return redirect()->route('page404');
  141. }
  142. $data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get());
  143. DB::table('goods')->where(array('id'=>$id))->increment('click', 1);
  144. return view('home.index.goods', $data);
  145. }
  146. //商品列表页
  147. public function brandList(Request $request)
  148. {
  149. $data['brand_list'] = object_to_array(DB::table('goods_brand')->where(['status'=>0])->take(30)->orderBy('listorder','asc')->get());
  150. return view('home.index.brandList', $data);
  151. }
  152. //网址组装
  153. public function listpageurl($http_host,$query_string,$page=0)
  154. {
  155. $res = '';
  156. foreach(explode("&",$query_string) as $row)
  157. {
  158. if($row)
  159. {
  160. $canshu = explode("=",$row);
  161. $res[$canshu[0]] = $canshu[1];
  162. }
  163. }
  164. if(isset($res['page']))
  165. {
  166. unset($res['page']);
  167. }
  168. if($page==1 || $page==0){}else{$res['page'] = $page;}
  169. if($res){$res = $http_host.'?'.http_build_query($res);}
  170. return $res;
  171. }
  172. //列表页
  173. public function category(Request $request)
  174. {
  175. $pagesize = 10;
  176. $offset = 0;
  177. //文章分类
  178. $postdata = array(
  179. 'id' => $cat
  180. );
  181. $url = env('APP_API_URL')."/arctype_detail";
  182. $arctype_detail = curl_request($url,$postdata,'GET');
  183. $data['post'] = $arctype_detail['data'];
  184. dd($data['post']);
  185. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  186. //文章列表
  187. $postdata2['limit'] = $limit;
  188. $postdata2['offset'] = $offset;
  189. if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');}
  190. $url = env('APP_API_URL')."/article_list";
  191. $res = curl_request($url,$postdata2,'GET');
  192. $data['list'] = $res['data']['list'];
  193. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  194. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  195. {
  196. $html = '';
  197. if($res['data']['list'])
  198. {
  199. foreach($res['data']['list'] as $k => $v)
  200. {
  201. $html .= '<li><a href="'.$v['article_detail_url'].'">'.$v['title'].'</a><p>'.$v['pubdate'].'</p></li>';
  202. }
  203. }
  204. exit(json_encode($html));
  205. }
  206. return view('home.index.'.$data['post']['templist'], $data);
  207. }
  208. //文章列表页
  209. public function arclist(Request $request)
  210. {
  211. $pagesize = 10;
  212. $offset = 0;
  213. //文章分类
  214. if($request->input('typeid', null) != null)
  215. {
  216. $postdata = array(
  217. 'id' => $request->input('typeid')
  218. );
  219. $url = env('APP_API_URL')."/arctype_detail";
  220. $arctype_detail = curl_request($url,$postdata,'GET');
  221. $data['post'] = $arctype_detail['data'];
  222. }
  223. if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
  224. //文章列表
  225. $postdata2 = array(
  226. 'limit' => $pagesize,
  227. 'offset' => $offset
  228. );
  229. if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');}
  230. $url = env('APP_API_URL')."/article_list";
  231. $res = curl_request($url,$postdata2,'GET');
  232. $data['list'] = $res['data']['list'];
  233. $data['totalpage'] = ceil($res['data']['count']/$pagesize);
  234. if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
  235. {
  236. $html = '';
  237. if($res['data']['list'])
  238. {
  239. foreach($res['data']['list'] as $k => $v)
  240. {
  241. $html .= '<div class="list">';
  242. if(!empty($v['litpic']))
  243. {
  244. $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>';
  245. }
  246. $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>';
  247. $html .= '<div class="info"><span class="fl">';
  248. $taglist=taglist($v['id']);
  249. if($taglist)
  250. {
  251. foreach($taglist as $row)
  252. {
  253. $html .= '<a href="'.get_front_url(array("tagid"=>$row['id'],"type"=>'tags')).'">'.$row['tag'].'</a>';
  254. }
  255. }
  256. $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>';
  257. }
  258. }
  259. exit(json_encode($html));
  260. }
  261. return view('home.index.arclist', $data);
  262. }
  263. //文章详情页
  264. public function detail($id)
  265. {
  266. if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
  267. 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));}
  268. if($post)
  269. {
  270. $cat = $post['typeid'];
  271. $post['body'] = ReplaceKeyword($post['body']);
  272. if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];}
  273. $data['post'] = $post;
  274. $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre"));
  275. }
  276. else
  277. {
  278. return redirect()->route('page404');
  279. }
  280. 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));}
  281. return view('home.index.'.$post['temparticle'], $data);
  282. }
  283. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  284. public function tag($tag, $page=0)
  285. {
  286. $pagenow = $page;
  287. if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');}
  288. $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1);
  289. $data['post'] = $post;
  290. $counts=DB::table("taglist")->where('tid',$tag)->count('aid');
  291. if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');}
  292. $pagesize=sysconfig('CMS_PAGESIZE');$page=0;
  293. if($counts % $pagesize){//取总数据量除以每页数的余数
  294. $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  295. }else{$pages = $counts/$pagesize;}
  296. 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;}
  297. $data['page'] = $page;
  298. $data['pages'] = $pages;
  299. $data['counts'] = $counts;
  300. $start=$page*$pagesize;
  301. $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  302. foreach($posts as $row)
  303. {
  304. $aid[] = $row["aid"];
  305. }
  306. $aid = isset($aid)?implode(',',$aid):"";
  307. if($aid!="")
  308. {
  309. if($post['template']=='tag2')
  310. {
  311. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表
  312. }
  313. else
  314. {
  315. $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表
  316. }
  317. }
  318. else
  319. {
  320. $data['posts'] = ''; //获取列表
  321. }
  322. $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表
  323. if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}}
  324. return view('home.index.'.$post['template'], $data);
  325. }
  326. //标签页
  327. public function tags()
  328. {
  329. return view('home.index.tags');
  330. }
  331. //搜索页
  332. public function search($keyword)
  333. {
  334. if(empty($keyword))
  335. {
  336. echo '请输入正确的关键词';exit;
  337. }
  338. if(strstr($keyword,"&")) exit;
  339. $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get());
  340. $data['keyword']= $keyword;
  341. return view('home.index.search', $data);
  342. }
  343. //单页面
  344. public function page($id)
  345. {
  346. $data = [];
  347. if(!empty($id) && preg_match('/[a-z0-9]+/',$id))
  348. {
  349. $map['filename']=$id;
  350. 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));}
  351. if($post)
  352. {
  353. $data['post'] = $post;
  354. }
  355. else
  356. {
  357. return redirect()->route('page404');
  358. }
  359. }
  360. else
  361. {
  362. return redirect()->route('page404');
  363. }
  364. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  365. return view('home.index.'.$post['template'], $data);
  366. }
  367. //sitemap页面
  368. public function sitemap()
  369. {
  370. return view('home.index.sitemap');
  371. }
  372. //404页面
  373. public function page404()
  374. {
  375. return view('home.404');
  376. }
  377. //测试页面
  378. public function test()
  379. {return view('home.index.test');
  380. //return base_path('resources/org');
  381. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  382. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  383. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  384. //set_exception_handler('myException');
  385. //return uniqid();
  386. //return \App\Common\Helper::formatPrice(1.2346);
  387. }
  388. }