This commit is contained in:
wangjinlei
2022-11-29 09:03:25 +08:00
parent 9f27e8e054
commit 3bfc55519b
2 changed files with 98 additions and 35 deletions

View File

@@ -602,6 +602,8 @@ class Article extends Controller {
if(!$rule->check($data)){ if(!$rule->check($data)){
return jsonError($rule->getError()); return jsonError($rule->getError());
} }
$this->article_obj->where('article_id',$data['article_id'])->update(['sort'=>$data['sort']]);
return jsonSuccess([]);
} }
/** /**

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace app\master\controller; namespace app\master\controller;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
@@ -19,9 +20,53 @@ class Mytest extends Controller
parent::__construct($request); parent::__construct($request);
} }
public function ttt()
public function getAllfile()
{ {
$file = ROOT_PATH . 'public' . DS . "zch" . DS . 'text.xlsx'; $path = ROOT_PATH . 'public' . DS . 'welfare' . DS;
if (!is_dir($path)) {
return false;
}
$arr = array();
$data = scandir($path);
foreach ($data as $value) {
if ($value != '.' && $value != '..') {
$arr[] = $value;
}
}
$re['dirs'] = $arr;
return jsonSuccess($re);
}
// public function getexFile()
// {
// $data = $this->request->post();
// $path = ROOT_PATH . 'public' . DS . 'welfare' . DS.$data['dir'];
// if (!is_dir($path)) {
// return false;
// }
// $arr = array();
// $data = scandir($path);
// foreach ($data as $value) {
// if ($value != '.' && $value != '..') {
// $arr[] = $value;
// }
// }
// $re['files'] = $arr;
// return jsonSuccess($re);
// }
public function getLastFile()
{
$data = $this->request->post();
$file = ROOT_PATH . 'public' . DS . "welfare" . DS . $data['filename'];
$savefile = ROOT_PATH . 'public' . DS . "zch" . DS . substr($data['filename'],0,strrpos($data['filename'],'.')).'.docx';
$medir = "zch" . DS . substr($data['filename'],0,strrpos($data['filename'],'.')).'.docx';
if(is_file($savefile)){
$re['file'] = $medir;
return jsonSuccess($re);
}
$res = $this->readExcel($file); $res = $this->readExcel($file);
$frag = []; $frag = [];
$fraz = []; $fraz = [];
@@ -103,7 +148,7 @@ class Mytest extends Controller
$PHPWord = new PhpWord(); $PHPWord = new PhpWord();
$section=$PHPWord->addSection(); $section = $PHPWord->addSection();
// $section = $PHPWord->createSection(); // $section = $PHPWord->createSection();
@@ -134,9 +179,9 @@ class Mytest extends Controller
); );
// $cellStyle = array('gridSpan' => 2); // $cellStyle = array('gridSpan' => 2);
$cellStyle1 = array('gridSpan' => 3,"bgColor"=>"FF0000",'align'=>'center'); $cellStyle1 = array('gridSpan' => 3, "bgColor" => "FF0000", 'align' => 'center');
$cellStyle2 = array('gridSpan' => 3,"bgColor"=>"EEEE11",'align'=>'center'); $cellStyle2 = array('gridSpan' => 3, "bgColor" => "EEEE11", 'align' => 'center');
$cellStyle3 = array('gridSpan' => 3,"bgColor"=>"0099FF",'align'=>'center'); $cellStyle3 = array('gridSpan' => 3, "bgColor" => "0099FF", 'align' => 'center');
//添加表格样式 //添加表格样式
@@ -147,14 +192,14 @@ class Mytest extends Controller
$table = $section->addTable('myOwnTableStyle'); $table = $section->addTable('myOwnTableStyle');
$table->addRow(); $table->addRow();
$table->addCell(9000,$cellStyle1)->addText('高风险等级地区'); $table->addCell(9000, $cellStyle1)->addText('高风险等级地区');
$gn = ""; $gn = "";
foreach($fg as $v){ foreach ($fg as $v) {
$table->addRow(); $table->addRow();
if($v['p']==$gn){ if ($v['p'] == $gn) {
$table->addCell(2000,array('vMerge' => 'continue')); $table->addCell(2000, array('vMerge' => 'continue'));
}else{ } else {
$table->addCell(2000, array('vMerge' => 'restart','valign'=>'center'))->addText($v['p']); $table->addCell(2000, array('vMerge' => 'restart', 'valign' => 'center'))->addText($v['p']);
} }
$table->addCell(2000)->addText($v["city"]); $table->addCell(2000)->addText($v["city"]);
$table->addCell(5000)->addText($v['area']); $table->addCell(5000)->addText($v['area']);
@@ -163,14 +208,14 @@ class Mytest extends Controller
$table = $section->addTable('myOwnTableStyle'); $table = $section->addTable('myOwnTableStyle');
$table->addRow(); $table->addRow();
$table->addCell(9000,$cellStyle2)->addText('中风险等级地区'); $table->addCell(9000, $cellStyle2)->addText('中风险等级地区');
$zn = ""; $zn = "";
foreach($fz as $v){ foreach ($fz as $v) {
$table->addRow(); $table->addRow();
if($v['p']==$zn){ if ($v['p'] == $zn) {
$table->addCell(2000,array('vMerge' => 'continue')); $table->addCell(2000, array('vMerge' => 'continue'));
}else{ } else {
$table->addCell(2000, array('vMerge' => 'restart','valign'=>'center'))->addText($v['p']); $table->addCell(2000, array('vMerge' => 'restart', 'valign' => 'center'))->addText($v['p']);
} }
$table->addCell(2000)->addText($v["city"]); $table->addCell(2000)->addText($v["city"]);
$table->addCell(5000)->addText($v['area']); $table->addCell(5000)->addText($v['area']);
@@ -180,21 +225,21 @@ class Mytest extends Controller
$table1 = $section->addTable('myOwnTableStyle'); $table1 = $section->addTable('myOwnTableStyle');
$table1->addRow(); $table1->addRow();
$table1->addCell(9000,$cellStyle3)->addText('低风险等级地区'); $table1->addCell(9000, $cellStyle3)->addText('低风险等级地区');
$dn = ""; $dn = "";
foreach($fd as $v){ foreach ($fd as $v) {
$table1->addRow(); $table1->addRow();
if($v['p']==$dn){ if ($v['p'] == $dn) {
$table1->addCell(2000,array('vMerge' => 'continue')); $table1->addCell(2000, array('vMerge' => 'continue'));
}else{ } else {
$table1->addCell(2000, array('vMerge' => 'restart','valign'=>'center'))->addText($v['p']); $table1->addCell(2000, array('vMerge' => 'restart', 'valign' => 'center'))->addText($v['p']);
} }
$table1->addCell(2000)->addText($v["city"]); $table1->addCell(2000)->addText($v["city"]);
$table1->addCell(5000)->addText($v['area']); $table1->addCell(5000)->addText($v['area']);
$dn = $v['p']; $dn = $v['p'];
} }
// $table1 = $section->addTable('myOwnTableStyle'); // $table1 = $section->addTable('myOwnTableStyle');
// $table1->addRow(); // $table1->addRow();
// $table1->addCell(9000,$cellStyle2)->addText('中风险等级地区'); // $table1->addCell(9000,$cellStyle2)->addText('中风险等级地区');
@@ -271,27 +316,29 @@ class Mytest extends Controller
//文档存在服务器上用此代码 //文档存在服务器上用此代码
// $objWriter = IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter = IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save($savefile);
// $objWriter->save('d:\编程爱好者.docx'); $re['file'] = $medir;
return jsonSuccess($re);
//直接下载不存储在服务器上用此代码 //直接下载不存储在服务器上用此代码
header("Content-Description: File Transfer"); // header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"'); // header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); // header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary'); // header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); // header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0'); // header('Expires: 0');
$xmlWriter = IOFactory::createWriter($PHPWord, 'Word2007'); // $xmlWriter = IOFactory::createWriter($PHPWord, 'Word2007');
$xmlWriter->save("php://output"); // $xmlWriter->save("php://output");
} }
/** /**
@@ -326,4 +373,18 @@ class Mytest extends Controller
} }
return $frag; return $frag;
} }
public function up_excel_file()
{
$file = request()->file('welfare');
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'welfare', '');
if ($info) {
return json(['code' => 0, 'msg' => 'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
} }