diff --git a/app/common.php b/app/common.php index bd9d7fc6..3afad931 100644 --- a/app/common.php +++ b/app/common.php @@ -185,7 +185,8 @@ function schlist($low='班级',$high='其它级',$xueduan=array()) ->where('status',1) ->where('xueduan','in',$xdlist) ->order(['paixu']) - ->column('id,title,jiancheng'); + ->field('id,title,jiancheng') + ->select(); return $schlist; } @@ -220,123 +221,52 @@ function teacherNames($list = array()) * 获取文件信息并保存 * * @param file对象 $file - * @param array() + * @param array() $list 文件信息 * str $list['text'] 文件分类标识 * str $list['serurl'] 文件存储位置 - * str $list['oldname'] 文件存储位置 - * @return \think\Response + * file $file 文件对象 + * @return array $data + * str $data['msg'] 返回信息提示 + * str $data['val'] 返回信息 + * str $data['url'] 文件路径 */ - function saveFileInfo($file,$list) + function saveFileInfo($file,$list,$isSave=false) { - - - // 上传文件到本地服务器 $savename = \think\facade\Filesystem::putFile($list['serurl'], $file); // 重新组合文件路径 $savename = str_replace("/","\\",$savename); + $url = $savename; $savename = str_replace($list['serurl'].'\\', "", $savename); - $a = config('filesystem.disks.public.root'); - $b = app()->getRootPath(); - dump($a); - - dump($file); - - // 获取文件信息 - // $list['category'] = $file->fileExt(); $list['url'] = $savename; - $list['newname'] = $file->getFilename(); + $list['newname'] = substr($savename,9,strlen($savename)-9); $list['hash'] = $file->hash('sha1'); $list['userid'] = session('userid'); - $list['oldname'] = $list['oldname']; + $list['oldname'] = $file->getOriginalName(); $list['fieldsize'] = $file->getSize(); $list['text'] = $list['text']; $list['bianjitime'] = $file->getMTime(); - halt($list); + $list['category'] = $file->getOriginalExtension(); - return $list; - } + $f = new \app\system\model\Fields; + $saveinfo = $f::create($list); - - -/** -* 上传文件,并返回文件存储地址 -* -* @access public -* @param array $list 文件信息 -* @param mixed $list['serurl'] 文件要存到哪儿 -* @param mixed $list[''] 文件要存到哪儿 -* @param mixed $file 文件 -* @param array $isSave 是否将文件信息保存到数据库 -* @return array 返回类型 数组 -* @return msg string 提示 -* @return val string 结果 -* @return url string 如果保存到数据库,返回完整路径,否则保存部分路径。 -*/ -function upload($list,$file,$isSave=false) -{ - // 声明默认目录 - $myrul = '..\public\uploads\\'; - - // 实例化文件数据模型 - $field = new \app\system\model\Fields; - - - // 移动到框架应用根目录/uploads/ 目录下 - $info = $file->move($myrul.$list['serurl']); - - - // 如果上传成功 - if(!$info){ - // 上传失败获取错误信息 - $data = array('msg'=>$file->getError(),'val'=>false,'url'=>null); - return $data; - } - - - // 成功上传后 获取上传信息 - $list['category'] = $info->getExtension(); - $list['url'] = $list['serurl'].$info->getSaveName(); - $list['newname'] = $info->getFilename(); - $list['hash'] = $info->hash('sha1'); - $list['userid'] = session('userid'); - $list['oldname'] = $info->getInfo('name'); - $list['fieldsize'] = $info->getInfo('size'); - // $list['bianjitime'] = Null; - - - // 如果需要保存文件 - if($isSave == true){ - - //将文件信息保存 - $data = $field->create($list); - - if($data){ - $data = array( - 'msg'=>'上传成功' - ,'val'=>true - ,'url'=>$myrul.$list['serurl'].$info->getSaveName() - ); + if($saveinfo) + { + $data['msg'] = '上传成功'; + $data['val'] = true; + $data['url'] = $url; }else{ - $data = array( - 'msg'=>'保存文件信息失败' - ,'val'=>false - ); + $data['msg'] = '上传失败'; + $data['val'] = false; + $data['url'] = ''; } - }else{ - $data = array( - 'msg'=>'上传成功' - ,'val'=>true - ,'url'=>$info->getSaveName() - ); - } - + return $data; + } + - // 返回信息 - return $data; -} diff --git a/app/renshi/controller/Teacher.php b/app/renshi/controller/Teacher.php index 12397236..2245e1c9 100644 --- a/app/renshi/controller/Teacher.php +++ b/app/renshi/controller/Teacher.php @@ -298,18 +298,18 @@ class Teacher extends BaseController return $this->view->fetch(); } + // 批量保存 public function saveAll() { // 获取表单数据 $list = request()->only(['school','url'],'post'); - // 实例化操作表格类 $excel = new \app\renshi\controller\Myexcel;; // 读取表格数据 - $teacherinfo = $excel->readXls($list['url']); + $teacherinfo = $excel->readXls(public_path().'public\\uploads\\'.$list['url']); // 判断表格是否正确 if($teacherinfo[0][1] != "教师基本情况表" ) @@ -318,6 +318,7 @@ class Teacher extends BaseController return json($data); } + // 删除标题行 array_splice($teacherinfo,0,4 ); @@ -364,6 +365,10 @@ class Teacher extends BaseController return json($data); } + + + + // 根据教师姓名、首拼、全拼搜索教师信息 public function srcTeacher($str="") { @@ -390,6 +395,7 @@ class Teacher extends BaseController return json($list); } + // 上传文件 public function upload() { @@ -401,14 +407,7 @@ class Teacher extends BaseController $file = request()->file('file'); $savename = \think\facade\Filesystem::putFile($list['serurl'], $file); - $list['oldname'] = $_FILES['file']['name']; - $data = saveFileInfo($file,$list); - halt($data); - - - // 上传文件并返回结果 - $data = upload($list,$file,true); return json($data); } diff --git a/composer.json b/composer.json index a6a83609..471029af 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "whitehat101/apr1-md5": "^1.0", "liliuwei/thinkphp-jump": "^1.3", "liliuwei/thinkphp-auth": "2.0.*", - "topthink/think-migration": "^3.0" + "topthink/think-migration": "^3.0", + "phpoffice/phpspreadsheet": "^1.10" }, "require-dev": { "symfony/var-dumper": "^4.2", diff --git a/composer.lock b/composer.lock index 18e9a440..62fcf4d5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c8a13cfd4be3db080c7c740fb762575", + "content-hash": "c264fd758746a299f4eca9fdb46423e0", "packages": [ { "name": "league/flysystem", - "version": "1.0.57", + "version": "1.0.61", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "0e9db7f0b96b9f12dcf6f65bc34b72b1a30ea55a" + "reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/0e9db7f0b96b9f12dcf6f65bc34b72b1a30ea55a", - "reference": "0e9db7f0b96b9f12dcf6f65bc34b72b1a30ea55a", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/4fb13c01784a6c9f165a351e996871488ca2d8c9", + "reference": "4fb13c01784a6c9f165a351e996871488ca2d8c9", "shasum": "", "mirrors": [ { @@ -94,7 +94,7 @@ "sftp", "storage" ], - "time": "2019-10-16T21:01:05+00:00" + "time": "2019-12-08T21:46:50+00:00" }, { "name": "league/flysystem-cached-adapter", @@ -170,7 +170,7 @@ ] }, "require": { - "php": "^7.1", + "php": ">=7.1.0", "topthink/framework": "^6.0" }, "type": "think-extend", @@ -196,14 +196,12 @@ "email": "974829947@qq.com" } ], - "description": "适用于thinkphp5.1和6.0的Auth权限扩展", + "description": "适用于thinkphp6.0的Auth权限扩展", "keywords": [ "think-auth", - "thinkphp", - "thinkphp5.1", - "thinkphp6.0" + "thinkphp" ], - "time": "2019-12-04T04:49:15+00:00" + "time": "2019-12-04T14:17:14+00:00" }, { "name": "liliuwei/thinkphp-jump", @@ -264,6 +262,182 @@ ], "time": "2019-12-04T06:29:00+00:00" }, + { + "name": "markbaker/complex", + "version": "1.4.7", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPComplex.git", + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/1ea674a8308baf547cbcbd30c5fcd6d301b7c000", + "reference": "1ea674a8308baf547cbcbd30c5fcd6d301b7c000", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.6.0|^7.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3", + "phpcompatibility/php-compatibility": "^8.0", + "phpdocumentor/phpdocumentor": "2.*", + "phploc/phploc": "2.*", + "phpmd/phpmd": "2.*", + "phpunit/phpunit": "^4.8.35|^5.4.0", + "sebastian/phpcpd": "2.*", + "squizlabs/php_codesniffer": "^3.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Complex\\": "classes/src/" + }, + "files": [ + "classes/src/functions/abs.php", + "classes/src/functions/acos.php", + "classes/src/functions/acosh.php", + "classes/src/functions/acot.php", + "classes/src/functions/acoth.php", + "classes/src/functions/acsc.php", + "classes/src/functions/acsch.php", + "classes/src/functions/argument.php", + "classes/src/functions/asec.php", + "classes/src/functions/asech.php", + "classes/src/functions/asin.php", + "classes/src/functions/asinh.php", + "classes/src/functions/atan.php", + "classes/src/functions/atanh.php", + "classes/src/functions/conjugate.php", + "classes/src/functions/cos.php", + "classes/src/functions/cosh.php", + "classes/src/functions/cot.php", + "classes/src/functions/coth.php", + "classes/src/functions/csc.php", + "classes/src/functions/csch.php", + "classes/src/functions/exp.php", + "classes/src/functions/inverse.php", + "classes/src/functions/ln.php", + "classes/src/functions/log2.php", + "classes/src/functions/log10.php", + "classes/src/functions/negative.php", + "classes/src/functions/pow.php", + "classes/src/functions/rho.php", + "classes/src/functions/sec.php", + "classes/src/functions/sech.php", + "classes/src/functions/sin.php", + "classes/src/functions/sinh.php", + "classes/src/functions/sqrt.php", + "classes/src/functions/tan.php", + "classes/src/functions/tanh.php", + "classes/src/functions/theta.php", + "classes/src/operations/add.php", + "classes/src/operations/subtract.php", + "classes/src/operations/multiply.php", + "classes/src/operations/divideby.php", + "classes/src/operations/divideinto.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with complex numbers", + "homepage": "https://github.com/MarkBaker/PHPComplex", + "keywords": [ + "complex", + "mathematics" + ], + "time": "2018-10-13T23:28:42+00:00" + }, + { + "name": "markbaker/matrix", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPMatrix.git", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "reference": "5348c5a67e3b75cd209d70103f916a93b1f1ed21", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.6.0|^7.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-master", + "phpcompatibility/php-compatibility": "dev-master", + "phploc/phploc": "^4", + "phpmd/phpmd": "dev-master", + "phpunit/phpunit": "^5.7", + "sebastian/phpcpd": "^3.0", + "squizlabs/php_codesniffer": "^3.0@dev" + }, + "type": "library", + "autoload": { + "psr-4": { + "Matrix\\": "classes/src/" + }, + "files": [ + "classes/src/functions/adjoint.php", + "classes/src/functions/antidiagonal.php", + "classes/src/functions/cofactors.php", + "classes/src/functions/determinant.php", + "classes/src/functions/diagonal.php", + "classes/src/functions/identity.php", + "classes/src/functions/inverse.php", + "classes/src/functions/minors.php", + "classes/src/functions/trace.php", + "classes/src/functions/transpose.php", + "classes/src/operations/add.php", + "classes/src/operations/directsum.php", + "classes/src/operations/subtract.php", + "classes/src/operations/multiply.php", + "classes/src/operations/divideby.php", + "classes/src/operations/divideinto.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with matrices", + "homepage": "https://github.com/MarkBaker/PHPMatrix", + "keywords": [ + "mathematics", + "matrix", + "vector" + ], + "time": "2019-10-06T11:29:25+00:00" + }, { "name": "opis/closure", "version": "3.5.1", @@ -331,6 +505,105 @@ ], "time": "2019-11-29T22:36:02+00:00" }, + { + "name": "phpoffice/phpspreadsheet", + "version": "1.10.1", + "source": { + "type": "git", + "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", + "reference": "1648dc9ebef6ebe0c5a172e16cf66732918416e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/1648dc9ebef6ebe0c5a172e16cf66732918416e0", + "reference": "1648dc9ebef6ebe0c5a172e16cf66732918416e0", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-ctype": "*", + "ext-dom": "*", + "ext-fileinfo": "*", + "ext-gd": "*", + "ext-iconv": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "ext-xml": "*", + "ext-xmlreader": "*", + "ext-xmlwriter": "*", + "ext-zip": "*", + "ext-zlib": "*", + "markbaker/complex": "^1.4", + "markbaker/matrix": "^1.2", + "php": "^7.1", + "psr/simple-cache": "^1.0" + }, + "require-dev": { + "dompdf/dompdf": "^0.8.3", + "friendsofphp/php-cs-fixer": "^2.16", + "jpgraph/jpgraph": "^4.0", + "mpdf/mpdf": "^8.0", + "phpcompatibility/php-compatibility": "^9.3", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.5", + "tecnickcom/tcpdf": "^6.3" + }, + "suggest": { + "dompdf/dompdf": "Option for rendering PDF with PDF Writer", + "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers", + "mpdf/mpdf": "Option for rendering PDF with PDF Writer", + "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maarten Balliauw", + "homepage": "https://blog.maartenballiauw.be" + }, + { + "name": "Mark Baker", + "homepage": "https://markbakeruk.net" + }, + { + "name": "Franck Lefevre", + "homepage": "https://rootslabs.net" + }, + { + "name": "Erik Tilt" + }, + { + "name": "Adrien Crivelli" + } + ], + "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", + "homepage": "https://github.com/PHPOffice/PhpSpreadsheet", + "keywords": [ + "OpenXML", + "excel", + "gnumeric", + "ods", + "php", + "spreadsheet", + "xls", + "xlsx" + ], + "time": "2019-12-01T23:13:51+00:00" + }, { "name": "psr/cache", "version": "1.0.1",