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.

488 lines
16 KiB

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