diff --git a/app/common.php b/app/common.php index 8429880a..0484e10f 100644 --- a/app/common.php +++ b/app/common.php @@ -92,26 +92,26 @@ } - // // 整理教师名 - // function teacherNames($list = array()) - // { - // if(count($list) == 0 ) - // { - // return ''; - // } + // 整理教师名 + function teacherNames($list = array()) + { + if(count($list) == 0 ) + { + return ''; + } - // $names = ''; - // foreach ($list as $key => $value) { - // if($key == 0) - // { - // $names = $value['teacher']['xingming']; - // }else{ - // $names = $names . '、'. $value['teacher']['xingming']; - // } - // } + $names = ''; + foreach ($list as $key => $value) { + if($key == 0) + { + $names = $value['teacher']['xingming']; + }else{ + $names = $names . '、'. $value['teacher']['xingming']; + } + } - // return $names; - // } + return $names; + } // 给数组按多条件排序 @@ -123,12 +123,12 @@ } - /** + /* * 根据键值,用数组2的值替换数组1的值 * $cover 覆盖数组,存储新值的数组 * $covered 被覆盖数组,被更改值的数组 * 返回 新arr1 - * */ + */ function array_cover($cover = array(), $covered = array()) { $tools = new \app\tools\controller\Index; diff --git a/app/keti/controller/KetiInfo.php b/app/keti/controller/KetiInfo.php index c110b268..c6f0a202 100644 --- a/app/keti/controller/KetiInfo.php +++ b/app/keti/controller/KetiInfo.php @@ -10,6 +10,9 @@ use app\keti\model\KetiInfo as ktinfo; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +// 引用上传文件 +use app\tools\controller\File; + class KetiInfo extends BaseController { @@ -192,14 +195,17 @@ class KetiInfo extends BaseController // 批量保存图片 public function saveAll($ketice_id) { - // 获取文件信息 - $list['text'] = $this->request->post('text'); - $list['serurl'] = $this->request->post('serurl'); + // 获取表单数据 + $list = request()->only([ + 'text' + ,'serurl' + ], 'post'); // 获取表单上传文件 $file = request()->file('file'); // 上传文件并返回结果 - $data = saveFileInfo($file, $list, false); + $fileObj = new File(); + $data = $fileObj->saveFileInfo($file, $list, false); if($data['val'] != 1) { @@ -427,7 +433,7 @@ class KetiInfo extends BaseController }else{ $data = true; } - + // 根据更新结果设置返回提示信息 $data ? $data = ['msg' => '更新成功', 'val' => 1] diff --git a/app/rongyu/controller/Danwei.php b/app/rongyu/controller/Danwei.php index 18ddef78..f77fcf30 100644 --- a/app/rongyu/controller/Danwei.php +++ b/app/rongyu/controller/Danwei.php @@ -6,6 +6,9 @@ namespace app\rongyu\controller; use app\BaseController; // 引用教师数据模型类 use app\rongyu\model\DwRongyu as DW; +// 引用上传文件 +use app\tools\controller\File; + class Danwei extends BaseController { @@ -155,14 +158,17 @@ class Danwei extends BaseController // 保存批传 public function saveAll() { - // 获取文件信息 - $list['text'] = $this->request->post('text'); - $list['serurl'] = $this->request->post('serurl'); + // 获取表单数据 + $list = request()->only([ + 'text' + ,'serurl' + ], 'post'); // 获取表单上传文件 $file = request()->file('file'); // 上传文件并返回结果 - $data = saveFileInfo($file, $list, false); + $fileObj = new File(); + $data = $fileObj->saveFileInfo($file, $list, false); if($data['val'] != true) { @@ -173,6 +179,7 @@ class Danwei extends BaseController $createInfo = [ 'url' => $data['url'] ,'title' => '批传单位荣誉图片' + ,'project' => '无' ]; // 实例化验证类 @@ -200,15 +207,17 @@ class Danwei extends BaseController */ public function upload() { - - // 获取文件信息 - $list['text'] = $this->request->post('text'); - $list['serurl'] = $this->request->post('serurl'); + // 获取表单数据 + $list = request()->only([ + 'text' + ,'serurl' + ], 'post'); // 获取表单上传文件 $file = request()->file('file'); // 上传文件并返回结果 - $data = saveFileInfo($file, $list, false); + $fileObj = new File(); + $data = $fileObj->saveFileInfo($file, $list, false); return json($data); } diff --git a/app/rongyu/controller/JsRongyuInfo.php b/app/rongyu/controller/JsRongyuInfo.php index 0143f369..29a42744 100644 --- a/app/rongyu/controller/JsRongyuInfo.php +++ b/app/rongyu/controller/JsRongyuInfo.php @@ -11,6 +11,10 @@ use app\rongyu\model\JsRongyuInfo as ryinfo; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +// 引用上传文件 +use app\tools\controller\File; + + class JsRongyuInfo extends BaseController { /** @@ -214,14 +218,17 @@ class JsRongyuInfo extends BaseController // 保存批传 public function saveall($rongyuce_id) { - // 获取文件信息 - $list['text'] = $this->request->post('text'); - $list['serurl'] = $this->request->post('serurl'); + // 获取表单数据 + $list = request()->only([ + 'text' + ,'serurl' + ], 'post'); // 获取表单上传文件 $file = request()->file('file'); // 上传文件并返回结果 - $data = saveFileInfo($file, $list, false); + $fileObj = new File(); + $data = $fileObj->saveFileInfo($file, $list, false); if($data['val'] != 1) { diff --git a/app/rongyu/model/JsRongyuInfo.php b/app/rongyu/model/JsRongyuInfo.php index 259e1867..7ba74461 100644 --- a/app/rongyu/model/JsRongyuInfo.php +++ b/app/rongyu/model/JsRongyuInfo.php @@ -290,24 +290,4 @@ class JsRongyuInfo extends BaseModel } return $value; } - - // // 获奖教师名整理 - // public function getHjJsNameAttr($value) - // { - // $teacherList = $this->getAttr('hjJsry'); - // $teachNames = teacherNames($teacherList); - - // return $teachNames; - - // } - - // // 获奖教师名整理 - // public function getCyJsNameAttr($value) - // { - // $teacherList = $this->getAttr('cyJsry'); - // $teachNames = teacherNames($teacherList); - - // return $teachNames; - - // } } diff --git a/app/rongyu/validate/Upload.php b/app/rongyu/validate/Upload.php new file mode 100644 index 00000000..eb5f8931 --- /dev/null +++ b/app/rongyu/validate/Upload.php @@ -0,0 +1,37 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'text' => 'require', + 'serurl' => 'require', + 'isSave' => 'require|boolean' + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = [ + + ]; + + // 验证场景 + protected $scene = [ + 'save' => ['text', 'serurl', 'isSave'], + 'nosave' => ['text', 'serurl'] + ]; +} diff --git a/app/rongyu/view/danwei/create_all.html b/app/rongyu/view/danwei/create_all.html index 2dbd70c8..ec930ec0 100644 --- a/app/rongyu/view/danwei/create_all.html +++ b/app/rongyu/view/danwei/create_all.html @@ -1,10 +1,13 @@ {extend name=".././view/create.html" /} {block name="form"} -
- +
+
+ +

点击上传,或将文件拖拽到此处

+
+
+
{/block} @@ -13,7 +16,7 @@ layui.use('upload', function(){ var upload = layui.upload; - + //执行实例 var uploadInst = upload.render({ elem: '#upload' //绑定元素 diff --git a/app/student/controller/Index.php b/app/student/controller/Index.php index 2cf441ff..defb38c1 100644 --- a/app/student/controller/Index.php +++ b/app/student/controller/Index.php @@ -453,7 +453,7 @@ class Index extends BaseController $stuinfo = $excel->readXls(public_path() . 'uploads\\' . $list['url']); if($stuinfo[0][2] != "序号" && $stuinfo[1][2] != "姓名" && $stuinfo[2][2] != "身份证号") { - $this->error('请使用模板上传', '/login/err'); #如果表格数据与模板不相符,则跳转。 + $data = array('msg'=>'请使用模板上传','val'=>0,'url'=>''); return json($data); } diff --git a/app/student/view/index/create_all.html b/app/student/view/index/create_all.html index 854b3500..24a19677 100644 --- a/app/student/view/index/create_all.html +++ b/app/student/view/index/create_all.html @@ -1,19 +1,21 @@ -{extend name=".././view/createhref.html" /} +{extend name=".././view/create.html" /} {block name="form"} -
- -
-
diff --git a/app/student/view/index/deletes.html b/app/student/view/index/deletes.html index 1dbde009..d2037ff0 100644 --- a/app/student/view/index/deletes.html +++ b/app/student/view/index/deletes.html @@ -1,19 +1,21 @@ {extend name=".././view/create.html" /} {block name="form"} -
- -
-
diff --git a/app/teacher/controller/Index.php b/app/teacher/controller/Index.php index bd40be1a..93242cbf 100644 --- a/app/teacher/controller/Index.php +++ b/app/teacher/controller/Index.php @@ -7,6 +7,9 @@ use app\BaseController; // 引用教师数据模型类 use app\teacher\model\Teacher as TC; +// 引用上传文件 +use app\tools\controller\File; + class Index extends BaseController { @@ -426,13 +429,17 @@ class Index extends BaseController // 上传文件 public function upload() { - // 获取文件信息 - $list['category_id'] = $this->request->post('category_id'); - $list['serurl'] = $this->request->post('serurl'); + // 获取表单数据 + $list = request()->only([ + 'serurl' + ,'category_id' + ], 'post'); // 获取表单上传文件 $file = request()->file('file'); - $data = saveFileInfo($file, $list, true); + // 上传文件并返回结果 + $fileObj = new File(); + $data = $fileObj->saveFileInfo($file, $list, true); return json($data); } diff --git a/app/teacher/view/index/create_all.html b/app/teacher/view/index/create_all.html index 2b446ce7..5dd8ec03 100644 --- a/app/teacher/view/index/create_all.html +++ b/app/teacher/view/index/create_all.html @@ -1,19 +1,21 @@ {extend name=".././view/create.html" /} {block name="form"} -
- -
-
diff --git a/app/teacher/view/index/index.html b/app/teacher/view/index/index.html index 3d218fc3..bad8233f 100644 --- a/app/teacher/view/index/index.html +++ b/app/teacher/view/index/index.html @@ -145,7 +145,7 @@ cjgl.add('添加教师','/teacher/index/create','','',true); break; case 'upload': - cjgl.add('导入教师','/teacher/index/createall','','',true); + cjgl.add('导入教师','/teacher/index/createall','600','300'); break; case 'download': window.open("/teacher/index/downloadxls"); diff --git a/app/tools/controller/File.php b/app/tools/controller/File.php index 2cabbf65..a6eb9e1e 100644 --- a/app/tools/controller/File.php +++ b/app/tools/controller/File.php @@ -20,7 +20,7 @@ class File * str $data['val'] 返回信息 * str $data['url'] 文件路径 */ - public function saveFileInfo($file, $list, $isSave = false) + public function saveFileInfo($file, $list = array(), $isSave = false) { $hash = $file->hash('sha1'); $f = new \app\system\model\Fields; @@ -28,7 +28,7 @@ class File if($serFile) { - $serFile->user_id = session('userid'); + $serFile->user_id = session('admin.userid'); $serFile->save(); $data['msg'] = '文件已经存在'; $data['val'] = true; @@ -49,7 +49,7 @@ class File ,strlen($savename) - strripos($savename ,'\\')); $list['hash'] = $file->hash('sha1'); - $list['user_id'] = session('userid'); + $list['user_id'] = session('admin.userid'); $list['oldname'] = $file->getOriginalName(); $list['fieldsize'] = $file->getSize(); $list['category_id'] = $list['category_id']; diff --git a/app/tools/controller/Index.php b/app/tools/controller/Index.php index 4ccd03cd..395881ea 100644 --- a/app/tools/controller/Index.php +++ b/app/tools/controller/Index.php @@ -5,18 +5,6 @@ namespace app\tools\controller; class Index { - // // 将关联学生成绩转换成以学科列名为key得分为value的数组 - // public function subjectChengjiKeyAndValue($array = array()) - // { - // $arr = array(); - // foreach ($array as $key => $value) { - // $array[$value->subjectName->lieming] = $value; - // unset($array[$key]); - // } - // return $array; - // } - - // 给数组按多条件排序 public function sortArrByManyField(){ $args = func_get_args(); @@ -41,7 +29,7 @@ class Index $keys = array_keys($args[0]); call_user_func_array('array_multisort', $args); - return array_pop($args);; + return array_pop($args); } diff --git a/app/tools/controller/Kaoshi1.php b/app/tools/controller/Kaoshi1.php deleted file mode 100644 index f8ef24fd..00000000 --- a/app/tools/controller/Kaoshi1.php +++ /dev/null @@ -1,30 +0,0 @@ -srcSubject($src); - return $data; - } - - - // 查询参加考试的年级 - public function grade($kaoshi_id) - { - $ksset = new ksset(); - $data = $ksset->srcGrade($kaoshi_id); - return $data; - } - -}