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 = [];
@@ -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()]);
}
}
}
} }