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.

499 lines
17 KiB

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