From 521db936c42bb22541fbfd5a91f91823d3e5efc4 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Tue, 20 Nov 2018 21:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BEword=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/chengji/model/Chengji.php | 9 +++ application/teach/controller/Banji.php | 1 + application/teach/controller/Kaoshi.php | 84 ++++++------------------ application/teach/model/Banji.php | 28 +++++++- application/teach/view/kaoshi/index.html | 2 +- route/teach.php | 2 +- 6 files changed, 58 insertions(+), 68 deletions(-) diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php index 098996a5..2e79e236 100644 --- a/application/chengji/model/Chengji.php +++ b/application/chengji/model/Chengji.php @@ -30,4 +30,13 @@ class Chengji extends Base // 返回班级名称 return $bj->title; } + + // 班级名称(数字)获取器 + public function getBanjiNumnameAttr() + { + $bj = Banji::get($this->banji); + + // 返回班级名称 + return $bj->numTitle; + } } diff --git a/application/teach/controller/Banji.php b/application/teach/controller/Banji.php index a14518f0..815cf462 100644 --- a/application/teach/controller/Banji.php +++ b/application/teach/controller/Banji.php @@ -27,6 +27,7 @@ class Banji extends Base } + // 获取班级信息列表 public function ajaxData() { diff --git a/application/teach/controller/Kaoshi.php b/application/teach/controller/Kaoshi.php index 8ad5ea49..72d5087d 100644 --- a/application/teach/controller/Kaoshi.php +++ b/application/teach/controller/Kaoshi.php @@ -15,7 +15,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; // use PhpOffice\PhpSpreadsheet\Writer\Xlsx; // use PhpOffice\PhpSpreadsheet\IOFactory; -use Endroid\QrCode\QrCode; +use \Endroid\QrCode\QrCode; class Kaoshi extends Base { @@ -363,53 +363,15 @@ class Kaoshi extends Base } - - // 生成二维码基础信息 - public function ma($users_id=1) - { - $this->create_qrcode(); - - - $qrCode = new QrCode('Life is too short to be generating QR codes'); - - header('Content-Type: '.$qrCode->getContentType()); - - - // 保存文件 - $filename = '试卷标签.docx'; - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $filename . '"'); - header('Cache-Control: max-age=0'); - $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); - $objWriter->save('php://output'); - - } - - /** * 生成指定网址的二维码 * @param string $url 二维码中所代表的网址 */ - public function create_qrcode($url='') + public function create_qrcode($url='127.0.0.1') { - $url = $url ? $url : input('param.url'); - $qrCode = new QrCode;;//创建生成二维码对象 - $qrCode->setText($url) - ->setSize(150) - ->setPadding(10) - ->setErrorCorrection('high') - ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0)) - ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0)) - ->setImageType(\Endroid\QrCode\QrCode::IMAGE_TYPE_PNG); - - //>>>>>>>直接输出到浏览器>>>>>>>>>> - header("Content-type: image/png"); - $qrCode->render(); //输入到浏览器 - //>>>>>>>直接输出到浏览器>>>>>>>>>> - - //>>>>>>>>>保存文件>>>>>>>>>>> - //$qrCode->save('ziyuanniao.png'); //保存文件 - //>>>>>>>>>保存文件>>>>>>>>>>> + $qrCode = new QrCode($url); + header("Content-type: image/jpg"); + return $qrCode->writeString(); } @@ -419,10 +381,10 @@ class Kaoshi extends Base public function biaoqian() { - $id = 1; + $id = 2; // 获取数据库信息 $chengjiinfo = Chengji::where('kaoshi',$id) - ->append(['studentname','schooljian','banjiname']) + ->append(['studentname','schooljian','banjiNumname']) ->select(); // 获取学科信息 @@ -430,7 +392,7 @@ class Kaoshi extends Base $xks = $xks->Subjectids; $subject = new \app\teach\model\Subject(); - $xks = $subject->where('id','in',$xks)->column('id,leiming,title'); + $xks = $subject->where('id','in',$xks)->column('id,title'); // Word处理 // 实例化类 @@ -442,23 +404,23 @@ class Kaoshi extends Base 'pageSizeW'=>2*567, 'pageSizeH'=>3*567, 'orientation'=>'landscape', - 'marginLeft'=>100, - 'marginRight'=>100, - 'marginTop'=>200, + 'marginLeft'=>80, + 'marginRight'=>80, + 'marginTop'=>100, 'marginBottom'=>100 ); $section = $phpWord->createSection($sectionStyle); // 设置图片格式 - $imageStyle = array('width'=>40,'height'=>40,'align'=>'left'); + $imageStyle = array('width'=>42,'height'=>42,'align'=>'left'); // 学生信息样式 $myStyle = 'myStyle'; $phpWord->addFontStyle( $myStyle, [ - 'name' => 'Verdana', + 'name' => '宋体', 'size' => 6.5, 'color' => '000000', 'bold' => true, @@ -467,17 +429,20 @@ class Kaoshi extends Base // 循环写出信息 foreach ($chengjiinfo as $key => $value) { - foreach ($xks as $key => $val) { + foreach ($xks as $xkkey => $val) { // 创建表格 $table = $section->addTable($key); $table->addRow(1500); - $table->addCell(700)->addImage('aaaa.jpg',$imageStyle); + + $img = $this->create_qrcode($value['id'].','.$xkkey); + $table->addCell(850)->addImage($img,$imageStyle); + // $table->addCell(700)->addImage('aaaa.jpg',$imageStyle); - $info = $table->addCell(700); + $info = $table->addCell(650); $info->addText($value['schooljian'],$myStyle); - $info->addText($value['banjiname'],$myStyle); + $info->addText($value['banjiNumname'],$myStyle); $info->addText($value['studentname'],$myStyle); - $info->addText($val['title'],$myStyle); + $info->addText($val,$myStyle); } } @@ -532,11 +497,4 @@ class Kaoshi extends Base } - // 生成表格录入成绩表 - public function biaolu() - { - return $this->fetch(); - } - - } diff --git a/application/teach/model/Banji.php b/application/teach/model/Banji.php index 01bc7491..f009118f 100644 --- a/application/teach/model/Banji.php +++ b/application/teach/model/Banji.php @@ -8,22 +8,44 @@ use app\common\model\Base; class Banji extends Base { // 班级名获取器 - public function getTitleAttr() + public function getNumTitleAttr() { $njname = nianjilist(); - $bjname = banjinamelist(); + // $bjname = banjinamelist(); $nj = $this->getAttr('ruxuenian'); $bj = $this->getAttr('paixu'); + $numnj = array_flip(array_keys($njname)); + + $numname = ($numnj[$nj] + 1).'.'.$bj; + + return $numname; + } + + + + // 班级名获取器 + public function getTitleAttr() + { + $njname = nianjilist(); + $bjname = banjinamelist(); + $nj = $this->getAttr('ruxuenian'); + $bj = $this->getAttr('paixu'); + $njkeys = array_keys($njname); $bjkeys = array_keys($bjname); in_array($nj,$njkeys) ? $title = $njname[$nj] : $title = $nj.'届'; in_array($bj,$bjkeys) ? $title = $title.$bjname[$bj] : $title = $title.$bj.'班'; - return $title; + return $title; } + + + + + // 学校获取器 public function getSchoolAttr($value) { diff --git a/application/teach/view/kaoshi/index.html b/application/teach/view/kaoshi/index.html index c3b635e5..ff490f76 100644 --- a/application/teach/view/kaoshi/index.html +++ b/application/teach/view/kaoshi/index.html @@ -101,7 +101,7 @@ // 删除按钮 delbut = ''; // 生成码录表按钮 - malubut = ''; + malubut = ''; // 生成表格录入表 biaolubut = ''; diff --git a/route/teach.php b/route/teach.php index 7b27905a..315a9f1b 100644 --- a/route/teach.php +++ b/route/teach.php @@ -19,7 +19,7 @@ Route::post('banji/mybanji','teach/Banji/mybanji'); // 定义GET请求路由规 Route::post('banji/banjilist','teach/Banji/banjilist'); // 定义GET请求路由规则 Route::get('kaoshi/:id/kaohao','teach/Kaoshi/kaohao'); Route::post('kaoshi/kaohao','teach/Kaoshi/kaohaosave'); -Route::get('kaoshi/:id/malu','teach/Kaoshi/malubiao'); +Route::get('kaoshi/:id/biaoqian','teach/Kaoshi/biaoqian'); Route::get('kaoshi/:id/biaolu','teach/Kaoshi/biaolubiao');