From 20357343745ae81bf316a6277077e3a3f94619ea 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: Fri, 23 Jun 2017 18:16:18 +0800 Subject: [PATCH] excel --- app/Http/Controllers/Home/TestController.php | 291 +++++++++++++++++++ config/app.php | 11 +- storage/学生成绩.xls | Bin 0 -> 24064 bytes 3 files changed, 296 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/Home/TestController.php create mode 100644 storage/学生成绩.xls diff --git a/app/Http/Controllers/Home/TestController.php b/app/Http/Controllers/Home/TestController.php new file mode 100644 index 0000000..c95a634 --- /dev/null +++ b/app/Http/Controllers/Home/TestController.php @@ -0,0 +1,291 @@ +sheet('score', function($sheet) use ($cellData){ + $sheet->rows($cellData); + }); + + //第二个工作簿 + $excel->sheet('score', function($sheet) use ($cellData){ + $sheet->rows($cellData); + }); + })->export('xls'); + + //Excel文件导入功能 + $filePath = 'storage/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; + \Excel::load($filePath, function($reader) { + $reader = $reader->getSheet(0); + $res = $reader->toArray(); + dd($res); + }); */ + } + + //列表页 + public function category($cat, $page=0) + { + $pagenow = $page; + + if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} + + if(cache("catid$cat")){$post = cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} + $data['post'] = $post; + + $subcat="";$sql=""; + $post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); + if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} + $subcat=$subcat."typeid=".$cat; + $sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit; + $data['sql'] = $sql; + + $counts = DB::table("article")->whereRaw($sql)->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("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表 + $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表 + + if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} + + return view('home.index.'.$post['templist'], $data); + } + + //文章详情页 + public function detail($id) + { + if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} + + 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));} + if($post) + { + $cat = $post['typeid']; + $post['body'] = ReplaceKeyword($post['body']); + if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} + + $data['post'] = $post; + $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); + } + else + { + return redirect()->route('page404'); + } + + 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));} + + return view('home.index.'.$post['temparticle'], $data); + } + + //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述 + public function tag($tag, $page=0) + { + $pagenow = $page; + + if(empty($tag) || !preg_match('/[0-9]+/',$tag)){return redirect()->route('page404');} + + $post = object_to_array(DB::table('tagindex')->where('id',$tag)->first(), 1); + $data['post'] = $post; + + $counts=DB::table("taglist")->where('tid',$tag)->count('aid'); + if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');} + $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; + + $posts=object_to_array(DB::table("taglist")->where('tid',$tag)->orderBy('aid', 'desc')->skip($start)->take($pagesize)->get()); + foreach($posts as $row) + { + $aid[] = $row["aid"]; + } + $aid = isset($aid)?implode(',',$aid):""; + + if($aid!="") + { + if($post['template']=='tag2') + { + $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize","field"=>"title,body")); //获取列表 + } + else + { + $data['posts'] = arclist(array("sql"=>"id in ($aid)","orderby"=>['id', 'desc'],"row"=>"$pagesize")); //获取列表 + } + } + else + { + $data['posts'] = ''; //获取列表 + } + + $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$tag,"urltype"=>"tag")); //获取分页列表 + + if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}} + + return view('home.index.'.$post['template'], $data); + } + + //标签页 + public function tags() + { + return view('home.index.tags'); + } + + //搜索页 + public function search($keyword) + { + if(empty($keyword)) + { + echo '请输入正确的关键词';exit; + } + + if(strstr($keyword,"&")) exit; + + $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); + $data['keyword']= $keyword; + + return view('home.index.search', $data); + } + + //单页面 + public function page($id) + { + $data = []; + + if(!empty($id) && preg_match('/[a-z0-9]+/',$id)) + { + $map['filename']=$id; + 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));} + + if($post) + { + $data['post'] = $post; + } + else + { + return redirect()->route('page404'); + } + + } + else + { + return redirect()->route('page404'); + } + + $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); + + return view('home.index.'.$post['template'], $data); + } + + //商品列表页 + public function productcat($cat, $page=0) + { + $pagenow = $page; + + if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} + + $post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} + $data['post'] = $post; + + $subcat=""; + $post2 = object_to_array(DB::table('product_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("product")->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"=>"product","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表 + $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"product")); //获取分页列表 + + if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} + + return view('home.index.'.$post['templist'], $data); + } + + //商品详情页 + public function product($id) + { + if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} + + $post = object_to_array(DB::table('product')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('product_type')->where('id', $post['typeid'])->value('name'); + if($post) + { + $cat = $post['typeid']; + $post['body'] = ReplaceKeyword($post['body']); + if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} + + $data['post'] = $post; + $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); + } + else + { + return redirect()->route('page404'); + } + + $post = object_to_array(DB::table('product_type')->where('id', $cat)->first(), 1); + + return view('home.index.'.$post['temparticle'], $data); + } + + //sitemap页面 + public function sitemap() + { + return view('home.index.sitemap'); + } + + //404页面 + public function page404() + { + return view('home.404'); + } + + //测试页面 + public function test() + { + return date("Y-m-d H:i:s",strtotime("2017-04")); + } +} \ No newline at end of file diff --git a/config/app.php b/config/app.php index e0bf9db..4e8afcf 100644 --- a/config/app.php +++ b/config/app.php @@ -136,7 +136,6 @@ return [ */ 'providers' => [ - /* * Laravel Framework Service Providers... */ @@ -163,12 +162,12 @@ return [ Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, Intervention\Image\ImageServiceProvider::class, - + /* * Package Service Providers... */ Laravel\Tinker\TinkerServiceProvider::class, - + /* * Application Service Providers... */ @@ -177,7 +176,8 @@ return [ // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, - + + 'Maatwebsite\Excel\ExcelServiceProvider', //Excel导入导出 ], /* @@ -192,7 +192,6 @@ return [ */ 'aliases' => [ - 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, @@ -227,7 +226,7 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Image' => Intervention\Image\Facades\Image::class, //图片处理 - + 'Excel' => Maatwebsite\Excel\Facades\Excel::class, //Excel导入导出 ], ]; diff --git a/storage/学生成绩.xls b/storage/学生成绩.xls new file mode 100644 index 0000000000000000000000000000000000000000..2cef511acb07768a09bc1fa43f75f436b37ccbe2 GIT binary patch literal 24064 zcmeHP3v^q>nI6fCEt3%2kc5yxqP!E57{@jyl!xP2h_kXKEE&QQDrD)(R*@yGBfVwXcsB;g6}$s}9z5H;2Hpu@3x68?eE0?Mr^7FVuY-pP zhz9sG;Ln6#1iu)53H({`OX1IkUk1M%{v7yo;a9+~gm=NOf?o~427WF4I{5YQ8{jv> zZ-S?N(Qna(-$N>XSBp9z68OuYEqX*8@02(QEzjO9fyHPQw4<2I$)^z0@+o%m)%bXz z>Nmf9(pG<`J?Z$>leWzy(%|5(0{4`-UJOY&u2+et@H|7-3b0116du)V3D;XX)g=G%@f_=5Rx(|vIR~}p6%eT z)qS@7*}s1)xubtO(Tl6+iMv-mUh^zQ^J*ybC&DiN*6}EwLi`kduSjxiXz6TfcKvU; zPANmsMj57|t4k5GiDRJFV@x3xEsy7!^7$>9?-BXDRE|eNJhCpecsp|N8@0#2L+1NS z`CKiZ3-Ppx2W6QbOUgEkOwS>|QygaN0KUf71uKZb3Wi`EQLzn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