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.

306 lines
9.9 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
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
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 BaseController
  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(Request $request)
  19. {
  20. //分享到首页,把推荐id存下来
  21. if (isset($_REQUEST['invite_code']) && !empty($_REQUEST['invite_code'])) {
  22. $_SESSION['weixin_user_invite_code'] = $_REQUEST['invite_code'];
  23. }
  24. //banner轮播图
  25. $postdata = array(
  26. 'type' => 1,
  27. 'limit' => 5,
  28. 'offset' => 0
  29. );
  30. $url = env('APP_API_URL') . "/slide_list";
  31. $res = curl_request($url, $postdata, 'GET');
  32. $data['slide_list'] = $res['data']['list'];
  33. //最新资讯
  34. $postdata = array(
  35. 'limit' => 5,
  36. 'offset' => 0
  37. );
  38. $url = env('APP_API_URL') . "/article_list";
  39. $res = curl_request($url, $postdata, 'GET');
  40. $data['article_list'] = $res['data']['list'];
  41. //最新商品列表
  42. $postdata = array(
  43. 'limit' => 8,
  44. 'offset' => 0
  45. );
  46. $url = env('APP_API_URL') . "/goods_list";
  47. $res = curl_request($url, $postdata, 'GET');
  48. $data['goods_list'] = $res['data']['list'];
  49. //商品推荐
  50. $postdata = array(
  51. 'tuijian' => 1,
  52. 'limit' => 6,
  53. 'offset' => 0
  54. );
  55. $url = env('APP_API_URL') . "/goods_list";
  56. $res = curl_request($url, $postdata, 'GET');
  57. $data['goods_recommend_list'] = $res['data']['list'];
  58. //畅销商品列表
  59. $postdata = array(
  60. 'orderby' => 1,
  61. 'limit' => 6,
  62. 'offset' => 0
  63. );
  64. $url = env('APP_API_URL') . "/goods_list";
  65. $res = curl_request($url, $postdata, 'GET');
  66. $data['goods_sale_list'] = $res['data']['list'];
  67. //促销、优惠商品列表
  68. $postdata = array(
  69. 'orderby' => 5,
  70. 'limit' => 4,
  71. 'offset' => 0
  72. );
  73. $url = env('APP_API_URL') . "/goods_list";
  74. $res = curl_request($url, $postdata, 'GET');
  75. $data['goods_promote_list'] = $res['data']['list'];
  76. return view('weixin.index.index', $data);
  77. }
  78. //分类
  79. public function category()
  80. {
  81. $data['aaa'] = 111;
  82. return view('weixin.index.category', $data);
  83. }
  84. //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述
  85. public function tag($tag, $page = 0)
  86. {
  87. $pagenow = $page;
  88. if (empty($tag) || !preg_match('/[0-9]+/', $tag)) {
  89. return redirect()->route('page404');
  90. }
  91. $post = object_to_array(DB::table('tagindex')->where('id', $tag)->first(), 1);
  92. $data['post'] = $post;
  93. $counts = DB::table("taglist")->where('tid', $tag)->count('aid');
  94. if ($counts > sysconfig('CMS_MAXARC')) {
  95. $counts = sysconfig('CMS_MAXARC');
  96. }
  97. $pagesize = sysconfig('CMS_PAGESIZE');
  98. $page = 0;
  99. if ($counts % $pagesize) {//取总数据量除以每页数的余数
  100. $pages = intval($counts / $pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果
  101. } else {
  102. $pages = $counts / $pagesize;
  103. }
  104. if (!empty($pagenow)) {
  105. if ($pagenow == 1 || $pagenow > $pages) {
  106. return redirect()->route('page404');
  107. }
  108. $page = $pagenow - 1;
  109. $nextpage = $pagenow + 1;
  110. $previouspage = $pagenow - 1;
  111. } else {
  112. $page = 0;
  113. $nextpage = 2;
  114. $previouspage = 0;
  115. }
  116. $data['page'] = $page;
  117. $data['pages'] = $pages;
  118. $data['counts'] = $counts;
  119. $start = $page * $pagesize;
  120. $posts = object_to_array(DB::table("taglist")->where('tid', $tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get());
  121. foreach ($posts as $row) {
  122. $aid[] = $row["aid"];
  123. }
  124. $aid = isset($aid) ? implode(',', $aid) : "";
  125. if ($aid != "") {
  126. if ($post['template'] == 'tag2') {
  127. $data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize", "field" => "title,body")); //获取列表
  128. } else {
  129. $data['posts'] = arclist(array("sql" => "id in ($aid)", "orderby" => ['id', 'desc'], "row" => "$pagesize")); //获取列表
  130. }
  131. } else {
  132. $data['posts'] = ''; //获取列表
  133. }
  134. $data['pagenav'] = get_listnav(array("counts" => $counts, "pagesize" => $pagesize, "pagenow" => $page + 1, "catid" => $tag, "urltype" => "tag")); //获取分页列表
  135. if ($post['template'] == 'tag2' || $post['template'] == 'tag3') {
  136. if (!empty($pagenow)) {
  137. return redirect()->route('page404');
  138. }
  139. }
  140. return view('weixin.index.' . $post['template'], $data);
  141. }
  142. //标签页
  143. public function tags()
  144. {
  145. return view('weixin.index.tags');
  146. }
  147. //搜索页
  148. public function search()
  149. {
  150. //商品热门搜索词列表
  151. $postdata = array(
  152. 'limit' => 10,
  153. 'offset' => 0
  154. );
  155. $url = env('APP_API_URL') . "/goods_searchword_list";
  156. $res = curl_request($url, $postdata, 'GET');
  157. $data['goods_searchword_list'] = $res['data']['list'];
  158. return view('weixin.index.search', $data);
  159. }
  160. //单页面
  161. public function page($id)
  162. {
  163. $data = [];
  164. if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) {
  165. $map['filename'] = $id;
  166. if (cache("pageid$id")) {
  167. $post = cache("pageid$id");
  168. } else {
  169. $post = object_to_array(DB::table('page')->where($map)->first(), 1);
  170. cache("pageid$id", $post, 2592000);
  171. cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000));
  172. }
  173. if ($post) {
  174. $post['body'] = preg_replace('/src=\"\/uploads\/allimg/', "src=\"" . env('APP_URL') . "/uploads/allimg", $post['body']);
  175. $post['pubdate'] = date('Y-m-d', $post['pubdate']);
  176. $data['post'] = $post;
  177. } else {
  178. return redirect()->route('page404');
  179. }
  180. } else {
  181. return redirect()->route('page404');
  182. }
  183. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  184. return view('weixin.index.' . $post['template'], $data);
  185. }
  186. //商品列表页
  187. public function goodslist(Request $request)
  188. {
  189. if ($request->input('typeid', '') != '') {
  190. $data['typeid'] = $request->input('typeid');
  191. }
  192. if ($request->input('tuijian', '') != '') {
  193. $data['tuijian'] = $request->input('tuijian');
  194. }
  195. if ($request->input('keyword', '') != '') {
  196. $data['keyword'] = $request->input('keyword');
  197. }
  198. if ($request->input('status', '') != '') {
  199. $data['status'] = $request->input('status');
  200. }
  201. if ($request->input('is_promote', '') != '') {
  202. $data['is_promote'] = $request->input('is_promote');
  203. }
  204. if ($request->input('orderby', '') != '') {
  205. $data['orderby'] = $request->input('orderby');
  206. }
  207. if ($request->input('max_price', '') != '') {
  208. $data['max_price'] = $request->input('max_price');
  209. } else {
  210. $data['max_price'] = 99999;
  211. }
  212. if ($request->input('min_price', '') != '') {
  213. $data['min_price'] = $request->input('min_price');
  214. } else {
  215. $data['min_price'] = 0;
  216. }
  217. return view('weixin.index.goodslist', $data);
  218. }
  219. //商品详情页
  220. public function goods($id)
  221. {
  222. if (empty($id) || !preg_match('/[0-9]+/', $id)) {
  223. return redirect()->route('page404');
  224. }
  225. $post = object_to_array(DB::table('goods')->where('id', $id)->first(), 1);
  226. if (empty($post)) {
  227. return redirect()->route('page404');
  228. }
  229. $post['name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name');
  230. if ($post) {
  231. $cat = $post['typeid'];
  232. $post['body'] = ReplaceKeyword($post['body']);
  233. if (!empty($post['writer'])) {
  234. $post['writertitle'] = $post['title'] . ' ' . $post['writer'];
  235. }
  236. $data['post'] = $post;
  237. $data['pre'] = get_article_prenext(array('aid' => $post["id"], 'typeid' => $post["typeid"], 'type' => "pre"));
  238. } else {
  239. return redirect()->route('page404');
  240. }
  241. $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);
  242. return view('weixin.index.' . $post['temparticle'], $data);
  243. }
  244. //sitemap页面
  245. public function sitemap()
  246. {
  247. return view('weixin.index.sitemap');
  248. }
  249. //404页面
  250. public function page404()
  251. {
  252. return view('weixin.404');
  253. }
  254. //测试页面
  255. public function test()
  256. {
  257. return view('weixin.index.test');
  258. //return base_path('resources/org');
  259. //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
  260. //return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
  261. //return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';
  262. //set_exception_handler('myException');
  263. //return uniqid();
  264. //return \App\Common\Helper::formatPrice(1.2346);
  265. }
  266. }