From 74f5b9e9332658e134a96b090992db2fc7e40f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Mon, 18 Dec 2017 23:59:00 +0800 Subject: [PATCH] goodslist --- app/Http/Controllers/Home/IndexController.php | 114 ++++++++-------- resources/views/home/index/goods.blade.php | 2 +- resources/views/home/index/goodscat.blade.php | 23 ---- .../views/home/index/goodslist.blade.php | 127 ++++++++++++++++++ 4 files changed, 187 insertions(+), 79 deletions(-) delete mode 100644 resources/views/home/index/goodscat.blade.php create mode 100644 resources/views/home/index/goodslist.blade.php diff --git a/app/Http/Controllers/Home/IndexController.php b/app/Http/Controllers/Home/IndexController.php index 005bf1f..8273bd3 100644 --- a/app/Http/Controllers/Home/IndexController.php +++ b/app/Http/Controllers/Home/IndexController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Home; use App\Http\Controllers\Home\CommonController; use Illuminate\Support\Facades\DB; +use Illuminate\Http\Request; class IndexController extends CommonController { @@ -24,6 +25,64 @@ class IndexController extends CommonController return view('home.index.index',$data); } + //商品列表页 + public function goodslist(Request $request) + { + $cat = $request->input('id', ''); + $page = $request->input('page', ''); + $pagenow = $page; + + if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} + + $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} + $data['post'] = $post; + + $subcat=""; + $post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get()); + if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} + $subcat=$subcat."typeid=".$cat; + $data['sql'] = $subcat; + + $counts = DB::table("goods")->whereRaw($subcat)->count(); + if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} + $pagesize = sysconfig('CMS_PAGESIZE');$page=0; + if($counts % $pagesize){//取总数据量除以每页数的余数 + $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果 + }else{$pages = $counts/$pagesize;} + 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;} + $data['page'] = $page; + $data['pages'] = $pages; + $data['counts'] = $counts; + $start = $page*$pagesize; + + $data['posts'] = arclist(array("table"=>"goods","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表 + $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"goods")); //获取分页列表 + + $data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid'=>0,'status'=>1])->select('id','name')->take(30)->orderBy('listorder','asc')->get()); + $data['id'] = $cat; + + return view('home.index.goodslist', $data); + } + + //商品详情页 + public function goods($id) + { + if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} + + $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'); + if($post) + { + $data['post'] = $post; + } + else + { + return redirect()->route('page404'); + } + + $data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get()); + return view('home.index.goods', $data); + } + //列表页 public function category($cat, $page=0) { @@ -190,61 +249,6 @@ class IndexController extends CommonController return view('home.index.'.$post['template'], $data); } - //商品列表页 - public function goodslist($cat, $page=0) - { - $pagenow = $page; - - if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} - - $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} - $data['post'] = $post; - - $subcat=""; - $post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get()); - if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} - $subcat=$subcat."typeid=".$cat; - $data['sql'] = $subcat; - - $counts = DB::table("goods")->whereRaw($subcat)->count(); - if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} - $pagesize = sysconfig('CMS_PAGESIZE');$page=0; - if($counts % $pagesize){//取总数据量除以每页数的余数 - $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果 - }else{$pages = $counts/$pagesize;} - 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;} - $data['page'] = $page; - $data['pages'] = $pages; - $data['counts'] = $counts; - $start = $page*$pagesize; - - $data['posts'] = arclist(array("table"=>"goods","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表 - $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"goods")); //获取分页列表 - - if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} - - return view('home.index.'.$post['templist'], $data); - } - - //商品详情页 - public function goods($id) - { - if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} - - $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'); - if($post) - { - $data['post'] = $post; - } - else - { - return redirect()->route('page404'); - } - - $data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get()); - return view('home.index.goods', $data); - } - //sitemap页面 public function sitemap() { diff --git a/resources/views/home/index/goods.blade.php b/resources/views/home/index/goods.blade.php index aeca55f..8276a78 100644 --- a/resources/views/home/index/goods.blade.php +++ b/resources/views/home/index/goods.blade.php @@ -99,7 +99,7 @@
库存() 撒个地方官发个话说得好电话公司电话
+