diff --git a/README.md b/README.md index 9e3d2053..87aca2a2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@   这是一款注重优化成绩采集方法、丰富成绩分析维度的小学成绩统计系统,力争做到符合教师工作习惯、使用方法简单、数据分析多样、分析结果科学,为教师的试卷分析、教育科研提供数据参考。 -  开发者是一名非计算机专业的小学教师,只因工作遇到了兴趣,才有了这个小项目。为了让自己统计成绩工作变得更优雅,才边学边写这个成绩统计项目。信息录入与输出简单,支持在单条录入和表格录入、表格输出,尽量让所有信息可管理。在操作设计中,遵循 Giles Colborne 的简约至上原则,尽量做到三步便可到达要操作的位置。统计维度参考华东师范大学教育学系王孝玲教授著作的《教育统计学》第五版。前端采用X-admin,后端采用ThinkPHP框架开发。 +  开发者是一名非计算机专业的小学教师,只因工作遇到了兴趣,才有了这个小项目。为了让自己统计成绩工作变得更优雅,才边学边写这个成绩统计项目。信息录入与输出简单,支持在单条录入和表格录入、表格输出,尽量让所有信息可管理。在操作设计中,遵循 Giles Colborne 的简约至上原则,尽量做到三步便可到达要操作的位置。统计维度参考华东师范大学教育学系王孝玲教授著作的《教育统计学》第五版。前端采用X-adminV2.2,后端采用ThinkPHP V6.0.3框架开发。   “情怀”的代言人罗永浩说:“科技的每一次进步,给我们带来的是更好的世界,而不是完美的世界”。因此,这个项目会一直走在奔向完美的路上,让统计成绩不再是一份辛苦的工作,让大家变成成绩分析牛人! diff --git a/app/chengji/common.php b/app/chengji/common.php index e9e90b62..e388c51c 100644 --- a/app/chengji/common.php +++ b/app/chengji/common.php @@ -146,4 +146,4 @@ function manfenvalidate($defen, $manfen) } return $cj; - } + } \ No newline at end of file diff --git a/app/chengji/controller/Bjtongji.php b/app/chengji/controller/Bjtongji.php index 50053fc1..f3102507 100644 --- a/app/chengji/controller/Bjtongji.php +++ b/app/chengji/controller/Bjtongji.php @@ -274,7 +274,7 @@ class Bjtongji extends BaseController // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $btj = new BTJ; @@ -301,7 +301,7 @@ class Bjtongji extends BaseController // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $btj = new BTJ; diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index 11f7c31e..1869ae13 100644 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -51,6 +51,7 @@ class Index extends BaseController ,'banji_id' => array() ,'searchval' ], 'POST'); + // 获取参与考试的班级 if (count($src['banji_id']) == 0) { $khSrc = new \app\kaohao\model\Search; @@ -294,6 +295,9 @@ class Index extends BaseController $sheet->setCellValue($colname[$i] . '6', '优秀率%'); $sheet->setCellValue($colname[$i] . '7', '及格率%'); $sheet->setCellValue($colname[$i] . '8', '标准差'); + $sheet->setCellValue($colname[$i] . '9', '中位数'); + $sheet->setCellValue($colname[$i] . '10', '众数'); + $i ++; foreach ($subject_id as $key => $value) { $sheet->setCellValue($colname[$i] . '3', $value['title']); @@ -358,17 +362,21 @@ class Index extends BaseController $sheet->setCellValue($colname[$colcnt] . '6', $temp['cj'][$value['lieming']]['youxiu']); $sheet->setCellValue($colname[$colcnt] . '7', $temp['cj'][$value['lieming']]['jige']); $sheet->setCellValue($colname[$colcnt] . '8', $temp['cj'][$value['lieming']]['biaozhuncha']); + $sheet->setCellValue($colname[$colcnt] . '9', $temp['cj'][$value['lieming']]['zhongweishu']); + $sheet->setCellValue($colname[$colcnt] . '10', $temp['cj'][$value['lieming']]['zhongshu']); $colcnt ++; } - $sheet->setCellValue($colname[$colBiankuang - 1] . '9', '总平均分'); - $sheet->setCellValue($colname[$colBiankuang] . '9', $temp['cj']['all']['avg']); - $sheet->mergeCells($colname[$colBiankuang] . '9:' . $colname[$colcnt - 1] . '9'); - $sheet->setCellValue($colname[$colBiankuang - 1] . '10', '全科及格率%'); - $sheet->setCellValue($colname[$colBiankuang] . '10', $temp['cj']['all']['jige']); - $sheet->mergeCells($colname[$colBiankuang] . '10:' . $colname[$colcnt - 1] . '10'); - $sheet->getStyle($colname[$colBiankuang - 1] . '3:' . $colname[$colcnt - 1] . '10')->applyFromArray($styleArrayJZ); - $sheet->getStyle($colname[$colBiankuang - 1] . '3:' . $colname[$colcnt - 1] . '10')->applyFromArray($styleArrayBK); + + $sheet->setCellValue($colname[$colBiankuang - 1] . '11', '总平均分'); + $sheet->setCellValue($colname[$colBiankuang] . '11', $temp['cj']['all']['avg']); + $sheet->mergeCells($colname[$colBiankuang] . '11:' . $colname[$colcnt - 1] . '11'); + $sheet->setCellValue($colname[$colBiankuang - 1] . '12', '全科及格率%'); + $sheet->setCellValue($colname[$colBiankuang] . '12', $temp['cj']['all']['jige']); + $sheet->mergeCells($colname[$colBiankuang] . '12:' . $colname[$colcnt - 1] . '12'); + $sheet->getStyle($colname[$colBiankuang - 1] . '3:' . $colname[$colcnt - 1] . '12')->applyFromArray($styleArrayJZ); + $sheet->getStyle($colname[$colBiankuang - 1] . '3:' . $colname[$colcnt - 1] . '12')->applyFromArray($styleArrayBK); + $sheet->getStyle('A1')->getFont()->setBold(true)->setName('宋体')->setSize(16); # 修改标题字号 $sheet->getDefaultRowDimension()->setRowHeight(22.5); # 设置行高 diff --git a/app/chengji/controller/Njtongji.php b/app/chengji/controller/Njtongji.php index 4c1fb98d..860281eb 100644 --- a/app/chengji/controller/Njtongji.php +++ b/app/chengji/controller/Njtongji.php @@ -262,7 +262,7 @@ class Njtongji extends BaseController // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $ntj = new NTJ; $data = $ntj->tjNianji($kaoshi_id); @@ -294,7 +294,7 @@ class Njtongji extends BaseController // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $ntj = new NTJ; diff --git a/app/chengji/controller/Schtongji.php b/app/chengji/controller/Schtongji.php index edaa403e..6926a825 100644 --- a/app/chengji/controller/Schtongji.php +++ b/app/chengji/controller/Schtongji.php @@ -14,7 +14,7 @@ class Schtongji // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $schtj = new SCHTJ; $data = $schtj->tjSchool($kaoshi_id); @@ -41,7 +41,7 @@ class Schtongji // 获取变量 $kaoshi_id = input('post.kaoshi_id'); // 判断考试状态 - event('ksjs', $kaoshi_id); + event('kstj', $kaoshi_id); // 统计成绩 $schtj = new SCHTJ; diff --git a/app/chengji/model/Tongji.php b/app/chengji/model/Tongji.php index 757771de..e88bcdd4 100644 --- a/app/chengji/model/Tongji.php +++ b/app/chengji/model/Tongji.php @@ -46,6 +46,7 @@ class Tongji extends BaseModel ,'max' => null ,'min' => null ,'zhongshu' => null + ,'zhongweishu' => null ,'defenlv' => null ]; @@ -79,8 +80,10 @@ class Tongji extends BaseModel $temp['max'] = max($cjcol); $temp['min'] = min($cjcol); $temp['sifenwei'] = $this->myquartile($cjcol); - $temp['zhongshu'] = ''; + $temp['zhongshu'] = $this->zhongshu($cjcol); + $temp['zhongweishu'] = $this->zhongweishu($cjcol); $temp['defenlv'] = round($temp['defenlv'] * 100, 2); + $temp['fenshuduan'] = $this->fenshuduan($cjcol, $value['fenshuxian']['manfen']); } $data['cj'][$value['lieming']] = $temp; } @@ -108,8 +111,10 @@ class Tongji extends BaseModel $temp['youxiu'] = null; $temp['jige'] = $this->rateAll($cj, $subject); #全科及格率 $temp['sifenwei'] = $this->myquartile($cjcol); - $temp['zhongshu'] = ''; + $temp['zhongshu'] = $this->zhongshu($cjcol); + $temp['zhongweishu'] = $this->zhongweishu($cjcol); $temp['defenlv'] = round($temp['defenlv'] * 100, 2); + $temp['fenshuduan'] = $this->fenshuduan($cjcol, $value['fenshuxian']['manfen']); } $data['cj']['all'] = $temp; @@ -216,10 +221,6 @@ class Tongji extends BaseModel $q[0] = 1 + ($length - 1 ) * 0.25; $q[1] = 1 + ($length - 1 ) * 0.5; $q[2] = 1 + ($length - 1 ) * 0.75; - // n+1方法结果也对,但是与excel不相同 - // $q[0] = ($length + 1 ) * 0.25; - // $q[1] = ($length + 1 ) * 0.5; - // $q[2] = ($length + 1 ) * 0.75; // 计算每个位置对应的值 foreach ($q as $key => $value) { @@ -238,4 +239,109 @@ class Tongji extends BaseModel return $result; } + + // 计算中位数 + public function zhongweishu($arr) + { + // 将数据排序 + rsort($arr); + $zws = 0; + + $cnt = count($arr); + if ($cnt = 1) { + $zws = $arr[0]; + }elseif ($cnt > 1) { + $mod = $cnt % 2; + if ($mod == 0) { + $i = $cnt / 2; + $zws = ($arr[$i] + $arr[$i + 1]) / 2; + }else{ + $i = ($cnt + 1) / 2; + $zws = $arr[$i]; + } + }else{ + $zws = 0; + } + + return $zws; + } + + + // 计算众数 + public function zhongshu ($arr) + { + // 将数据排序 + rsort($arr); + // 将数据填入数组 + $data = array(); + foreach ($arr as $key => $value) { + if (isset($data[$value])) { + $data[$value] = $data[$value] + 1; + }else{ + $data[$value] = 1; + } + } + // 对数据进行降序排列 + arsort($data); + $i = 0; + $zs = array(); + $old = ''; + foreach ($data as $key => $value) { + if ($value > 2 && $i===0) { + $zs[] = $key; + } elseif ($data[$key] === $old) { + $zs[] = $key; + }else{ + continue; + } + $old = $value; + $i = $i + 1; + } + asort($zs); + $zs = implode($zs,'、'); + + return $zs; + } + + + // 分数段统计 + public function fenshuduan($arr, $manfen) + { + // 计算分数段 + $fenshuduan = array(); + $long = 5; + $cnt = 0; + for($i = 0; $i <= $manfen; $i=$i+$long) + { + $fenshuduan[] = [ + 'low' => $i + ,'high' => $i + $long + ,'cnt' => 0 + ]; + } + + foreach ($arr as $key => $value) { + $xiabiao = intval($value / $long); + if (isset($fenshuduan[$xiabiao])) + { + $fenshuduan[$xiabiao]['cnt'] = $fenshuduan[$xiabiao]['cnt'] + 1; + $cnt = $cnt + 1; + } + } + $count = count($arr); + if ($count > $cnt) + { + $last = array_pop($fenshuduan); + $fenshuduan[] = [ + 'low' => $last['high'] + ,'high' => $last['high'] + $long + ,'cnt' => $count - $cnt + ]; + } + + return $fenshuduan; + } + + + } diff --git a/app/chengji/view/bjtongji/biaoge.html b/app/chengji/view/bjtongji/biaoge.html index bea9b915..2f8ab39e 100644 --- a/app/chengji/view/bjtongji/biaoge.html +++ b/app/chengji/view/bjtongji/biaoge.html @@ -2,6 +2,7 @@ {extend name=".././view/list.html" /} {block name="jsset"} {load href="__STATIC__/echarts/echarts.js" /} +{load href="__STATIC__/echarts/infographic.js" /} {/block} {block name="nav"} @@ -263,7 +264,7 @@ */ function createTiaoxing(id, url, val, title) { - var myTiaoxing = echarts.init(document.getElementById(id)); + var myTiaoxing = echarts.init(document.getElementById(id), 'infographic'); $.post(url,val).done(function (data) { myTiaoxing.setOption({ title:{ @@ -433,7 +434,7 @@ series: myseries, }; - var myXiangti = echarts.init(document.getElementById(id)); + var myXiangti = echarts.init(document.getElementById(id), 'infographic'); myXiangti.setOption(option); }); } diff --git a/app/event.php b/app/event.php index f7587a67..65618efd 100644 --- a/app/event.php +++ b/app/event.php @@ -17,8 +17,8 @@ return [ 'tjlog' => [ '\app\listener\TongjiLog' ], - 'ksjs' => [ - '\app\listener\KaoshiJieShu' + 'kstj' => [ + '\app\listener\KaoshiTongJi' ], ], 'subscribe' => [ diff --git a/app/kaohao/controller/Index.php b/app/kaohao/controller/Index.php index 3f988f96..99d1023f 100644 --- a/app/kaohao/controller/Index.php +++ b/app/kaohao/controller/Index.php @@ -237,6 +237,7 @@ class Index extends BaseController foreach ($defen->ksChengji as $key => $value) { $list['cj'][$value->subject_id]['defen'] = $value->defen * 1; $list['cj'][$value->subject_id]['defenlv'] = $value->defenlv * 1; + $list['cj'][$value->subject_id]['bweizhi'] = $value->bweizhi * 1 .'%'; $list['cj'][$value->subject_id]['title'] = $value->subjectName->title; $list['cj'][$value->subject_id]['color'] = $color[$key % 5]; } diff --git a/app/kaohao/view/index/read.html b/app/kaohao/view/index/read.html index cf4b6b60..939fda68 100644 --- a/app/kaohao/view/index/read.html +++ b/app/kaohao/view/index/read.html @@ -22,7 +22,13 @@
- 成绩列表 + 总分位置 +
+
+
+
+
+ 各学科成绩 @@ -33,7 +39,7 @@ - + @@ -42,7 +48,7 @@ - + {/volist} {else /} @@ -58,7 +64,7 @@
- 得分率 + 学科得分率 {present name="list.cj"} {volist name="list.cj" id="vo"}
@@ -78,7 +84,7 @@
- 雷达图 + 个人成绩与总平均分
@@ -98,8 +104,9 @@ }); getLeiDa("{$list.id}"); + getYiBiao("{$list.id}"); - // 条形统计图--平均分 + // 雷达图 function getLeiDa(kaohao_id){ var url = '/student/studentcj/chengjileida'; var title = '学科成绩雷达图'; @@ -109,6 +116,16 @@ createLeiDa(url,val,title); } + // 仪表图 + function getYiBiao(kaohao_id){ + var url = '/student/studentcj/chengjiyibiao'; + var title = '总成绩仪表图'; + var val = { + kaohao_id: kaohao_id + }; + createYiBiao(url,val,title); + } + /** @@ -164,5 +181,49 @@ }); } + + /** + * 异步获取图表中的数据 + * + * @access public + * @param id 要添加数据的div + * @param url 异步地址 + * @param val 异步时携带的参数 + * @param val 图表标题 + * @return array 返回类型 + */ + function createYiBiao(url, val, title) + { + var myYiBiao = echarts.init(document.getElementById('yibiao')); + $.post(url, val).done(function (data) { + myYiBiao.setOption({ + title: { + text:'', + }, + tooltip: {}, + toolbox: { + id:'yibiao', + show:true, + orient:'horizontal', + showTitle:true, + feature: { + restore: { //重置 + show: true + }, + saveAsImage: { //保存文件 + show: true + }, + }, + }, + series: { + name:data.series.name + ,type:data.series.type + ,data:data.series.data + ,detail:{formatter: data.series.data[0].value + '%'} + } + }) + }); + } + diff --git a/app/kaoshi/view/index/index.html b/app/kaoshi/view/index/index.html index 089f91f0..b259c238 100644 --- a/app/kaoshi/view/index/index.html +++ b/app/kaoshi/view/index/index.html @@ -65,6 +65,9 @@ + diff --git a/app/listener/KaoshiLuru.php b/app/listener/KaoshiLuru.php index 51f65e49..b3243832 100644 --- a/app/listener/KaoshiLuru.php +++ b/app/listener/KaoshiLuru.php @@ -21,9 +21,13 @@ class KaoshiLuru $event = new MyEvent; $ksInfo = $event->ksInfo($kaoshi_id); if($ksInfo){ + if($ksInfo->status == 0) + { + return $this->error('本次考试已经结束!','/login/err'); + } if($ksInfo->luru == 0) { - return $this->error('本次考试已经不允许操作!','/login/err'); + return $this->error('本次考试成绩已经不允许编辑!','/login/err'); } }else{ return $this->error('没有找到考试。','/login/err'); diff --git a/app/listener/KaoshiJieShu.php b/app/listener/KaoshiTongJi.php similarity index 70% rename from app/listener/KaoshiJieShu.php rename to app/listener/KaoshiTongJi.php index 069d14aa..0f06eebf 100644 --- a/app/listener/KaoshiJieShu.php +++ b/app/listener/KaoshiTongJi.php @@ -6,7 +6,7 @@ namespace app\listener; // 实例化考试状态事件 use \app\event\MyEvent; -class KaoshiJieShu +class KaoshiTongJi { /** * 事件监听处理 @@ -20,9 +20,13 @@ class KaoshiJieShu { $event = new MyEvent; $ksInfo = $event->ksInfo($kaoshi_id); + if($ksInfo->luru == 1) + { + return $this->error('请先禁止成绩编辑,再进行其它操作!', '/login/err'); + } if($ksInfo->status == 0) { - return $this->error('本次考试已经结束,不能操作!', '/login/err'); + return $this->error('本次考试已经结束,不能进行操作!', '/login/err'); } return $ksInfo; diff --git a/app/login/view/index/shangma_log.html b/app/login/view/index/shangma_log.html index 43895dce..f7596fd3 100644 --- a/app/login/view/index/shangma_log.html +++ b/app/login/view/index/shangma_log.html @@ -44,17 +44,23 @@
    -
  • +
  • diff --git a/app/middleware/Auth.php b/app/middleware/Auth.php index 7532a09e..751f39a1 100644 --- a/app/middleware/Auth.php +++ b/app/middleware/Auth.php @@ -72,15 +72,16 @@ class Auth 'kaohao/excel/biaoqianxls', # 下载试卷标签 'kaohao/excel/dwcaiji', # 下载成绩采集表 // Renshi应用 - 'renshi/student/ajaxdataby', # 获取毕业学生列表 - 'renshi/student/ajaxdatadel', # 获取删除学生列表 - 'renshi/student/srcstudent', # 查询学生名单 - 'renshi/studentchengji/ajaxonestudentchengjitubiao', # 获取学生成绩拆线图数据 - 'renshi/studentchengji/ajaxonestudentchengjileida', # 获取学生成绩雷达图数据 - 'renshi/teacher/ajaxdatadel', # 获取删除教师列表 - 'renshi/teacher/srcteacher', # 搜索教师 - 'renshi/teacher/srcry', # 获取当前教师荣誉列表 - 'renshi/teacher/srckt', # 获取当前教师课题列表 + 'student/index/ajaxdataby', # 获取毕业学生列表 + 'student/index/ajaxdatadel', # 获取删除学生列表 + 'student/index/srcstudent', # 查询学生名单 + 'student/studentchengji/ajaxonestudentchengjitubiao', # 获取学生成绩拆线图数据 + 'student/studentchengji/ajaxonestudentchengjileida', # 获取学生成绩雷达图数据 + 'student/studentchengji/ajaxonestudentchengjiyibiao', # 获取学生成绩雷达图数据 + 'teacher/index/ajaxdatadel', # 获取删除教师列表 + 'teacher/index/srcteacher', # 搜索教师 + 'teacher/index/srcry', # 获取当前教师荣誉列表 + 'teacher/index/srckt', # 获取当前教师课题列表 // Chengji应用 'chengji/index/ajaxaddinfo', # 获取录入该学生成绩人员的信息 'chengji/index/dwchengjixlsx', # 下载学生成绩 diff --git a/app/student/controller/StudentChengji.php b/app/student/controller/StudentChengji.php index 18e63ea9..95539a83 100644 --- a/app/student/controller/StudentChengji.php +++ b/app/student/controller/StudentChengji.php @@ -117,4 +117,22 @@ class StudentChengji extends BaseController return json($data); } + + + // 获取单个学生单次考试成绩仪表图 + public function ajaxOneStudentChengjiYiBiao() + { + // 获取表单参数 + // 获取参数 + $src = $this->request + ->only([ + 'kaohao_id' => '', + ], 'POST'); + + // 获取学生成绩 + $stucj = new STUCJ; + $data = $stucj->oneStudentYiBiao($src); + + return json($data); + } } diff --git a/app/student/model/StudentChengji.php b/app/student/model/StudentChengji.php index f4454ada..92a1ab0b 100644 --- a/app/student/model/StudentChengji.php +++ b/app/student/model/StudentChengji.php @@ -165,7 +165,7 @@ class StudentChengji extends BaseModel } - // 一个学生一个学科历次成绩 + // 该学生本次考试各学科成绩雷达图 public function oneStudentLeiDa($srcfrom) { // 初始化参数 @@ -195,7 +195,7 @@ class StudentChengji extends BaseModel // 查询区成绩 $SchoolChengji = new \app\chengji\model\TongjiSch; $schcj = $SchoolChengji - ->where('kaoshi_id',$khInfo->kaoshi) + ->where('kaoshi_id',$khInfo->kaoshi_id) ->where('ruxuenian',$khInfo->ruxuenian) ->select(); @@ -234,14 +234,15 @@ class StudentChengji extends BaseModel if($sbj_val['id'] == $cj_val->subject_id) { $bjcj['value'][$i] = $cj_val->defen; + unset($khInfo->ksChengji[$cj_k]); continue; } - if(isset($bjcj['value'][$i]) == false) - { - $bjcj['value'][$i] = null; - } } } + if(isset($bjcj['value'][$i]) == false) + { + $bjcj['value'][$i] = null; + } // 班级成绩 if(isset($qcj['value'][$i]) == false) @@ -250,14 +251,16 @@ class StudentChengji extends BaseModel if($sbj_val['id'] == $sch_val->subject_id) { $qcj['value'][$i] = $sch_val->avg; + unset($schcj[$sch_k]); continue; } - if(isset($qcj['value'][$i]) == false) - { - $qcj['value'][$i] = null; - } + } } + if(isset($qcj['value'][$i]) == false) + { + $qcj['value'][$i] = null; + } $i++; } @@ -273,6 +276,64 @@ class StudentChengji extends BaseModel ] ]; + return $data; + } + + + // 该学生本次考试各学科成绩仪表图 + public function oneStudentYiBiao($srcfrom) + { + // 初始化参数 + $src = array( + 'kaohao_id' => '', + ); + + // 用新值替换初始值 + $src = array_cover($srcfrom, $src); + + // 成绩查询信息 + $kh = new \app\kaohao\model\Kaohao; #该考号对应的考试信息。 + $khInfo = $kh->where('id', $src['kaohao_id']) + ->find(); + $src['ruxuenian'] = $khInfo->ruxuenian; #设置查询条件 + $src['kaoshi_id'] = $khInfo->kaoshi_id; + $khSrc = new \app\kaohao\model\Search; + $src['banji_id'] = array_column($khSrc->cyBanji($src), 'id'); + + // 实例化并查询成绩 + $cj = new \app\chengji\model\Chengji; + $data = $cj->search($src); + if (count($data)>0) { + $data = sortArrByManyField($data, 'sum', SORT_DESC); + $data = array_column($data, 'id'); + $rank = array_search($src['kaohao_id'], $data); + $rank = round(($rank + 1) / count($data) * 100, 0); + + $data = [ + 'title' => '学生成绩' + ,'series' => [ + 'name'=>'总成绩位置' + ,'type' => 'gauge' + // ,'detail' => $rank . '%' + ,'data' => [['value'=>$rank, 'name'=>'位置']] + ] + ]; + } else { + $data = [ + 'title' => '学生成绩' + ,'series' => [ + 'name'=>'总成绩位置' + ,'type' => 'gauge' + // ,'detail' => $rank . '%' + ,'data' => [['value'=>0, 'name'=>'位置']] + ] + ]; + } + + + + + return $data; } diff --git a/app/student/route/student.php b/app/student/route/student.php index 54707c8a..01389900 100644 --- a/app/student/route/student.php +++ b/app/student/route/student.php @@ -38,17 +38,10 @@ Route::group('index', function () { // 学生成绩列表 Route::group('studentcj', function () { - Route::rule('','StudentChengji/index','get'); # 读取信息 + Route::rule('index/','StudentChengji/index','get'); # 读取信息 Route::rule('data','StudentChengji/ajaxData','post'); # 获取学生成绩列表 Route::rule('chengjitubiao','StudentChengji/ajaxOneStudentChengjiTuBiao','post'); # 获取学生成绩列表 Route::rule('chengjileida','StudentChengji/ajaxOneStudentChengjiLeiDa','post'); # 获取学生成绩列表 + Route::rule('chengjiyibiao','StudentChengji/ajaxOneStudentChengjiYiBiao','post'); # 获取学生成绩列表 }); - -// // 学生管理 -// Route::group('student', function () { -// Route::rule('bylist','Student/byList','get'); # 信息列表 -// Route::rule('databy','Student/ajaxdataBy','post'); # 获取数据 -// Route::rule('dellist','Student/delList','get'); # 信息列表 -// Route::rule('datadel','Student/ajaxdataDel','post'); # 获取数据 -// }); \ No newline at end of file diff --git a/app/student/view/index/by_list.html b/app/student/view/index/by_list.html index 868cf3e7..0c417348 100644 --- a/app/student/view/index/by_list.html +++ b/app/student/view/index/by_list.html @@ -113,10 +113,10 @@ var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ case 'detail':// 查看 - cjgl.add(obj.data.xingming+'信息','/student/index/read/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'信息','/student/index/read/'+obj.data.id,true); break; case 'chengji':// 查看 - cjgl.add(obj.data.xingming+'成绩','/student/studentcj/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'成绩','/student/studentcj/index/'+obj.data.id,true); break; }; }); diff --git a/app/student/view/index/del_list.html b/app/student/view/index/del_list.html index 9df25119..55b9de68 100644 --- a/app/student/view/index/del_list.html +++ b/app/student/view/index/del_list.html @@ -111,10 +111,10 @@ var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ case 'detail':// 查看 - cjgl.add(obj.data.xingming+'信息','/student/index/read/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'信息','/student/index/read/'+obj.data.id,true); break; case 'chengji':// 查看 - cjgl.add(obj.data.xingming+'成绩','/student/studentcj/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'成绩','/student/studentcj/index/'+obj.data.id,true); break; case 'huifu':// 恢复删除 cjgl.redel(obj,"/student/index/redel"); diff --git a/app/student/view/index/index.html b/app/student/view/index/index.html index 209c3dee..277fc5f4 100644 --- a/app/student/view/index/index.html +++ b/app/student/view/index/index.html @@ -140,10 +140,10 @@ var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ case 'detail':// 查看 - cjgl.add(obj.data.xingming+'-信息','/student/index/read/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'-信息','/student/index/read/'+obj.data.id,true); break; case 'chengji':// 查看 - parent.xadmin.add_tab(obj.data.xingming + ' - 成绩','/student/studentcj/'+obj.data.id,true); + cjgl.addTab(obj.data.xingming + ' - 成绩','/student/studentcj/index/'+obj.data.id,true); break; case 'del':// 删除 cjgl.del(obj,"/student/index/delete"); diff --git a/app/system/controller/Fields.php b/app/system/controller/Fields.php index 8f45410d..f7762ed0 100644 --- a/app/system/controller/Fields.php +++ b/app/system/controller/Fields.php @@ -74,7 +74,14 @@ class Fields extends BaseController } $url = public_path() . 'public\\uploads\\' . $filist->url; - return download($url, $oldname); + + $data = file_exists($url); + if ($data === true) { + return download($url, $oldname); + } else { + return $this->error('文件不存在!'); + } + } diff --git a/app/system/view/fields/index.html b/app/system/view/fields/index.html index 0992fef5..02ba27b7 100644 --- a/app/system/view/fields/index.html +++ b/app/system/view/fields/index.html @@ -17,7 +17,7 @@
    + autocomplete="off" class="layui-input" placeholder="输入文件名并回车">
    {/block} @@ -101,7 +101,8 @@ cjgl.del(obj,"file/delete"); break; case 'download':// 编辑 - cjgl.add('下载文件','file/download/'+obj.data.id,'350','150'); + var data = cjgl.add('下载文件','file/download/'+obj.data.id,'350','150',false); + console.log(data); break; }; }); diff --git a/app/teach/view/subject/create.html b/app/teach/view/subject/create.html index 8393f15a..8bf46525 100644 --- a/app/teach/view/subject/create.html +++ b/app/teach/view/subject/create.html @@ -76,7 +76,7 @@
    + autocomplete="off" class="layui-input" value="{$list.data.paixu|999}" placeholder="数字1-999">
diff --git a/app/teacher/view/index/del_list.html b/app/teacher/view/index/del_list.html index 8002dc82..471a0135 100644 --- a/app/teacher/view/index/del_list.html +++ b/app/teacher/view/index/del_list.html @@ -93,7 +93,7 @@ layer.msg('这个~算了吧!'); break; var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值 - cjgl.delAll(checkStatus,'/renshi/teacher/delete','mytable'); + cjgl.delAll(checkStatus,'/teacher/index/delete','mytable'); break; }; }); @@ -105,10 +105,10 @@ var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ case 'detail':// 查看 - cjgl.add(obj.data.xingming+'信息','/renshi/teacher/read/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'信息','/teacher/index/read/'+obj.data.id,true); break; case 'huifu':// 恢复删除 - cjgl.redel(obj,"/renshi/teacher/redel"); + cjgl.redel(obj,"/teacher/index/redel"); break; }; }); diff --git a/app/teacher/view/index/index.html b/app/teacher/view/index/index.html index 6ca6cafd..dda0ed95 100644 --- a/app/teacher/view/index/index.html +++ b/app/teacher/view/index/index.html @@ -160,7 +160,7 @@ var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ case 'detail':// 查看 - cjgl.add(obj.data.xingming+'信息','/teacher/index/read/'+obj.data.id,'','',true); + cjgl.addTab(obj.data.xingming+'信息','/teacher/index/read/'+obj.data.id,true); break; case 'del':// 删除 cjgl.del(obj,"/teacher/index/delete"); diff --git a/composer.lock b/composer.lock index 54995b86..3702fcfd 100644 --- a/composer.lock +++ b/composer.lock @@ -889,16 +889,16 @@ }, { "name": "topthink/framework", - "version": "v6.0.2", + "version": "v6.0.3", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "1444cce94b40a836958380b160a5fb7bfc165daf" + "reference": "b4046fb21e6163ba23a792b694162693dbe71b4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/1444cce94b40a836958380b160a5fb7bfc165daf", - "reference": "1444cce94b40a836958380b160a5fb7bfc165daf", + "url": "https://api.github.com/repos/top-think/framework/zipball/b4046fb21e6163ba23a792b694162693dbe71b4b", + "reference": "b4046fb21e6163ba23a792b694162693dbe71b4b", "shasum": "", "mirrors": [ { @@ -953,7 +953,7 @@ "orm", "thinkphp" ], - "time": "2020-01-13T05:48:05+00:00" + "time": "2020-06-26T16:03:10+00:00" }, { "name": "topthink/think-captcha", diff --git a/database/migrations/20200616052125_teacher_zhiwu.php b/database/migrations/20200616052125_teacher_zhiwu.php index 2d4e125f..0b6ac750 100644 --- a/database/migrations/20200616052125_teacher_zhiwu.php +++ b/database/migrations/20200616052125_teacher_zhiwu.php @@ -29,7 +29,7 @@ class TeacherZhiwu extends Migrator public function up() { // 定义数据表名称 - $table = $this->table('teacher'); + $table = $this->table('teacher_zhiwu'); // 添加当前表字段 $table diff --git a/database/seeds/Rule.php b/database/seeds/Rule.php index 82059d09..15582767 100644 --- a/database/seeds/Rule.php +++ b/database/seeds/Rule.php @@ -144,7 +144,7 @@ class Rule extends Seeder ,'pid' => 301 ], ['id' => 30107 - ,'title' => '操作成绩权限' + ,'title' => '成绩编辑' ,'name' => 'kaoshi/index/luru' ,'paixu' => 7 ,'pid' => 301 @@ -210,6 +210,18 @@ class Rule extends Seeder ,'paixu' => 6 ,'pid' => 3020101 ], + ['id' => 302010108 + ,'title' => '统计得分率' + ,'name' => 'chengji/tongji/editdefenlv' + ,'paixu' => 4 + ,'pid' => 3020101 + ], + ['id' => 302010109 + ,'title' => '更新得分率' + ,'name' => 'chengji/tongji/updatedefenLv' + ,'paixu' => 5 + ,'pid' => 3020101 + ], ['id' => 3020102 ,'title' => '生成考号' ,'name' => 'kaohao/index/createall' @@ -445,116 +457,116 @@ class Rule extends Seeder ], /*====================================================================== - * 考试管理 + * 学生管理 */ ['id' => 4 - ,'title' => '师生名单' - ,'name' => 'renshi' + ,'title' => '学生管理' + ,'name' => 'student' ,'paixu' => 3 ,'ismenu' => 1 - ,'font' => '' + ,'font' => '' ], ['id' => 401 ,'title' => '学生列表' - ,'name' => 'renshi/student/index' + ,'name' => 'student/index/index' ,'paixu' => 1 ,'ismenu' => 1 ,'pid' => 4 - ,'url' => '/renshi/student' + ,'url' => '/student/index/index' ], // 学生管理权限 ['id' => 40101 ,'title' => '添加' - ,'name' => 'renshi/student/create' + ,'name' => 'student/index/create' ,'paixu' => 1 ,'pid' => 401 ], ['id' => 40102 ,'title' => '保存' - ,'name' => 'renshi/student/save' + ,'name' => 'student/index/save' ,'paixu' => 2 ,'pid' => 401 ], ['id' => 40103 ,'title' => '删除' - ,'name' => 'renshi/student/delete' + ,'name' => 'student/index/delete' ,'paixu' => 3 ,'pid' => 401 ], ['id' => 40104 ,'title' => '编辑' - ,'name' => 'renshi/student/edit' + ,'name' => 'student/index/edit' ,'paixu' => 4 ,'pid' => 401 ], ['id' => 40105 ,'title' => '更新' - ,'name' => 'renshi/student/update' + ,'name' => 'student/index/update' ,'paixu' => 5 ,'pid' => 401 ], ['id' => 40106 ,'title' => '查看信息' - ,'name' => 'renshi/student/read' + ,'name' => 'student/index/read' ,'paixu' => 6 ,'pid' => 401 ] ,['id' => 40107 ,'title' => '状态' - ,'name' => 'renshi/student/setstatus' + ,'name' => 'student/index/setstatus' ,'paixu' => 7 ,'pid' => 401 ], ['id' => 40108 ,'title' => '是否参加考试' - ,'name' => 'renshi/student/setkaoshi' + ,'name' => 'student/index/setkaoshi' ,'paixu' => 8 ,'pid' => 401 ], ['id' => 40109 ,'title' => '下载模板' - ,'name' => 'renshi/student/download' + ,'name' => 'student/index/download' ,'paixu' => 9 ,'pid' => 401 ], ['id' => 40110 ,'title' => '校对导入' - ,'name' => 'renshi/student/createall' + ,'name' => 'student/index/createall' ,'paixu' => 10 ,'pid' => 401 ], ['id' => 4011 ,'title' => '批量保存' - ,'name' => 'renshi/student/saveall' + ,'name' => 'student/index/saveall' ,'paixu' => 11 ,'pid' => 401 ], ['id' => 40112 ,'title' => '表格删除页面' - ,'name' => 'renshi/student/deletes' + ,'name' => 'student/index/deletes' ,'paixu' => 12 ,'pid' => 401 ], ['id' => 40113 ,'title' => '表格删除数据' - ,'name' => 'renshi/student/deletexlsx' + ,'name' => 'student/index/deletexlsx' ,'paixu' => 13 ,'pid' => 401 ], ['id' => 40114 ,'title' => '查看成绩' - ,'name' => 'renshi/studentchengji/index' + ,'name' => 'student/studentchengji/index' ,'paixu' => 14 ,'pid' => 401 ], - // 师生名单 + // 师生名单 ['id' => 402 ,'title' => '毕业学生' - ,'name' => 'renshi/student/bylist' + ,'name' => 'student/index/bylist' ,'paixu' => 2 ,'ismenu' => 1 ,'pid' => 4 - ,'url' => '/renshi/student/bylist' + ,'url' => '/student/index/bylist' ], // 毕业学生 ['id' => 40201 @@ -566,109 +578,21 @@ class Rule extends Seeder // 师生名单 ['id' => 403 ,'title' => '删除学生' - ,'name' => 'renshi/student/dellist' + ,'name' => 'student/index/dellist' ,'paixu' => 3 ,'ismenu' => 1 ,'pid' => 4 - ,'url' => '/renshi/student/dellist' + ,'url' => '/student/index/dellist' ], // 删除学生 ['id' => 40301 ,'title' => '恢复删除' - ,'name' => 'renshi/student/redel' + ,'name' => 'student/index/redel' ,'paixu' => 1 ,'pid' => 403 ], - ['id' => 404 - ,'title' => '教师列表' - ,'name' => 'renshi/teacher/index' - ,'paixu' => 4 - ,'ismenu' => 1 - ,'pid' => 4 - ,'url' => '/renshi/teacher' - ], - // 教师管理权限 - ['id' => 40401 - ,'title' => '添加' - ,'name' => 'renshi/teacher/create' - ,'paixu' => 1 - ,'pid' => 404 - ], - ['id' => 40402 - ,'title' => '保存' - ,'name' => 'renshi/teacher/save' - ,'paixu' => 2 - ,'pid' => 404 - ], - ['id' => 40403 - ,'title' => '删除' - ,'name' => 'renshi/teacher/delete' - ,'paixu' => 3 - ,'pid' => 404 - ], - ['id' => 40404 - ,'title' => '编辑' - ,'name' => 'renshi/teacher/edit' - ,'paixu' => 4 - ,'pid' => 404 - ], - ['id' => 40405 - ,'title' => '更新' - ,'name' => 'renshi/teacher/update' - ,'paixu' => 5 - ,'pid' => 404 - ], - ['id' => 40406 - ,'title' => '查看' - ,'name' => 'renshi/teacher/read' - ,'paixu' => 6 - ,'pid' => 404 - ], - ['id' => 40407 - ,'title' => '状态' - ,'name' => 'renshi/teacher/setstatus' - ,'paixu' => 7 - ,'pid' => 404 - ], - ['id' => 40408 - ,'title' => '查询教师' - ,'name' => 'renshi/teacher/srcteacher' - ,'paixu' => 8 - ,'pid' => 404 - ], - ['id' => 40409 - ,'title' => '批量上传' - ,'name' => 'renshi/teacher/createall' - ,'paixu' => 9 - ,'pid' => 404 - ], - ['id' => 40410 - ,'title' => '批量保存' - ,'name' => 'renshi/teacher/saveall' - ,'paixu' => 10 - ,'pid' => 404 - ], - ['id' => 40411 - ,'title' => '表格模板下载' - ,'name' => 'renshi/teacher/downloadxls' - ,'paixu' => 11 - ,'pid' => 404 - ], - ['id' => 405 - ,'title' => '删除教师' - ,'name' => 'renshi/teacher/dellist' - ,'paixu' => 5 - ,'ismenu' => 1 - ,'pid' => 4 - ,'url' => '/renshi/teacher/dellist' - ], - // 删除教师 - ['id' => 40501 - ,'title' => '恢复删除' - ,'name' => 'renshi/teacher/redel' - ,'paixu' => 1 - ,'pid' => 405 - ], + + /*====================================================================== * 考试管理 @@ -676,7 +600,7 @@ class Rule extends Seeder ['id' => 5 ,'title' => '教务管理' ,'name' => 'teach' - ,'paixu' => 4 + ,'paixu' => 7 ,'ismenu' => 1 ,'font' => '' ], @@ -838,7 +762,7 @@ class Rule extends Seeder ['id' => 6 ,'title' => '管理员管理' ,'name' => 'admin' - ,'paixu' => 9 + ,'paixu' => 8 ,'ismenu' => 1 ,'font' => '' ], @@ -1537,6 +1461,105 @@ class Rule extends Seeder ,'status' => 0 ], + // 教师管理 + ['id' => 10 + ,'title' => '教师管理' + ,'name' => 'teacher' + ,'paixu' => 4 + ,'ismenu' => 1 + ,'font' => '' + ], + ['id' => 1001 + ,'title' => '教师列表' + ,'name' => 'teacher/index/index' + ,'paixu' => 1 + ,'ismenu' => 1 + ,'pid' => 10 + ,'url' => '/teacher/index/index' + ], + // 教师管理权限 + ['id' => 100101 + ,'title' => '添加' + ,'name' => 'teacher/index/create' + ,'paixu' => 1 + ,'pid' => 1001 + ], + ['id' => 100102 + ,'title' => '保存' + ,'name' => 'teacher/index/save' + ,'paixu' => 2 + ,'pid' => 1001 + ], + ['id' => 100103 + ,'title' => '删除' + ,'name' => 'teacher/index/delete' + ,'paixu' => 3 + ,'pid' => 1001 + ], + ['id' => 100104 + ,'title' => '编辑' + ,'name' => 'teacher/index/edit' + ,'paixu' => 4 + ,'pid' => 1001 + ], + ['id' => 100105 + ,'title' => '更新' + ,'name' => 'teacher/index/update' + ,'paixu' => 5 + ,'pid' => 1001 + ], + ['id' => 100106 + ,'title' => '查看' + ,'name' => 'teacher/index/read' + ,'paixu' => 6 + ,'pid' => 1001 + ], + ['id' => 100107 + ,'title' => '状态' + ,'name' => 'teacher/index/setstatus' + ,'paixu' => 7 + ,'pid' => 1001 + ], + ['id' => 100108 + ,'title' => '查询教师' + ,'name' => 'teacher/index/srcteacher' + ,'paixu' => 8 + ,'pid' => 1001 + ], + ['id' => 100109 + ,'title' => '批量上传' + ,'name' => 'teacher/index/createall' + ,'paixu' => 9 + ,'pid' => 1001 + ], + ['id' => 100110 + ,'title' => '批量保存' + ,'name' => 'teacher/index/saveall' + ,'paixu' => 10 + ,'pid' => 1001 + ], + ['id' => 100111 + ,'title' => '表格模板下载' + ,'name' => 'teacher/index/downloadxls' + ,'paixu' => 11 + ,'pid' => 1001 + ], + ['id' => 1002 + ,'title' => '删除教师' + ,'name' => 'teacher/index/dellist' + ,'paixu' => 2 + ,'ismenu' => 1 + ,'pid' => 10 + ,'url' => '/teacher/index/dellist' + ], + // 删除教师 + ['id' => 100201 + ,'title' => '恢复删除' + ,'name' => 'teacher/index/redel' + ,'paixu' => 1 + ,'pid' => 1002 + ], + ]; // 保存数据 $this->table('auth_rule')->insert($rows)->save(); diff --git a/public/static/echarts/infographic.js b/public/static/echarts/infographic.js new file mode 100644 index 00000000..df47b912 --- /dev/null +++ b/public/static/echarts/infographic.js @@ -0,0 +1,204 @@ +(function (root, factory) {if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['exports', 'echarts'], factory); + } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { + // CommonJS + factory(exports, require('echarts')); + } else { + // Browser globals + factory({}, root.echarts); + } +}(this, function (exports, echarts) { + var log = function (msg) { + if (typeof console !== 'undefined') { + console && console.error && console.error(msg); + } + }; + if (!echarts) { + log('ECharts is not Loaded'); + return; + } + + var colorPalette = [ + '#C1232B','#27727B','#FCCE10','#E87C25','#B5C334', + '#FE8463','#9BCA63','#FAD860','#F3A43B','#60C0DD', + '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0' + ]; + + var theme = { + + color: colorPalette, + + title: { + textStyle: { + fontWeight: 'normal', + color: '#27727B' + } + }, + + visualMap: { + color:['#C1232B','#FCCE10'] + }, + + toolbox: { + iconStyle: { + normal: { + borderColor: colorPalette[0] + } + } + }, + + tooltip: { + backgroundColor: 'rgba(50,50,50,0.5)', + axisPointer : { + type : 'line', + lineStyle : { + color: '#27727B', + type: 'dashed' + }, + crossStyle: { + color: '#27727B' + }, + shadowStyle : { + color: 'rgba(200,200,200,0.3)' + } + } + }, + + dataZoom: { + dataBackgroundColor: 'rgba(181,195,52,0.3)', + fillerColor: 'rgba(181,195,52,0.2)', + handleColor: '#27727B' + }, + + categoryAxis: { + axisLine: { + lineStyle: { + color: '#27727B' + } + }, + splitLine: { + show: false + } + }, + + valueAxis: { + axisLine: { + show: false + }, + splitArea : { + show: false + }, + splitLine: { + lineStyle: { + color: ['#ccc'], + type: 'dashed' + } + } + }, + + timeline: { + lineStyle: { + color: '#27727B' + }, + controlStyle: { + normal: { + color: '#27727B', + borderColor: '#27727B' + } + }, + symbol: 'emptyCircle', + symbolSize: 3 + }, + + line: { + itemStyle: { + normal: { + borderWidth:2, + borderColor:'#fff', + lineStyle: { + width: 3 + } + }, + emphasis: { + borderWidth:0 + } + }, + symbol: 'circle', + symbolSize: 3.5 + }, + + candlestick: { + itemStyle: { + normal: { + color: '#C1232B', + color0: '#B5C334', + lineStyle: { + width: 1, + color: '#C1232B', + color0: '#B5C334' + } + } + } + }, + + graph: { + color: colorPalette + }, + + map: { + label: { + normal: { + textStyle: { + color: '#C1232B' + } + }, + emphasis: { + textStyle: { + color: 'rgb(100,0,0)' + } + } + }, + itemStyle: { + normal: { + areaColor: '#ddd', + borderColor: '#eee' + }, + emphasis: { + areaColor: '#fe994e' + } + } + }, + + gauge: { + axisLine: { + lineStyle: { + color: [[0.2, '#B5C334'],[0.8, '#27727B'],[1, '#C1232B']] + } + }, + axisTick: { + splitNumber: 2, + length: 5, + lineStyle: { + color: '#fff' + } + }, + axisLabel: { + textStyle: { + color: '#fff' + } + }, + splitLine: { + length: '5%', + lineStyle: { + color: '#fff' + } + }, + title : { + offsetCenter: [0, -20] + } + } + }; + + echarts.registerTheme('infographic', theme); +})); \ No newline at end of file diff --git a/public/static/echarts/roma.js b/public/static/echarts/roma.js new file mode 100644 index 00000000..e69de29b diff --git a/public/static/echarts/shine.js b/public/static/echarts/shine.js new file mode 100644 index 00000000..e69de29b diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 73696975..d7bcf3ff 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1122,17 +1122,17 @@ }, { "name": "topthink/framework", - "version": "v6.0.2", - "version_normalized": "6.0.2.0", + "version": "v6.0.3", + "version_normalized": "6.0.3.0", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "1444cce94b40a836958380b160a5fb7bfc165daf" + "reference": "b4046fb21e6163ba23a792b694162693dbe71b4b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/1444cce94b40a836958380b160a5fb7bfc165daf", - "reference": "1444cce94b40a836958380b160a5fb7bfc165daf", + "url": "https://api.github.com/repos/top-think/framework/zipball/b4046fb21e6163ba23a792b694162693dbe71b4b", + "reference": "b4046fb21e6163ba23a792b694162693dbe71b4b", "shasum": "", "mirrors": [ { @@ -1159,7 +1159,7 @@ "mockery/mockery": "^1.2", "phpunit/phpunit": "^7.0" }, - "time": "2020-01-13T05:48:05+00:00", + "time": "2020-06-26T16:03:10+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/services.php b/vendor/services.php index 65fa597a..cefc6671 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\captcha\\CaptchaService', diff --git a/vendor/topthink/framework/README.md b/vendor/topthink/framework/README.md index 8c856b47..be0bb4e6 100644 --- a/vendor/topthink/framework/README.md +++ b/vendor/topthink/framework/README.md @@ -13,6 +13,8 @@ ThinkPHP 6.0 ThinkPHP6.0底层架构采用PHP7.1改写和进一步优化。 +[官方应用服务市场](https://www.thinkphp.cn/service) | [`ThinkPHP`开发者扶持计划](https://sites.thinkphp.cn/1782366) + ## 主要新特性 * 采用`PHP7`强类型(严格模式) @@ -69,7 +71,7 @@ composer update topthink/framework ## 参与开发 -请参阅 [ThinkPHP核心框架包](https://github.com/top-think/framework)。 +直接提交PR或者Issue即可 ## 版权信息 @@ -77,9 +79,7 @@ ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 本项目包含的第三方源码和二进制文件之版权信息另行标注。 -版权所有Copyright © 2006-2019 by ThinkPHP (http://thinkphp.cn) - -All rights reserved。 +版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn) All rights reserved。 ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 diff --git a/vendor/topthink/framework/composer.json b/vendor/topthink/framework/composer.json index 017b3d96..1405162e 100644 --- a/vendor/topthink/framework/composer.json +++ b/vendor/topthink/framework/composer.json @@ -44,7 +44,7 @@ }, "autoload-dev": { "psr-4": { - "think\\tests\\": "src/tests/" + "think\\tests\\": "tests/" } }, "minimum-stability": "dev", diff --git a/vendor/topthink/framework/src/helper.php b/vendor/topthink/framework/src/helper.php index d1ba0474..8b289988 100644 --- a/vendor/topthink/framework/src/helper.php +++ b/vendor/topthink/framework/src/helper.php @@ -359,7 +359,7 @@ if (!function_exists('parse_name')) { return $ucfirst ? ucfirst($name) : lcfirst($name); } - return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); + return strtolower(trim(preg_replace('/[A-Z]/', '_\\0', $name), '_')); } } @@ -632,7 +632,7 @@ if (!function_exists('public_path')) { */ function public_path($path = '') { - return app()->getRootPath() . ($path ? ltrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $path); + return app()->getRootPath() . 'public' . DIRECTORY_SEPARATOR . ($path ? ltrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $path); } } diff --git a/vendor/topthink/framework/src/think/App.php b/vendor/topthink/framework/src/think/App.php index 24c03f39..09433950 100644 --- a/vendor/topthink/framework/src/think/App.php +++ b/vendor/topthink/framework/src/think/App.php @@ -39,7 +39,7 @@ use think\initializer\RegisterService; */ class App extends Container { - const VERSION = '6.0.2'; + const VERSION = '6.0.3'; /** * 应用调试模式 @@ -602,9 +602,7 @@ class App extends Container */ protected function getDefaultRootPath(): string { - $path = dirname(dirname(dirname(dirname($this->thinkPath)))); - - return $path . DIRECTORY_SEPARATOR; + return dirname($this->thinkPath, 4) . DIRECTORY_SEPARATOR; } } diff --git a/vendor/topthink/framework/src/think/Db.php b/vendor/topthink/framework/src/think/Db.php index 06b7ff29..fac8d072 100644 --- a/vendor/topthink/framework/src/think/Db.php +++ b/vendor/topthink/framework/src/think/Db.php @@ -15,6 +15,7 @@ namespace think; /** * 数据库管理类 * @package think + * @property Config $config */ class Db extends DbManager { @@ -32,7 +33,9 @@ class Db extends DbManager $db->setConfig($config); $db->setEvent($event); $db->setLog($log); - $db->setCache($cache); + + $store = $db->getConfig('cache_store'); + $db->setCache($cache->store($store)); $db->triggerSql(); return $db; diff --git a/vendor/topthink/framework/src/think/Event.php b/vendor/topthink/framework/src/think/Event.php index ecb99123..edef54cc 100644 --- a/vendor/topthink/framework/src/think/Event.php +++ b/vendor/topthink/framework/src/think/Event.php @@ -39,12 +39,6 @@ class Event 'LogWrite' => event\LogWrite::class, ]; - /** - * 是否需要事件响应 - * @var bool - */ - protected $withEvent = true; - /** * 应用对象 * @var App @@ -56,18 +50,6 @@ class Event $this->app = $app; } - /** - * 设置是否开启事件响应 - * @access protected - * @param bool $event 是否需要事件响应 - * @return $this - */ - public function withEvent(bool $event) - { - $this->withEvent = $event; - return $this; - } - /** * 批量注册事件监听 * @access public @@ -76,10 +58,6 @@ class Event */ public function listenEvents(array $events) { - if (!$this->withEvent) { - return $this; - } - foreach ($events as $event => $listeners) { if (isset($this->bind[$event])) { $event = $this->bind[$event]; @@ -101,10 +79,6 @@ class Event */ public function listen(string $event, $listener, bool $first = false) { - if (!$this->withEvent) { - return $this; - } - if (isset($this->bind[$event])) { $event = $this->bind[$event]; } @@ -169,10 +143,6 @@ class Event */ public function subscribe($subscriber) { - if (!$this->withEvent) { - return $this; - } - $subscribers = (array) $subscriber; foreach ($subscribers as $subscriber) { @@ -201,10 +171,6 @@ class Event */ public function observe($observer, string $prefix = '') { - if (!$this->withEvent) { - return $this; - } - if (is_string($observer)) { $observer = $this->app->make($observer); } @@ -238,10 +204,6 @@ class Event */ public function trigger($event, $params = null, bool $once = false) { - if (!$this->withEvent) { - return; - } - if (is_object($event)) { $params = $event; $event = get_class($event); diff --git a/vendor/topthink/framework/src/think/File.php b/vendor/topthink/framework/src/think/File.php index cb4cca05..77bec891 100644 --- a/vendor/topthink/framework/src/think/File.php +++ b/vendor/topthink/framework/src/think/File.php @@ -157,11 +157,11 @@ class File extends SplFileInfo /** * 自动生成文件名 - * @access protected + * @access public * @param string|\Closure $rule * @return string */ - public function hashName($rule = 'date'): string + public function hashName($rule = ''): string { if (!$this->hashName) { if ($rule instanceof \Closure) { diff --git a/vendor/topthink/framework/src/think/Http.php b/vendor/topthink/framework/src/think/Http.php index a78b8b4d..6de30b59 100644 --- a/vendor/topthink/framework/src/think/Http.php +++ b/vendor/topthink/framework/src/think/Http.php @@ -191,9 +191,6 @@ class Http // 加载全局中间件 $this->loadMiddleware(); - // 设置开启事件机制 - $this->app->event->withEvent($this->app->config->get('app.with_event', true)); - // 监听HttpRun $this->app->event->trigger(HttpRun::class); diff --git a/vendor/topthink/framework/src/think/Lang.php b/vendor/topthink/framework/src/think/Lang.php index aed43fdb..be27f5e7 100644 --- a/vendor/topthink/framework/src/think/Lang.php +++ b/vendor/topthink/framework/src/think/Lang.php @@ -33,6 +33,8 @@ class Lang 'extend_list' => [], // 多语言cookie变量 'cookie_var' => 'think_lang', + // 多语言header变量 + 'header_var' => 'think-lang', // 多语言自动侦测变量名 'detect_var' => 'lang', // Accept-Language转义为对应语言包名称 @@ -118,9 +120,9 @@ class Lang $lang = []; - foreach ((array) $file as $_file) { - if (is_file($_file)) { - $result = $this->parse($_file); + foreach ((array) $file as $name) { + if (is_file($name)) { + $result = $this->parse($name); $lang = array_change_key_case($result) + $lang; } } @@ -239,6 +241,9 @@ class Lang if ($request->get($this->config['detect_var'])) { // url中设置了语言变量 $langSet = strtolower($request->get($this->config['detect_var'])); + } elseif ($request->header($this->config['header_var'])) { + // Header中设置了语言变量 + $langSet = strtolower($request->header($this->config['header_var'])); } elseif ($request->cookie($this->config['cookie_var'])) { // Cookie中设置了语言变量 $langSet = strtolower($request->cookie($this->config['cookie_var'])); diff --git a/vendor/topthink/framework/src/think/Request.php b/vendor/topthink/framework/src/think/Request.php index 0053c0b0..0181ab89 100644 --- a/vendor/topthink/framework/src/think/Request.php +++ b/vendor/topthink/framework/src/think/Request.php @@ -12,6 +12,7 @@ declare (strict_types = 1); namespace think; +use ArrayAccess; use think\file\UploadedFile; use think\route\Rule; @@ -19,7 +20,7 @@ use think\route\Rule; * 请求管理类 * @package think */ -class Request +class Request implements ArrayAccess { /** * 兼容PATH_INFO获取 @@ -898,7 +899,8 @@ class Request */ public function setRoute(array $route) { - $this->route = array_merge($this->route, $route); + $this->route = array_merge($this->route, $route); + $this->mergeParam = false; return $this; } @@ -985,7 +987,7 @@ class Request protected function getInputData($content): array { $contentType = $this->contentType(); - if ($contentType == 'application/x-www-form-urlencoded') { + if ('application/x-www-form-urlencoded' == $contentType) { parse_str($content, $data); return $data; } elseif (false !== strpos($contentType, 'json')) { @@ -1754,7 +1756,7 @@ class Request if ($this->host) { $host = $this->host; } else { - $host = strval($this->server('HTTP_X_REAL_HOST') ?: $this->server('HTTP_HOST')); + $host = strval($this->server('HTTP_X_FORWARDED_HOST') ?: $this->server('HTTP_HOST')); } return true === $strict && strpos($host, ':') ? strstr($host, ':', true) : $host; @@ -1767,7 +1769,7 @@ class Request */ public function port(): int { - return (int) $this->server('SERVER_PORT', ''); + return (int) ($this->server('HTTP_X_FORWARDED_PORT') ?: $this->server('SERVER_PORT', '')); } /** @@ -2126,4 +2128,22 @@ class Request { return isset($this->middleware[$name]); } + + // ArrayAccess + public function offsetExists($name): bool + { + return $this->has($name); + } + + public function offsetGet($name) + { + return $this->param($name); + } + + public function offsetSet($name, $value) + {} + + public function offsetUnset($name) + {} + } diff --git a/vendor/topthink/framework/src/think/Route.php b/vendor/topthink/framework/src/think/Route.php index 6bf7c808..e3be55da 100644 --- a/vendor/topthink/framework/src/think/Route.php +++ b/vendor/topthink/framework/src/think/Route.php @@ -15,6 +15,7 @@ namespace think; use Closure; use think\exception\RouteNotFoundException; use think\route\Dispatch; +use think\route\dispatch\Callback; use think\route\dispatch\Url as UrlDispatch; use think\route\Domain; use think\route\Resource; @@ -120,7 +121,7 @@ class Route /** * 域名对象 - * @var array + * @var Domain[] */ protected $domains = []; @@ -134,7 +135,7 @@ class Route * 路由是否延迟解析 * @var bool */ - protected $lazy = true; + protected $lazy = false; /** * 路由是否测试模式 @@ -433,7 +434,7 @@ class Route * 批量导入路由标识 * @access public * @param array $name 路由标识 - * @return $this + * @return void */ public function import(array $name): void { @@ -510,6 +511,12 @@ class Route */ public function rule(string $rule, $route = null, string $method = '*'): RuleItem { + if ($route instanceof Response) { + // 兼容之前的路由到响应对象,感觉不需要,使用场景很少,闭包就能实现 + $route = function () use ($route) { + return $route; + }; + } return $this->group->addRule($rule, $route, $method); } @@ -658,7 +665,9 @@ class Route */ public function view(string $rule, string $template = '', array $vars = []): RuleItem { - return $this->rule($rule, $template, 'GET')->view($vars); + return $this->rule($rule, function () use ($vars, $template) { + return Response::create($template, 'view')->assign($vars); + }, 'GET'); } /** @@ -671,7 +680,9 @@ class Route */ public function redirect(string $rule, string $route = '', int $status = 301): RuleItem { - return $this->rule($rule, $route, '*')->redirect()->status($status); + return $this->rule($rule, function () use ($status, $route) { + return Response::create($route, 'redirect')->code($status); + }, '*'); } /** @@ -722,10 +733,10 @@ class Route /** * 路由调度 * @param Request $request - * @param Closure $withRoute + * @param Closure|bool $withRoute * @return Response */ - public function dispatch(Request $request, $withRoute = null) + public function dispatch(Request $request, $withRoute = true) { $this->request = $request; $this->host = $this->request->host(true); @@ -733,7 +744,9 @@ class Route if ($withRoute) { //加载路由 - $withRoute(); + if ($withRoute instanceof Closure) { + $withRoute(); + } $dispatch = $this->check(); } else { $dispatch = $this->url($this->path()); @@ -751,10 +764,10 @@ class Route /** * 检测URL路由 * @access public - * @return Dispatch + * @return Dispatch|false * @throws RouteNotFoundException */ - public function check(): Dispatch + public function check() { // 自动检测域名路由 $url = str_replace($this->config['pathinfo_depr'], '|', $this->path()); @@ -807,8 +820,15 @@ class Route * @param string $url URL地址 * @return Dispatch */ - public function url(string $url): UrlDispatch + public function url(string $url): Dispatch { + if ($this->request->method() == 'OPTIONS') { + // 自动响应options请求 + return new Callback($this->request, $this->group, function () { + return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']); + }); + } + return new UrlDispatch($this->request, $this->group, $url); } diff --git a/vendor/topthink/framework/src/think/Validate.php b/vendor/topthink/framework/src/think/Validate.php index 1b6adbde..42e64e38 100644 --- a/vendor/topthink/framework/src/think/Validate.php +++ b/vendor/topthink/framework/src/think/Validate.php @@ -472,15 +472,15 @@ class Validate { $this->error = []; + if ($this->currentScene) { + $this->getScene($this->currentScene); + } + if (empty($rules)) { // 读取验证规则 $rules = $this->rule; } - if ($this->currentScene) { - $this->getScene($this->currentScene); - } - foreach ($this->append as $key => $rule) { if (!isset($rules[$key])) { $rules[$key] = $rule; @@ -607,6 +607,10 @@ class Validate $rules = array_unique(array_merge($rules, $this->append[$field]), SORT_REGULAR); } + if (empty($rules)) { + return true; + } + $i = 0; foreach ($rules as $key => $rule) { if ($rule instanceof Closure) { @@ -617,7 +621,6 @@ class Validate [$type, $rule, $info] = $this->getValidateType($key, $rule); if (isset($this->append[$field]) && in_array($info, $this->append[$field])) { - } elseif (isset($this->remove[$field]) && in_array($info, $this->remove[$field])) { // 规则已经移除 $i++; @@ -1611,7 +1614,8 @@ class Validate $msg = str_replace( [':attribute', ':1', ':2', ':3'], [$title, $array[0], $array[1], $array[2]], - $msg); + $msg + ); if (strpos($msg, ':rule')) { $msg = str_replace(':rule', (string) $rule, $msg); diff --git a/vendor/topthink/framework/src/think/console/Output.php b/vendor/topthink/framework/src/think/console/Output.php index 13837a7d..294c4b80 100644 --- a/vendor/topthink/framework/src/think/console/Output.php +++ b/vendor/topthink/framework/src/think/console/Output.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2020 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- @@ -42,16 +42,22 @@ use Throwable; */ class Output { + // 不显示信息(静默) const VERBOSITY_QUIET = 0; + // 正常信息 const VERBOSITY_NORMAL = 1; + // 详细信息 const VERBOSITY_VERBOSE = 2; + // 非常详细的信息 const VERBOSITY_VERY_VERBOSE = 3; + // 调试信息 const VERBOSITY_DEBUG = 4; const OUTPUT_NORMAL = 0; const OUTPUT_RAW = 1; const OUTPUT_PLAIN = 2; + // 输出信息级别 private $verbosity = self::VERBOSITY_NORMAL; /** @var Buffer|Console|Nothing */ @@ -162,7 +168,8 @@ class Output } /** - * {@inheritdoc} + * 设置输出信息级别 + * @param int $level 输出信息级别 */ public function setVerbosity(int $level) { @@ -170,7 +177,8 @@ class Output } /** - * {@inheritdoc} + * 获取输出信息级别 + * @return int */ public function getVerbosity(): int { @@ -220,5 +228,4 @@ class Output throw new Exception('method not exists:' . __CLASS__ . '->' . $method); } } - } diff --git a/vendor/topthink/framework/src/think/console/command/Clear.php b/vendor/topthink/framework/src/think/console/command/Clear.php index 81878c59..da70b35d 100644 --- a/vendor/topthink/framework/src/think/console/command/Clear.php +++ b/vendor/topthink/framework/src/think/console/command/Clear.php @@ -25,6 +25,7 @@ class Clear extends Command ->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file') ->addOption('log', 'l', Option::VALUE_NONE, 'clear log file') ->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir') + ->addOption('expire', 'e', Option::VALUE_NONE, 'clear cache file if cache has expired') ->setDescription('Clear runtime file'); } @@ -41,24 +42,44 @@ class Clear extends Command } $rmdir = $input->getOption('dir') ? true : false; - $this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir); + // --expire 仅当 --cache 时生效 + $cache_expire = $input->getOption('expire') && $input->getOption('cache') ? true : false; + $this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir, $cache_expire); $output->writeln("Clear Successed"); } - protected function clear(string $path, bool $rmdir): void + protected function clear(string $path, bool $rmdir, bool $cache_expire): void { $files = is_dir($path) ? scandir($path) : []; foreach ($files as $file) { if ('.' != $file && '..' != $file && is_dir($path . $file)) { - array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*')); + $this->clear($path . $file . DIRECTORY_SEPARATOR, $rmdir, $cache_expire); if ($rmdir) { - rmdir($path . $file); + @rmdir($path . $file); } } elseif ('.gitignore' != $file && is_file($path . $file)) { - unlink($path . $file); + if ($cache_expire) { + if ($this->cacheHasExpired($path . $file)) { + unlink($path . $file); + } + } else { + unlink($path . $file); + } } } } + + /** + * 缓存文件是否已过期 + * @param $filename string 文件路径 + * @return bool + */ + protected function cacheHasExpired($filename) { + $content = file_get_contents($filename); + $expire = (int) substr($content, 8, 12); + return 0 != $expire && time() - $expire > filemtime($filename); + } + } diff --git a/vendor/topthink/framework/src/think/console/command/make/stubs/model.stub b/vendor/topthink/framework/src/think/console/command/make/stubs/model.stub index b2f4571d..bb94a388 100644 --- a/vendor/topthink/framework/src/think/console/command/make/stubs/model.stub +++ b/vendor/topthink/framework/src/think/console/command/make/stubs/model.stub @@ -6,7 +6,7 @@ namespace {%namespace%}; use think\Model; /** - * @mixin think\Model + * @mixin \think\Model */ class {%className%} extends Model { diff --git a/vendor/topthink/framework/src/think/console/command/optimize/Schema.php b/vendor/topthink/framework/src/think/console/command/optimize/Schema.php index 29f0bdb6..e61c2bc6 100644 --- a/vendor/topthink/framework/src/think/console/command/optimize/Schema.php +++ b/vendor/topthink/framework/src/think/console/command/optimize/Schema.php @@ -15,6 +15,7 @@ use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; +use think\db\PDOConnection; class Schema extends Command { @@ -22,7 +23,7 @@ class Schema extends Command { $this->setName('optimize:schema') ->addArgument('dir', Argument::OPTIONAL, 'dir name .') - ->addOption('db', null, Option::VALUE_REQUIRED, 'db name .') + ->addOption('connection', null, Option::VALUE_REQUIRED, 'connection name .') ->addOption('table', null, Option::VALUE_REQUIRED, 'table name .') ->setDescription('Build database schema cache.'); } @@ -31,22 +32,24 @@ class Schema extends Command { $dir = $input->getArgument('dir') ?: ''; - $schemaPath = $this->app->db->getConnection()->getConfig('schema_cache_path'); - - if (!is_dir($schemaPath)) { - mkdir($schemaPath, 0755, true); - } - if ($input->hasOption('table')) { + $connection = $this->app->db->connect($input->getOption('connection')); + if (!$connection instanceof PDOConnection) { + $output->error("only PDO connection support schema cache!"); + return; + } $table = $input->getOption('table'); if (false === strpos($table, '.')) { - $dbName = $this->app->db->getConnection()->getConfig('database'); + $dbName = $connection->getConfig('database'); + } else { + [$dbName, $table] = explode('.', $table); } - $tables[] = $table; - } elseif ($input->hasOption('db')) { - $dbName = $input->getOption('db'); - $tables = $this->app->db->getConnection()->getTables($dbName); + if ($table == '*') { + $table = $connection->getTables($dbName); + } + + $this->buildDataBaseSchema($connection, (array) $table, $dbName); } else { if ($dir) { $appPath = $this->app->getBasePath() . $dir . DIRECTORY_SEPARATOR; @@ -66,14 +69,8 @@ class Schema extends Command $class = '\\' . $namespace . '\\model\\' . pathinfo($file, PATHINFO_FILENAME); $this->buildModelSchema($class); } - - $output->writeln('Succeed!'); - return; } - $db = isset($dbName) ? $dbName . '.' : ''; - $this->buildDataBaseSchema($schemaPath, $tables, $db); - $output->writeln('Succeed!'); } @@ -82,35 +79,21 @@ class Schema extends Command $reflect = new \ReflectionClass($class); if (!$reflect->isAbstract() && $reflect->isSubclassOf('\think\Model')) { /** @var \think\Model $model */ - $model = new $class; - - $table = $model->getTable(); - $dbName = $model->db()->getConnection()->getConfig('database'); - $path = $model->db()->getConnection()->getConfig('schema_cache_path'); - if (!is_dir($path)) { - mkdir($path, 0755, true); + $model = new $class; + $connection = $model->db()->getConnection(); + if ($connection instanceof PDOConnection) { + $table = $model->getTable(); + //预读字段信息 + $connection->getSchemaInfo($table, true); } - $content = 'db()->getConnection()->getTableFieldsInfo($table); - $content .= var_export($info, true) . ';'; - - file_put_contents($path . $dbName . '.' . $table . '.php', $content); } } - protected function buildDataBaseSchema(string $path, array $tables, string $db): void + protected function buildDataBaseSchema(PDOConnection $connection, array $tables, string $dbName): void { - if ('' == $db) { - $dbName = $this->app->db->getConnection()->getConfig('database') . '.'; - } else { - $dbName = $db; - } - foreach ($tables as $table) { - $content = 'app->db->getConnection()->getTableFieldsInfo($db . $table); - $content .= var_export($info, true) . ';'; - file_put_contents($path . $dbName . $table . '.php', $content); + //预读字段信息 + $connection->getSchemaInfo("{$dbName}.{$table}", true); } } } diff --git a/vendor/topthink/framework/src/think/console/output/Descriptor.php b/vendor/topthink/framework/src/think/console/output/Descriptor.php index 8582b595..e4a9e61b 100644 --- a/vendor/topthink/framework/src/think/console/output/Descriptor.php +++ b/vendor/topthink/framework/src/think/console/output/Descriptor.php @@ -216,7 +216,7 @@ class Descriptor $description = new ConsoleDescription($console, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { - $width = $this->getColumnWidth($description->getCommands()); + $width = $this->getColumnWidth($description->getNamespaces()); foreach ($description->getCommands() as $command) { $this->writeText(sprintf("%-${width}s %s", $command->getName(), $command->getDescription()), $options); @@ -235,7 +235,7 @@ class Descriptor $this->writeText("\n"); $this->writeText("\n"); - $width = $this->getColumnWidth($description->getCommands()); + $width = $this->getColumnWidth($description->getNamespaces()); if ($describedNamespace) { $this->writeText(sprintf('Available commands for the "%s" namespace:', $describedNamespace), $options); @@ -282,14 +282,18 @@ class Descriptor } /** - * @param Command[] $commands + * @param Namespaces[] $namespaces * @return int */ - private function getColumnWidth(array $commands) + private function getColumnWidth(array $namespaces) { $width = 0; - foreach ($commands as $command) { - $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; + foreach ($namespaces as $namespace) { + foreach ($namespace['commands'] as $name) { + if (strlen($name) > $width) { + $width = strlen($name); + } + } } return $width + 2; diff --git a/vendor/topthink/framework/src/think/exception/Handle.php b/vendor/topthink/framework/src/think/exception/Handle.php index 9f92054a..8484b6fa 100644 --- a/vendor/topthink/framework/src/think/exception/Handle.php +++ b/vendor/topthink/framework/src/think/exception/Handle.php @@ -77,7 +77,7 @@ class Handle try { $this->app->log->record($log, 'error'); - } catch (Exception $e){} + } catch (Exception $e) {} } } @@ -152,7 +152,7 @@ class Handle { if ($this->app->isDebug()) { // 调试模式,获取详细的错误信息 - $traces = []; + $traces = []; $nextException = $exception; do { $traces[] = [ @@ -171,14 +171,12 @@ class Handle 'traces' => $traces, 'datas' => $this->getExtendData($exception), 'tables' => [ - 'GET Data' => $this->app->request->get(), - 'POST Data' => $this->app->request->post(), - 'Files' => $this->app->request->file(), - 'Cookies' => $this->app->request->cookie(), - 'Session' => $this->app->session->all(), - 'Server/Request Data' => $this->app->request->server(), - 'Environment Variables' => $this->app->request->env(), - 'ThinkPHP Constants' => $this->getConst(), + 'GET Data' => $this->app->request->get(), + 'POST Data' => $this->app->request->post(), + 'Files' => $this->app->request->file(), + 'Cookies' => $this->app->request->cookie(), + 'Session' => $this->app->exists('session') ? $this->app->session->all() : [], + 'Server/Request Data' => $this->app->request->server(), ], ]; } else { diff --git a/vendor/topthink/framework/src/think/facade/App.php b/vendor/topthink/framework/src/think/facade/App.php index 4f64d961..fe3de4da 100644 --- a/vendor/topthink/framework/src/think/facade/App.php +++ b/vendor/topthink/framework/src/think/facade/App.php @@ -18,6 +18,32 @@ use think\Facade; * @see \think\App * @package think\facade * @mixin \think\App + * @method static \think\Service|null register(\think\Service|string $service, bool $force = false) 注册服务 + * @method static mixed bootService(\think\Service $service) 执行服务 + * @method static \think\Service|null getService(string|\think\Service $service) 获取服务 + * @method static \think\App debug(bool $debug = true) 开启应用调试模式 + * @method static bool isDebug() 是否为调试模式 + * @method static \think\App setNamespace(string $namespace) 设置应用命名空间 + * @method static string getNamespace() 获取应用类库命名空间 + * @method static string version() 获取框架版本 + * @method static string getRootPath() 获取应用根目录 + * @method static string getBasePath() 获取应用基础目录 + * @method static string getAppPath() 获取当前应用目录 + * @method static mixed setAppPath(string $path) 设置应用目录 + * @method static string getRuntimePath() 获取应用运行时目录 + * @method static void setRuntimePath(string $path) 设置runtime目录 + * @method static string getThinkPath() 获取核心框架目录 + * @method static string getConfigPath() 获取应用配置目录 + * @method static string getConfigExt() 获取配置后缀 + * @method static float getBeginTime() 获取应用开启时间 + * @method static integer getBeginMem() 获取应用初始内存占用 + * @method static \think\App initialize() 初始化应用 + * @method static bool initialized() 是否初始化过 + * @method static void loadLangPack(string $langset) 加载语言包 + * @method static void boot() 引导应用 + * @method static void loadEvent(array $event) 注册应用事件 + * @method static string parseClass(string $layer, string $name) 解析应用类的类名 + * @method static bool runningInConsole() 是否运行在命令行下 */ class App extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Cache.php b/vendor/topthink/framework/src/think/facade/Cache.php index 62391b73..425b370b 100644 --- a/vendor/topthink/framework/src/think/facade/Cache.php +++ b/vendor/topthink/framework/src/think/facade/Cache.php @@ -13,11 +13,26 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\cache\Driver; +use think\cache\TagSet; /** * @see \think\Cache * @package think\facade * @mixin \think\Cache + * @method static string|null getDefaultDriver() 默认驱动 + * @method static mixed getConfig(null|string $name = null, mixed $default = null) 获取缓存配置 + * @method static array getStoreConfig(string $store, string $name = null, null $default = null) 获取驱动配置 + * @method static Driver store(string $name = null) 连接或者切换缓存 + * @method static bool clear() 清空缓冲池 + * @method static mixed get(string $key, mixed $default = null) 读取缓存 + * @method static bool set(string $key, mixed $value, int|\DateTime $ttl = null) 写入缓存 + * @method static bool delete(string $key) 删除缓存 + * @method static iterable getMultiple(iterable $keys, mixed $default = null) 读取缓存 + * @method static bool setMultiple(iterable $values, null|int|\DateInterval $ttl = null) 写入缓存 + * @method static bool deleteMultiple(iterable $keys) 删除缓存 + * @method static bool has(string $key) 判断缓存是否存在 + * @method static TagSet tag(string|array $name) 缓存标签 */ class Cache extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Config.php b/vendor/topthink/framework/src/think/facade/Config.php index 93916e45..604414af 100644 --- a/vendor/topthink/framework/src/think/facade/Config.php +++ b/vendor/topthink/framework/src/think/facade/Config.php @@ -18,6 +18,10 @@ use think\Facade; * @see \think\Config * @package think\facade * @mixin \think\Config + * @method static array load(string $file, string $name = '') 加载配置文件(多种格式) + * @method static bool has(string $name) 检测配置是否存在 + * @method static mixed get(string $name = null, mixed $default = null) 获取配置参数 为空则获取所有配置 + * @method static array set(array $config, string $name = null) 设置配置参数 name为数组则为批量设置 */ class Config extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Console.php b/vendor/topthink/framework/src/think/facade/Console.php index f3f92394..0d953f2f 100644 --- a/vendor/topthink/framework/src/think/facade/Console.php +++ b/vendor/topthink/framework/src/think/facade/Console.php @@ -13,11 +13,34 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\console\Command; +use think\console\Input; +use think\console\input\Definition as InputDefinition; +use think\console\Output; +use think\console\output\driver\Buffer; /** * Class Console * @package think\facade * @mixin \think\Console + * @method static Output|Buffer call(string $command, array $parameters = [], string $driver = 'buffer') + * @method static int run() 执行当前的指令 + * @method static int doRun(Input $input, Output $output) 执行指令 + * @method static void setDefinition(InputDefinition $definition) 设置输入参数定义 + * @method static InputDefinition The InputDefinition instance getDefinition() 获取输入参数定义 + * @method static string A help message. getHelp() Gets the help message. + * @method static void setCatchExceptions(bool $boolean) 是否捕获异常 + * @method static void setAutoExit(bool $boolean) 是否自动退出 + * @method static string getLongVersion() 获取完整的版本号 + * @method static void addCommands(array $commands) 添加指令集 + * @method static Command|void addCommand(string|Command $command, string $name = '') 添加一个指令 + * @method static Command getCommand(string $name) 获取指令 + * @method static bool hasCommand(string $name) 某个指令是否存在 + * @method static array getNamespaces() 获取所有的命名空间 + * @method static string findNamespace(string $namespace) 查找注册命名空间中的名称或缩写。 + * @method static Command find(string $name) 查找指令 + * @method static Command[] all(string $namespace = null) 获取所有的指令 + * @method static string extractNamespace(string $name, int $limit = 0) 返回命名空间部分 */ class Console extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Cookie.php b/vendor/topthink/framework/src/think/facade/Cookie.php index 98aa6c2d..b2956f83 100644 --- a/vendor/topthink/framework/src/think/facade/Cookie.php +++ b/vendor/topthink/framework/src/think/facade/Cookie.php @@ -18,6 +18,13 @@ use think\Facade; * @see \think\Cookie * @package think\facade * @mixin \think\Cookie + * @method static mixed get(mixed $name = '', string $default = null) 获取cookie + * @method static bool has(string $name) 是否存在Cookie参数 + * @method static void set(string $name, string $value, mixed $option = null) Cookie 设置 + * @method static void forever(string $name, string $value = '', mixed $option = null) 永久保存Cookie数据 + * @method static void delete(string $name) Cookie删除 + * @method static array getCookie() 获取cookie保存数据 + * @method static void save() 保存Cookie */ class Cookie extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Env.php b/vendor/topthink/framework/src/think/facade/Env.php index 5452e908..721881d7 100644 --- a/vendor/topthink/framework/src/think/facade/Env.php +++ b/vendor/topthink/framework/src/think/facade/Env.php @@ -18,6 +18,17 @@ use think\Facade; * @see \think\Env * @package think\facade * @mixin \think\Env + * @method static void load(string $file) 读取环境变量定义文件 + * @method static mixed get(string $name = null, mixed $default = null) 获取环境变量值 + * @method static void set(string|array $env, mixed $value = null) 设置环境变量值 + * @method static bool has(string $name) 检测是否存在环境变量 + * @method static void __set(string $name, mixed $value) 设置环境变量 + * @method static mixed __get(string $name) 获取环境变量 + * @method static bool __isset(string $name) 检测是否存在环境变量 + * @method static void offsetSet($name, $value) + * @method static bool offsetExists($name) + * @method static mixed offsetUnset($name) + * @method static mixed offsetGet($name) */ class Env extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Event.php b/vendor/topthink/framework/src/think/facade/Event.php index 09344526..c65690b1 100644 --- a/vendor/topthink/framework/src/think/facade/Event.php +++ b/vendor/topthink/framework/src/think/facade/Event.php @@ -18,6 +18,15 @@ use think\Facade; * @see \think\Event * @package think\facade * @mixin \think\Event + * @method static \think\Event listenEvents(array $events) 批量注册事件监听 + * @method static \think\Event listen(string $event, mixed $listener, bool $first = false) 注册事件监听 + * @method static bool hasListener(string $event) 是否存在事件监听 + * @method static void remove(string $event) 移除事件监听 + * @method static \think\Event bind(array $events) 指定事件别名标识 便于调用 + * @method static \think\Event subscribe(mixed $subscriber) 注册事件订阅者 + * @method static \think\Event observe(string|object $observer, null|string $prefix = '') 自动注册事件观察者 + * @method static mixed trigger(string|object $event, mixed $params = null, bool $once = false) 触发事件 + * @method static mixed until($event, $params = null) 触发事件(只获取一个有效返回值) */ class Event extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Filesystem.php b/vendor/topthink/framework/src/think/facade/Filesystem.php index 6fe4d5a7..ac0223ae 100644 --- a/vendor/topthink/framework/src/think/facade/Filesystem.php +++ b/vendor/topthink/framework/src/think/facade/Filesystem.php @@ -13,11 +13,16 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\filesystem\Driver; /** * Class Filesystem * @package think\facade * @mixin \think\Filesystem + * @method static Driver disk(string $name = null) ,null|string + * @method static mixed getConfig(null|string $name = null, mixed $default = null) 获取缓存配置 + * @method static array getDiskConfig(string $disk, null $name = null, null $default = null) 获取磁盘配置 + * @method static string|null getDefaultDriver() 默认驱动 */ class Filesystem extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Lang.php b/vendor/topthink/framework/src/think/facade/Lang.php index 1085c159..fa5c6911 100644 --- a/vendor/topthink/framework/src/think/facade/Lang.php +++ b/vendor/topthink/framework/src/think/facade/Lang.php @@ -18,6 +18,14 @@ use think\Facade; * @see \think\Lang * @package think\facade * @mixin \think\Lang + * @method static void setLangSet(string $lang) 设置当前语言 + * @method static string getLangSet() 获取当前语言 + * @method static string defaultLangSet() 获取默认语言 + * @method static array load(string|array $file, string $range = '') 加载语言定义(不区分大小写) + * @method static bool has(string|null $name, string $range = '') 判断是否存在语言定义(不区分大小写) + * @method static mixed get(string|null $name = null, array $vars = [], string $range = '') 获取语言定义(不区分大小写) + * @method static string detect(\think\Request $request) 自动侦测设置获取语言选择 + * @method static void saveToCookie(\think\Cookie $cookie) 保存当前语言到Cookie */ class Lang extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Log.php b/vendor/topthink/framework/src/think/facade/Log.php index e92a5dc6..eaf104d3 100644 --- a/vendor/topthink/framework/src/think/facade/Log.php +++ b/vendor/topthink/framework/src/think/facade/Log.php @@ -13,11 +13,36 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\log\Channel; +use think\log\ChannelSet; /** * @see \think\Log * @package think\facade * @mixin \think\Log + * @method static string|null getDefaultDriver() 默认驱动 + * @method static mixed getConfig(null|string $name = null, mixed $default = null) 获取日志配置 + * @method static array getChannelConfig(string $channel, null $name = null, null $default = null) 获取渠道配置 + * @method static Channel|ChannelSet channel(string|array $name = null) driver() 的别名 + * @method static mixed createDriver(string $name) + * @method static \think\Log clear(string|array $channel = '*') 清空日志信息 + * @method static \think\Log close(string|array $channel = '*') 关闭本次请求日志写入 + * @method static array getLog(string $channel = null) 获取日志信息 + * @method static bool save() 保存日志信息 + * @method static \think\Log record(mixed $msg, string $type = 'info', array $context = [], bool $lazy = true) 记录日志信息 + * @method static \think\Log write(mixed $msg, string $type = 'info', array $context = []) 实时写入日志信息 + * @method static Event listen($listener) 注册日志写入事件监听 + * @method static void log(string $level, mixed $message, array $context = []) 记录日志信息 + * @method static void emergency(mixed $message, array $context = []) 记录emergency信息 + * @method static void alert(mixed $message, array $context = []) 记录警报信息 + * @method static void critical(mixed $message, array $context = []) 记录紧急情况 + * @method static void error(mixed $message, array $context = []) 记录错误信息 + * @method static void warning(mixed $message, array $context = []) 记录warning信息 + * @method static void notice(mixed $message, array $context = []) 记录notice信息 + * @method static void info(mixed $message, array $context = []) 记录一般信息 + * @method static void debug(mixed $message, array $context = []) 记录调试信息 + * @method static void sql(mixed $message, array $context = []) 记录sql信息 + * @method static mixed __call($method, $parameters) */ class Log extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Middleware.php b/vendor/topthink/framework/src/think/facade/Middleware.php index 8a9cc36a..6f1eac59 100644 --- a/vendor/topthink/framework/src/think/facade/Middleware.php +++ b/vendor/topthink/framework/src/think/facade/Middleware.php @@ -18,6 +18,15 @@ use think\Facade; * @see \think\Middleware * @package think\facade * @mixin \think\Middleware + * @method static void import(array $middlewares = [], string $type = 'global') 导入中间件 + * @method static void add(mixed $middleware, string $type = 'global') 注册中间件 + * @method static void route(mixed $middleware) 注册路由中间件 + * @method static void controller(mixed $middleware) 注册控制器中间件 + * @method static mixed unshift(mixed $middleware, string $type = 'global') 注册中间件到开始位置 + * @method static array all(string $type = 'global') 获取注册的中间件 + * @method static Pipeline pipeline(string $type = 'global') 调度管道 + * @method static mixed end(\think\Response $response) 结束调度 + * @method static \think\Response handleException(\think\Request $passable, \Throwable $e) 异常处理 */ class Middleware extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Request.php b/vendor/topthink/framework/src/think/facade/Request.php index 8bf5fc23..7c3b1806 100644 --- a/vendor/topthink/framework/src/think/facade/Request.php +++ b/vendor/topthink/framework/src/think/facade/Request.php @@ -13,11 +13,112 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\file\UploadedFile; +use think\route\Rule; /** * @see \think\Request * @package think\facade * @mixin \think\Request + * @method static \think\Request setDomain(string $domain) 设置当前包含协议的域名 + * @method static string domain(bool $port = false) 获取当前包含协议的域名 + * @method static string rootDomain() 获取当前根域名 + * @method static \think\Request setSubDomain(string $domain) 设置当前泛域名的值 + * @method static string subDomain() 获取当前子域名 + * @method static \think\Request setPanDomain(string $domain) 设置当前泛域名的值 + * @method static string panDomain() 获取当前泛域名的值 + * @method static \think\Request setUrl(string $url) 设置当前完整URL 包括QUERY_STRING + * @method static string url(bool $complete = false) 获取当前完整URL 包括QUERY_STRING + * @method static \think\Request setBaseUrl(string $url) 设置当前URL 不含QUERY_STRING + * @method static string baseUrl(bool $complete = false) 获取当前URL 不含QUERY_STRING + * @method static string baseFile(bool $complete = false) 获取当前执行的文件 SCRIPT_NAME + * @method static \think\Request setRoot(string $url) 设置URL访问根地址 + * @method static string root(bool $complete = false) 获取URL访问根地址 + * @method static string rootUrl() 获取URL访问根目录 + * @method static \think\Request setPathinfo(string $pathinfo) 设置当前请求的pathinfo + * @method static string pathinfo() 获取当前请求URL的pathinfo信息(含URL后缀) + * @method static string ext() 当前URL的访问后缀 + * @method static integer|float time(bool $float = false) 获取当前请求的时间 + * @method static string type() 当前请求的资源类型 + * @method static void mimeType(string|array $type, string $val = '') 设置资源类型 + * @method static \think\Request setMethod(string $method) 设置请求类型 + * @method static string method(bool $origin = false) 当前的请求类型 + * @method static bool isGet() 是否为GET请求 + * @method static bool isPost() 是否为POST请求 + * @method static bool isPut() 是否为PUT请求 + * @method static bool isDelete() 是否为DELTE请求 + * @method static bool isHead() 是否为HEAD请求 + * @method static bool isPatch() 是否为PATCH请求 + * @method static bool isOptions() 是否为OPTIONS请求 + * @method static bool isCli() 是否为cli + * @method static bool isCgi() 是否为cgi + * @method static mixed param(string|array $name = '', mixed $default = null, string|array $filter = '') 获取当前请求的参数 + * @method static \think\Request setRule(Rule $rule) 设置路由变量 + * @method static Rule|null rule() 获取当前路由对象 + * @method static \think\Request setRoute(array $route) 设置路由变量 + * @method static mixed route(string|array $name = '', mixed $default = null, string|array $filter = '') 获取路由参数 + * @method static mixed get(string|array $name = '', mixed $default = null, string|array $filter = '') 获取GET参数 + * @method static mixed middleware(mixed $name, mixed $default = null) 获取中间件传递的参数 + * @method static mixed post(string|array $name = '', mixed $default = null, string|array $filter = '') 获取POST参数 + * @method static mixed put(string|array $name = '', mixed $default = null, string|array $filter = '') 获取PUT参数 + * @method static mixed delete(mixed $name = '', mixed $default = null, string|array $filter = '') 设置获取DELETE参数 + * @method static mixed patch(mixed $name = '', mixed $default = null, string|array $filter = '') 设置获取PATCH参数 + * @method static mixed request(string|array $name = '', mixed $default = null, string|array $filter = '') 获取request变量 + * @method static mixed env(string $name = '', string $default = null) 获取环境变量 + * @method static mixed session(string $name = '', string $default = null) 获取session数据 + * @method static mixed cookie(mixed $name = '', string $default = null, string|array $filter = '') 获取cookie参数 + * @method static mixed server(string $name = '', string $default = '') 获取server参数 + * @method static null|array|UploadedFile file(string $name = '') 获取上传的文件信息 + * @method static string|array header(string $name = '', string $default = null) 设置或者获取当前的Header + * @method static mixed input(array $data = [], string|false $name = '', mixed $default = null, string|array $filter = '') 获取变量 支持过滤和默认值 + * @method static mixed filter(mixed $filter = null) 设置或获取当前的过滤规则 + * @method static mixed filterValue(mixed &$value, mixed $key, array $filters) 递归过滤给定的值 + * @method static bool has(string $name, string $type = 'param', bool $checkEmpty = false) 是否存在某个请求参数 + * @method static array only(array $name, mixed $data = 'param', string|array $filter = '') 获取指定的参数 + * @method static mixed except(array $name, string $type = 'param') 排除指定参数获取 + * @method static bool isSsl() 当前是否ssl + * @method static bool isJson() 当前是否JSON请求 + * @method static bool isAjax(bool $ajax = false) 当前是否Ajax请求 + * @method static bool isPjax(bool $pjax = false) 当前是否Pjax请求 + * @method static string ip() 获取客户端IP地址 + * @method static boolean isValidIP(string $ip, string $type = '') 检测是否是合法的IP地址 + * @method static string ip2bin(string $ip) 将IP地址转换为二进制字符串 + * @method static bool isMobile() 检测是否使用手机访问 + * @method static string scheme() 当前URL地址中的scheme参数 + * @method static string query() 当前请求URL地址中的query参数 + * @method static \think\Request setHost(string $host) 设置当前请求的host(包含端口) + * @method static string host(bool $strict = false) 当前请求的host + * @method static int port() 当前请求URL地址中的port参数 + * @method static string protocol() 当前请求 SERVER_PROTOCOL + * @method static int remotePort() 当前请求 REMOTE_PORT + * @method static string contentType() 当前请求 HTTP_CONTENT_TYPE + * @method static string secureKey() 获取当前请求的安全Key + * @method static \think\Request setController(string $controller) 设置当前的控制器名 + * @method static \think\Request setAction(string $action) 设置当前的操作名 + * @method static string controller(bool $convert = false) 获取当前的控制器名 + * @method static string action(bool $convert = false) 获取当前的操作名 + * @method static string getContent() 设置或者获取当前请求的content + * @method static string getInput() 获取当前请求的php://input + * @method static string buildToken(string $name = '__token__', mixed $type = 'md5') 生成请求令牌 + * @method static bool checkToken(string $token = '__token__', array $data = []) 检查请求令牌 + * @method static \think\Request withMiddleware(array $middleware) 设置在中间件传递的数据 + * @method static \think\Request withGet(array $get) 设置GET数据 + * @method static \think\Request withPost(array $post) 设置POST数据 + * @method static \think\Request withCookie(array $cookie) 设置COOKIE数据 + * @method static \think\Request withSession(Session $session) 设置SESSION数据 + * @method static \think\Request withServer(array $server) 设置SERVER数据 + * @method static \think\Request withHeader(array $header) 设置HEADER数据 + * @method static \think\Request withEnv(Env $env) 设置ENV数据 + * @method static \think\Request withInput(string $input) 设置php://input数据 + * @method static \think\Request withFiles(array $files) 设置文件上传数据 + * @method static \think\Request withRoute(array $route) 设置ROUTE变量 + * @method static mixed __set(string $name, mixed $value) 设置中间传递数据 + * @method static mixed __get(string $name) 获取中间传递数据的值 + * @method static boolean __isset(string $name) 检测中间传递数据的值 + * @method static bool offsetExists($name) + * @method static mixed offsetGet($name) + * @method static mixed offsetSet($name, $value) + * @method static mixed offsetUnset($name) */ class Request extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Route.php b/vendor/topthink/framework/src/think/facade/Route.php index 5fd5e409..24ad3c82 100644 --- a/vendor/topthink/framework/src/think/facade/Route.php +++ b/vendor/topthink/framework/src/think/facade/Route.php @@ -13,11 +13,61 @@ declare (strict_types = 1); namespace think\facade; use think\Facade; +use think\route\Dispatch; +use think\route\Domain; +use think\route\Rule; +use think\route\RuleGroup; +use think\route\RuleItem; +use think\route\RuleName; +use think\route\Url as UrlBuild; /** * @see \think\Route * @package think\facade * @mixin \think\Route + * @method static mixed config(string $name = null) + * @method static \think\Route lazy(bool $lazy = true) 设置路由域名及分组(包括资源路由)是否延迟解析 + * @method static void setTestMode(bool $test) 设置路由为测试模式 + * @method static bool isTest() 检查路由是否为测试模式 + * @method static \think\Route mergeRuleRegex(bool $merge = true) 设置路由域名及分组(包括资源路由)是否合并解析 + * @method static void setGroup(RuleGroup $group) 设置当前分组 + * @method static RuleGroup getGroup(string $name = null) 获取指定标识的路由分组 不指定则获取当前分组 + * @method static \think\Route pattern(array $pattern) 注册变量规则 + * @method static \think\Route option(array $option) 注册路由参数 + * @method static Domain domain(string|array $name, mixed $rule = null) 注册域名路由 + * @method static array getDomains() 获取域名 + * @method static RuleName getRuleName() 获取RuleName对象 + * @method static \think\Route bind(string $bind, string $domain = null) 设置路由绑定 + * @method static array getBind() 读取路由绑定信息 + * @method static string|null getDomainBind(string $domain = null) 读取路由绑定 + * @method static RuleItem[] getName(string $name = null, string $domain = null, string $method = '*') 读取路由标识 + * @method static void import(array $name) 批量导入路由标识 + * @method static void setName(string $name, RuleItem $ruleItem, bool $first = false) 注册路由标识 + * @method static void setRule(string $rule, RuleItem $ruleItem = null) 保存路由规则 + * @method static RuleItem[] getRule(string $rule) 读取路由 + * @method static array getRuleList() 读取路由列表 + * @method static void clear() 清空路由规则 + * @method static RuleItem rule(string $rule, mixed $route = null, string $method = '*') 注册路由规则 + * @method static \think\Route setCrossDomainRule(Rule $rule, string $method = '*') 设置跨域有效路由规则 + * @method static RuleGroup group(string|\Closure $name, mixed $route = null) 注册路由分组 + * @method static RuleItem any(string $rule, mixed $route) 注册路由 + * @method static RuleItem get(string $rule, mixed $route) 注册GET路由 + * @method static RuleItem post(string $rule, mixed $route) 注册POST路由 + * @method static RuleItem put(string $rule, mixed $route) 注册PUT路由 + * @method static RuleItem delete(string $rule, mixed $route) 注册DELETE路由 + * @method static RuleItem patch(string $rule, mixed $route) 注册PATCH路由 + * @method static RuleItem options(string $rule, mixed $route) 注册OPTIONS路由 + * @method static Resource resource(string $rule, string $route) 注册资源路由 + * @method static RuleItem view(string $rule, string $template = '', array $vars = []) 注册视图路由 + * @method static RuleItem redirect(string $rule, string $route = '', int $status = 301) 注册重定向路由 + * @method static \think\Route rest(string|array $name, array|bool $resource = []) rest方法定义和修改 + * @method static array|null getRest(string $name = null) 获取rest方法定义的参数 + * @method static RuleItem miss(string|Closure $route, string $method = '*') 注册未匹配路由规则后的处理 + * @method static Response dispatch(\think\Request $request, Closure|bool $withRoute = true) 路由调度 + * @method static Dispatch|false check() 检测URL路由 + * @method static Dispatch url(string $url) 默认URL解析 + * @method static UrlBuild buildUrl(string $url = '', array $vars = []) URL生成 支持路由反射 + * @method static RuleGroup __call(string $method, array $args) 设置全局的路由分组参数 */ class Route extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Session.php b/vendor/topthink/framework/src/think/facade/Session.php index 4bcb6e80..33cbf630 100644 --- a/vendor/topthink/framework/src/think/facade/Session.php +++ b/vendor/topthink/framework/src/think/facade/Session.php @@ -18,6 +18,8 @@ use think\Facade; * @see \think\Session * @package think\facade * @mixin \think\Session + * @method static mixed getConfig(null|string $name = null, mixed $default = null) 获取Session配置 + * @method static string|null getDefaultDriver() 默认驱动 */ class Session extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/Validate.php b/vendor/topthink/framework/src/think/facade/Validate.php index 0d6a34e2..133116d5 100644 --- a/vendor/topthink/framework/src/think/facade/Validate.php +++ b/vendor/topthink/framework/src/think/facade/Validate.php @@ -18,6 +18,62 @@ use think\Facade; * @see \think\Validate * @package think\facade * @mixin \think\Validate + * @method static void setLang(\think\Lang $lang) 设置Lang对象 + * @method static void setDb(\think\Db $db) 设置Db对象 + * @method static void setRequest(\think\Request $request) 设置Request对象 + * @method static \think\Validate rule(string|array $name, mixed $rule = '') 添加字段验证规则 + * @method static \think\Validate extend(string $type, callable $callback = null, string $message = null) 注册验证(类型)规则 + * @method static void setTypeMsg(string|array $type, string $msg = null) 设置验证规则的默认提示信息 + * @method static Validate message(array $message) 设置提示信息 + * @method static \think\Validate scene(string $name) 设置验证场景 + * @method static bool hasScene(string $name) 判断是否存在某个验证场景 + * @method static \think\Validate batch(bool $batch = true) 设置批量验证 + * @method static \think\Validate failException(bool $fail = true) 设置验证失败后是否抛出异常 + * @method static \think\Validate only(array $fields) 指定需要验证的字段列表 + * @method static \think\Validate remove(string|array $field, mixed $rule = null) 移除某个字段的验证规则 + * @method static \think\Validate append(string|array $field, mixed $rule = null) 追加某个字段的验证规则 + * @method static bool check(array $data, array $rules = []) 数据自动验证 + * @method static bool checkRule(mixed $value, mixed $rules) 根据验证规则验证数据 + * @method static bool confirm(mixed $value, mixed $rule, array $data = [], string $field = '') 验证是否和某个字段的值一致 + * @method static bool different(mixed $value, mixed $rule, array $data = []) 验证是否和某个字段的值是否不同 + * @method static bool egt(mixed $value, mixed $rule, array $data = []) 验证是否大于等于某个值 + * @method static bool gt(mixed $value, mixed $rule, array $data = []) 验证是否大于某个值 + * @method static bool elt(mixed $value, mixed $rule, array $data = []) 验证是否小于等于某个值 + * @method static bool lt(mixed $value, mixed $rule, array $data = []) 验证是否小于某个值 + * @method static bool eq(mixed $value, mixed $rule) 验证是否等于某个值 + * @method static bool must(mixed $value, mixed $rule = null) 必须验证 + * @method static bool is(mixed $value, string $rule, array $data = []) 验证字段值是否为有效格式 + * @method static bool token(mixed $value, mixed $rule, array $data) 验证表单令牌 + * @method static bool activeUrl(mixed $value, mixed $rule = 'MX') 验证是否为合格的域名或者IP 支持A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY类型 + * @method static bool ip(mixed $value, mixed $rule = 'ipv4') 验证是否有效IP + * @method static bool fileExt(mixed $file, mixed $rule) 验证上传文件后缀 + * @method static bool fileMime(mixed $file, mixed $rule) 验证上传文件类型 + * @method static bool fileSize(mixed $file, mixed $rule) 验证上传文件大小 + * @method static bool image(mixed $file, mixed $rule) 验证图片的宽高及类型 + * @method static bool dateFormat(mixed $value, mixed $rule) 验证时间和日期是否符合指定格式 + * @method static bool unique(mixed $value, mixed $rule, array $data = [], string $field = '') 验证是否唯一 + * @method static bool filter(mixed $value, mixed $rule) 使用filter_var方式验证 + * @method static bool requireIf(mixed $value, mixed $rule, array $data = []) 验证某个字段等于某个值的时候必须 + * @method static bool requireCallback(mixed $value, mixed $rule, array $data = []) 通过回调方法验证某个字段是否必须 + * @method static bool requireWith(mixed $value, mixed $rule, array $data = []) 验证某个字段有值的情况下必须 + * @method static bool requireWithout(mixed $value, mixed $rule, array $data = []) 验证某个字段没有值的情况下必须 + * @method static bool in(mixed $value, mixed $rule) 验证是否在范围内 + * @method static bool notIn(mixed $value, mixed $rule) 验证是否不在某个范围 + * @method static bool between(mixed $value, mixed $rule) between验证数据 + * @method static bool notBetween(mixed $value, mixed $rule) 使用notbetween验证数据 + * @method static bool length(mixed $value, mixed $rule) 验证数据长度 + * @method static bool max(mixed $value, mixed $rule) 验证数据最大长度 + * @method static bool min(mixed $value, mixed $rule) 验证数据最小长度 + * @method static bool after(mixed $value, mixed $rule, array $data = []) 验证日期 + * @method static bool before(mixed $value, mixed $rule, array $data = []) 验证日期 + * @method static bool afterWith(mixed $value, mixed $rule, array $data = []) 验证日期 + * @method static bool beforeWith(mixed $value, mixed $rule, array $data = []) 验证日期 + * @method static bool expire(mixed $value, mixed $rule) 验证有效期 + * @method static bool allowIp(mixed $value, mixed $rule) 验证IP许可 + * @method static bool denyIp(mixed $value, mixed $rule) 验证IP禁用 + * @method static bool regex(mixed $value, mixed $rule) 使用正则验证数据 + * @method static array|string getError() 获取错误信息 + * @method static bool __call(string $method, array $args) 动态方法 直接调用is方法进行验证 */ class Validate extends Facade { diff --git a/vendor/topthink/framework/src/think/facade/View.php b/vendor/topthink/framework/src/think/facade/View.php index 0fecb15f..a27463be 100644 --- a/vendor/topthink/framework/src/think/facade/View.php +++ b/vendor/topthink/framework/src/think/facade/View.php @@ -18,6 +18,15 @@ use think\Facade; * @see \think\View * @package think\facade * @mixin \think\View + * @method static \think\View engine(string $type = null) 获取模板引擎 + * @method static \think\View assign(string|array $name, mixed $value = null) 模板变量赋值 + * @method static \think\View filter(\think\Callable $filter = null) 视图过滤 + * @method static string fetch(string $template = '', array $vars = []) 解析和获取模板内容 用于输出 + * @method static string display(string $content, array $vars = []) 渲染内容输出 + * @method static mixed __set(string $name, mixed $value) 模板变量赋值 + * @method static mixed __get(string $name) 取得模板显示变量的值 + * @method static bool __isset(string $name) 检测模板变量是否设置 + * @method static string|null getDefaultDriver() 默认驱动 */ class View extends Facade { diff --git a/vendor/topthink/framework/src/think/file/UploadedFile.php b/vendor/topthink/framework/src/think/file/UploadedFile.php index 7810eac1..66d061e1 100644 --- a/vendor/topthink/framework/src/think/file/UploadedFile.php +++ b/vendor/topthink/framework/src/think/file/UploadedFile.php @@ -60,13 +60,13 @@ class UploadedFile extends File $error = $msg; }); - $moved = move_uploaded_file($this->getPathname(), $target); + $moved = move_uploaded_file($this->getPathname(), (string) $target); restore_error_handler(); if (!$moved) { throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error))); } - @chmod($target, 0666 & ~umask()); + @chmod((string) $target, 0666 & ~umask()); return $target; } diff --git a/vendor/topthink/framework/src/think/log/driver/File.php b/vendor/topthink/framework/src/think/log/driver/File.php index 1b6314da..6f075b95 100644 --- a/vendor/topthink/framework/src/think/log/driver/File.php +++ b/vendor/topthink/framework/src/think/log/driver/File.php @@ -72,7 +72,7 @@ class File implements LogHandlerInterface $info = []; // 日志信息封装 - $time = date($this->config['time_format']); + $time = \DateTime::createFromFormat('0.u00 U', microtime())->setTimezone(new \DateTimeZone(date_default_timezone_get()))->format($this->config['time_format']); foreach ($log as $type => $val) { $message = []; diff --git a/vendor/topthink/framework/src/think/log/driver/Socket.php b/vendor/topthink/framework/src/think/log/driver/Socket.php index fc742588..b78ebfb5 100644 --- a/vendor/topthink/framework/src/think/log/driver/Socket.php +++ b/vendor/topthink/framework/src/think/log/driver/Socket.php @@ -90,14 +90,14 @@ class Socket implements LogHandlerInterface if ($this->config['debug']) { if ($this->app->exists('request')) { - $current_uri = $this->app->request->url(true); + $currentUri = $this->app->request->url(true); } else { - $current_uri = 'cmd:' . implode(' ', $_SERVER['argv'] ?? []); + $currentUri = 'cmd:' . implode(' ', $_SERVER['argv'] ?? []); } if (!empty($this->config['format_head'])) { try { - $current_uri = $this->app->invoke($this->config['format_head'], [$current_uri]); + $currentUri = $this->app->invoke($this->config['format_head'], [$currentUri]); } catch (NotFoundExceptionInterface $notFoundException) { // Ignore exception } @@ -106,16 +106,16 @@ class Socket implements LogHandlerInterface // 基本信息 $trace[] = [ 'type' => 'group', - 'msg' => $current_uri, + 'msg' => $currentUri, 'css' => $this->css['page'], ]; } - $expand_level = array_flip($this->config['expand_level']); + $expandLevel = array_flip($this->config['expand_level']); foreach ($log as $type => $val) { $trace[] = [ - 'type' => isset($expand_level[$type]) ? 'group' : 'groupCollapsed', + 'type' => isset($expandLevel[$type]) ? 'group' : 'groupCollapsed', 'msg' => '[ ' . $type . ' ]', 'css' => $this->css[$type] ?? '', ]; @@ -166,18 +166,18 @@ class Socket implements LogHandlerInterface $tabid = $this->getClientArg('tabid'); - if (!$client_id = $this->getClientArg('client_id')) { - $client_id = ''; + if (!$clientId = $this->getClientArg('client_id')) { + $clientId = ''; } if (!empty($this->allowForceClientIds)) { //强制推送到多个client_id - foreach ($this->allowForceClientIds as $force_client_id) { - $client_id = $force_client_id; - $this->sendToClient($tabid, $client_id, $trace, $force_client_id); + foreach ($this->allowForceClientIds as $forceClientId) { + $clientId = $forceClientId; + $this->sendToClient($tabid, $clientId, $trace, $forceClientId); } } else { - $this->sendToClient($tabid, $client_id, $trace, ''); + $this->sendToClient($tabid, $clientId, $trace, ''); } return true; @@ -188,21 +188,21 @@ class Socket implements LogHandlerInterface * @access protected * @author Zjmainstay * @param $tabid - * @param $client_id + * @param $clientId * @param $logs - * @param $force_client_id + * @param $forceClientId */ - protected function sendToClient($tabid, $client_id, $logs, $force_client_id) + protected function sendToClient($tabid, $clientId, $logs, $forceClientId) { $logs = [ 'tabid' => $tabid, - 'client_id' => $client_id, + 'client_id' => $clientId, 'logs' => $logs, - 'force_client_id' => $force_client_id, + 'force_client_id' => $forceClientId, ]; $msg = json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR); - $address = '/' . $client_id; //将client_id作为地址, server端通过地址判断将日志发布给谁 + $address = '/' . $clientId; //将client_id作为地址, server端通过地址判断将日志发布给谁 $this->send($this->config['host'], $this->config['port'], $msg, $address); } @@ -222,17 +222,17 @@ class Socket implements LogHandlerInterface } //用户认证 - $allow_client_ids = $this->config['allow_client_ids']; + $allowClientIds = $this->config['allow_client_ids']; - if (!empty($allow_client_ids)) { + if (!empty($allowClientIds)) { //通过数组交集得出授权强制推送的client_id - $this->allowForceClientIds = array_intersect($allow_client_ids, $this->config['force_client_ids']); + $this->allowForceClientIds = array_intersect($allowClientIds, $this->config['force_client_ids']); if (!$tabid && count($this->allowForceClientIds)) { return true; } - $client_id = $this->getClientArg('client_id'); - if (!in_array($client_id, $allow_client_ids)) { + $clientId = $this->getClientArg('client_id'); + if (!in_array($clientId, $allowClientIds)) { return false; } } else { diff --git a/vendor/topthink/framework/src/think/middleware/AllowCrossDomain.php b/vendor/topthink/framework/src/think/middleware/AllowCrossDomain.php index 1c1d4c70..68c3ace7 100644 --- a/vendor/topthink/framework/src/think/middleware/AllowCrossDomain.php +++ b/vendor/topthink/framework/src/think/middleware/AllowCrossDomain.php @@ -26,6 +26,7 @@ class AllowCrossDomain protected $header = [ 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Max-Age' => 1800, 'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With', ]; @@ -57,10 +58,6 @@ class AllowCrossDomain } } - if ($request->method(true) == 'OPTIONS') { - return Response::create()->code(204)->header($header); - } - return $next($request)->header($header); } } diff --git a/vendor/topthink/framework/src/think/response/File.php b/vendor/topthink/framework/src/think/response/File.php index ce000ab7..45d7196c 100644 --- a/vendor/topthink/framework/src/think/response/File.php +++ b/vendor/topthink/framework/src/think/response/File.php @@ -24,6 +24,7 @@ class File extends Response protected $name; protected $mimeType; protected $isContent = false; + protected $force = true; public function __construct($data = '', int $code = 200) { @@ -62,7 +63,7 @@ class File extends Response $this->header['Pragma'] = 'public'; $this->header['Content-Type'] = $mimeType ?: 'application/octet-stream'; $this->header['Cache-control'] = 'max-age=' . $this->expire; - $this->header['Content-Disposition'] = 'attachment; filename="' . $name . '"'; + $this->header['Content-Disposition'] = ($this->force ? 'attachment; ' : '') . 'filename="' . $name . '"'; $this->header['Content-Length'] = $size; $this->header['Content-Transfer-Encoding'] = 'binary'; $this->header['Expires'] = gmdate("D, d M Y H:i:s", time() + $this->expire) . ' GMT'; @@ -108,6 +109,18 @@ class File extends Response return $this; } + /** + * 设置文件强制下载 + * @access public + * @param bool $force 强制浏览器下载 + * @return $this + */ + public function force(bool $force) + { + $this->force = $force; + return $this; + } + /** * 获取文件类型信息 * @access public diff --git a/vendor/topthink/framework/src/think/response/Jsonp.php b/vendor/topthink/framework/src/think/response/Jsonp.php index a098d4c7..35f26f2c 100644 --- a/vendor/topthink/framework/src/think/response/Jsonp.php +++ b/vendor/topthink/framework/src/think/response/Jsonp.php @@ -51,8 +51,8 @@ class Jsonp extends Response { try { // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取] - $var_jsonp_handler = $this->request->param($this->options['var_jsonp_handler'], ""); - $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler']; + $varJsonpHandler = $this->request->param($this->options['var_jsonp_handler'], ""); + $handler = !empty($varJsonpHandler) ? $varJsonpHandler : $this->options['default_jsonp_handler']; $data = json_encode($data, $this->options['json_encode_param']); diff --git a/vendor/topthink/framework/src/think/route/Dispatch.php b/vendor/topthink/framework/src/think/route/Dispatch.php index dc39fd10..9884a476 100644 --- a/vendor/topthink/framework/src/think/route/Dispatch.php +++ b/vendor/topthink/framework/src/think/route/Dispatch.php @@ -53,19 +53,12 @@ abstract class Dispatch */ protected $param; - /** - * 状态码 - * @var int - */ - protected $code; - - public function __construct(Request $request, Rule $rule, $dispatch, array $param = [], int $code = null) + public function __construct(Request $request, Rule $rule, $dispatch, array $param = []) { $this->request = $request; $this->rule = $rule; $this->dispatch = $dispatch; $this->param = $param; - $this->code = $code; } public function init(App $app) @@ -244,7 +237,7 @@ abstract class Dispatch public function __sleep() { - return ['rule', 'dispatch', 'param', 'code', 'controller', 'actionName']; + return ['rule', 'dispatch', 'param', 'controller', 'actionName']; } public function __wakeup() @@ -258,7 +251,6 @@ abstract class Dispatch return [ 'dispatch' => $this->dispatch, 'param' => $this->param, - 'code' => $this->code, 'rule' => $this->rule, ]; } diff --git a/vendor/topthink/framework/src/think/route/Rule.php b/vendor/topthink/framework/src/think/route/Rule.php index b0ef3f59..05213934 100644 --- a/vendor/topthink/framework/src/think/route/Rule.php +++ b/vendor/topthink/framework/src/think/route/Rule.php @@ -18,13 +18,9 @@ use think\middleware\AllowCrossDomain; use think\middleware\CheckRequestCache; use think\middleware\FormTokenCheck; use think\Request; -use think\Response; use think\Route; use think\route\dispatch\Callback as CallbackDispatch; use think\route\dispatch\Controller as ControllerDispatch; -use think\route\dispatch\Redirect as RedirectDispatch; -use think\route\dispatch\Response as ResponseDispatch; -use think\route\dispatch\View as ViewDispatch; /** * 路由规则基础类 @@ -505,38 +501,16 @@ abstract class Rule } /** - * 当前路由到一个模板地址 当使用数组的时候可以传入模板变量 + * 路由到一个模板地址 需要额外传入的模板变量 * @access public - * @param bool|array $view 视图 + * @param array $view 视图 * @return $this */ - public function view($view = true) + public function view(array $view = []) { return $this->setOption('view', $view); } - /** - * 当前路由为重定向 - * @access public - * @param bool $redirect 是否为重定向 - * @return $this - */ - public function redirect(bool $redirect = true) - { - return $this->setOption('redirect', $redirect); - } - - /** - * 设置status - * @access public - * @param int $status 状态码 - * @return $this - */ - public function status(int $status) - { - return $this->setOption('status', $status); - } - /** * 设置路由完整匹配 * @access public @@ -651,20 +625,14 @@ abstract class Rule */ protected function dispatch(Request $request, $route, array $option): Dispatch { - if ($route instanceof Dispatch) { - $result = $route; + if (is_subclass_of($route, Dispatch::class)) { + $result = new $route($request, $this, $route, $this->vars); } elseif ($route instanceof Closure) { // 执行闭包 $result = new CallbackDispatch($request, $this, $route, $this->vars); - } elseif ($route instanceof Response) { - $result = new ResponseDispatch($request, $this, $route); - } elseif (isset($option['view']) && false !== $option['view']) { - $result = new ViewDispatch($request, $this, $route, is_array($option['view']) ? $option['view'] : $this->vars); - } elseif (!empty($option['redirect'])) { - // 路由到重定向地址 - $result = new RedirectDispatch($request, $this, $route, $this->vars, $option['status'] ?? 301); - } elseif (false !== strpos($route, '\\')) { + } elseif (false !== strpos($route, '@') || false !== strpos($route, '::')) { // 路由到类的方法 + $route = str_replace('::', '@', $route); $result = $this->dispatchMethod($request, $route); } else { // 路由到控制器/操作 diff --git a/vendor/topthink/framework/src/think/route/RuleGroup.php b/vendor/topthink/framework/src/think/route/RuleGroup.php index 5bfff9b3..3d5e9bc8 100644 --- a/vendor/topthink/framework/src/think/route/RuleGroup.php +++ b/vendor/topthink/framework/src/think/route/RuleGroup.php @@ -16,9 +16,7 @@ use Closure; use think\Container; use think\Exception; use think\Request; -use think\Response; use think\Route; -use think\route\dispatch\Response as ResponseDispatch; /** * 路由分组类 @@ -29,16 +27,7 @@ class RuleGroup extends Rule * 分组路由(包括子分组) * @var array */ - protected $rules = [ - '*' => [], - 'get' => [], - 'post' => [], - 'put' => [], - 'patch' => [], - 'delete' => [], - 'head' => [], - 'options' => [], - ]; + protected $rules = []; /** * 分组路由规则 @@ -151,15 +140,13 @@ class RuleGroup extends Rule // 解析分组路由 if ($this instanceof Resource) { $this->buildResourceRule(); - } elseif ($this->rule instanceof Response) { - return new ResponseDispatch($request, $this, $this->rule); } else { $this->parseGroupRule($this->rule); } // 获取当前路由规则 $method = strtolower($request->method()); - $rules = $this->getMethodRules($method); + $rules = $this->getRules($method); if ($this->parent) { // 合并分组参数 @@ -183,7 +170,7 @@ class RuleGroup extends Rule // 检查分组路由 foreach ($rules as $key => $item) { - $result = $item->check($request, $url, $completeMatch); + $result = $item[1]->check($request, $url, $completeMatch); if (false !== $result) { return $result; @@ -200,17 +187,6 @@ class RuleGroup extends Rule return $result; } - /** - * 获取当前请求的路由规则(包括子分组、资源路由) - * @access protected - * @param string $method 请求类型 - * @return array - */ - protected function getMethodRules(string $method): array - { - return array_merge($this->rules[$method], $this->rules['*']); - } - /** * 分组URL匹配检查 * @access protected @@ -302,7 +278,8 @@ class RuleGroup extends Rule $regex = []; $items = []; - foreach ($rules as $key => $item) { + foreach ($rules as $key => $val) { + $item = $val[1]; if ($item instanceof RuleItem) { $rule = $depr . str_replace('/', $depr, $item->getRule()); if ($depr == $rule && $depr != $url) { @@ -460,10 +437,10 @@ class RuleGroup extends Rule $method = '*'; } - $this->rules[$method][] = $rule; + $this->rules[] = [$method, $rule]; if ($rule instanceof RuleItem && 'options' != $method) { - $this->rules['options'][] = $rule->setAutoOptions(); + $this->rules[] = ['options', $rule->setAutoOptions()]; } return $this; @@ -517,7 +494,9 @@ class RuleGroup extends Rule return $this->rules; } - return $this->rules[strtolower($method)] ?? []; + return array_filter($this->rules, function ($item) use ($method) { + return $method == $item[0] || $item[0] == '*'; + }); } /** @@ -527,15 +506,6 @@ class RuleGroup extends Rule */ public function clear(): void { - $this->rules = [ - '*' => [], - 'get' => [], - 'post' => [], - 'put' => [], - 'patch' => [], - 'delete' => [], - 'head' => [], - 'options' => [], - ]; + $this->rules = []; } } diff --git a/vendor/topthink/framework/src/think/route/Url.php b/vendor/topthink/framework/src/think/route/Url.php index d9ecfd82..d0d808b2 100644 --- a/vendor/topthink/framework/src/think/route/Url.php +++ b/vendor/topthink/framework/src/think/route/Url.php @@ -164,9 +164,9 @@ class Url $domains = $this->route->getDomains(); if (!empty($domains)) { - $route_domain = array_keys($domains); - foreach ($route_domain as $domain_prefix) { - if (0 === strpos($domain_prefix, '*.') && strpos($domain, ltrim($domain_prefix, '*.')) !== false) { + $routeDomain = array_keys($domains); + foreach ($routeDomain as $domainPrefix) { + if (0 === strpos($domainPrefix, '*.') && strpos($domain, ltrim($domainPrefix, '*.')) !== false) { foreach ($domains as $key => $rule) { $rule = is_array($rule) ? $rule[0] : $rule; if (is_string($rule) && false === strpos($key, '*') && 0 === strpos($url, $rule)) { diff --git a/vendor/topthink/framework/src/think/route/dispatch/Controller.php b/vendor/topthink/framework/src/think/route/dispatch/Controller.php index 88094c6e..9182dec2 100644 --- a/vendor/topthink/framework/src/think/route/dispatch/Controller.php +++ b/vendor/topthink/framework/src/think/route/dispatch/Controller.php @@ -145,7 +145,10 @@ class Controller extends Dispatch } if (is_string($val) && strpos($val, ':')) { - $val = explode(':', $val, 2); + $val = explode(':', $val); + if (count($val) > 1) { + $val = [$val[0], array_slice($val, 1)]; + } } $this->app->middleware->controller($val); diff --git a/vendor/topthink/framework/src/think/route/dispatch/Redirect.php b/vendor/topthink/framework/src/think/route/dispatch/Redirect.php deleted file mode 100644 index 1ec9ed97..00000000 --- a/vendor/topthink/framework/src/think/route/dispatch/Redirect.php +++ /dev/null @@ -1,27 +0,0 @@ - -// +---------------------------------------------------------------------- -declare (strict_types = 1); - -namespace think\route\dispatch; - -use think\Response; -use think\route\Dispatch; - -/** - * Redirect Dispatcher - */ -class Redirect extends Dispatch -{ - public function exec() - { - return Response::create($this->dispatch, 'redirect')->code($this->code); - } -} diff --git a/vendor/topthink/framework/src/think/route/dispatch/Response.php b/vendor/topthink/framework/src/think/route/dispatch/Response.php deleted file mode 100644 index 3ae4c0a2..00000000 --- a/vendor/topthink/framework/src/think/route/dispatch/Response.php +++ /dev/null @@ -1,27 +0,0 @@ - -// +---------------------------------------------------------------------- -declare (strict_types = 1); - -namespace think\route\dispatch; - -use think\route\Dispatch; - -/** - * Response Dispatcher - */ -class Response extends Dispatch -{ - public function exec() - { - return $this->dispatch; - } - -} diff --git a/vendor/topthink/framework/src/think/route/dispatch/Url.php b/vendor/topthink/framework/src/think/route/dispatch/Url.php index da6d6558..eb89f541 100644 --- a/vendor/topthink/framework/src/think/route/dispatch/Url.php +++ b/vendor/topthink/framework/src/think/route/dispatch/Url.php @@ -23,14 +23,14 @@ use think\route\Rule; class Url extends Controller { - public function __construct(Request $request, Rule $rule, $dispatch, array $param = [], int $code = null) + public function __construct(Request $request, Rule $rule, $dispatch) { $this->request = $request; $this->rule = $rule; // 解析默认的URL规则 $dispatch = $this->parseUrl($dispatch); - parent::__construct($request, $rule, $dispatch, $this->param, $code); + parent::__construct($request, $rule, $dispatch, $this->param); } /** diff --git a/vendor/topthink/framework/src/think/route/dispatch/View.php b/vendor/topthink/framework/src/think/route/dispatch/View.php deleted file mode 100644 index 94f90476..00000000 --- a/vendor/topthink/framework/src/think/route/dispatch/View.php +++ /dev/null @@ -1,28 +0,0 @@ - -// +---------------------------------------------------------------------- -declare (strict_types = 1); - -namespace think\route\dispatch; - -use think\Response; -use think\route\Dispatch; - -/** - * View Dispatcher - */ -class View extends Dispatch -{ - public function exec() - { - // 渲染模板输出 - return Response::create($this->dispatch, 'view')->assign($this->param); - } -} diff --git a/vendor/topthink/framework/tests/DbTest.php b/vendor/topthink/framework/tests/DbTest.php index cffdc845..3bd0c1e9 100644 --- a/vendor/topthink/framework/tests/DbTest.php +++ b/vendor/topthink/framework/tests/DbTest.php @@ -5,6 +5,7 @@ namespace think\tests; use Mockery as m; use PHPUnit\Framework\TestCase; use think\Cache; +use think\cache\Driver; use think\Config; use think\Db; use think\Event; @@ -23,6 +24,10 @@ class DbTest extends TestCase $config = m::mock(Config::class); $log = m::mock(Log::class); $cache = m::mock(Cache::class); + $store = m::mock(Driver::class); + + $config->shouldReceive('get')->with('database.cache_store', null)->andReturn(null); + $cache->shouldReceive('store')->with(null)->andReturn($store); $db = Db::__make($event, $config, $log, $cache); diff --git a/vendor/topthink/framework/tests/EventTest.php b/vendor/topthink/framework/tests/EventTest.php index 707a35b5..ded5a36d 100644 --- a/vendor/topthink/framework/tests/EventTest.php +++ b/vendor/topthink/framework/tests/EventTest.php @@ -108,15 +108,6 @@ class EventTest extends TestCase $this->event->trigger('bar'); } - public function testWithoutEvent() - { - $this->event->withEvent(false); - - $this->event->listen('SomeListener', TestListener::class); - - $this->assertFalse($this->event->hasListener('SomeListener')); - } - } class TestListener diff --git a/vendor/topthink/framework/tests/InteractsWithApp.php b/vendor/topthink/framework/tests/InteractsWithApp.php new file mode 100644 index 00000000..f4fcf73f --- /dev/null +++ b/vendor/topthink/framework/tests/InteractsWithApp.php @@ -0,0 +1,30 @@ +app = m::mock(App::class)->makePartial(); + Container::setInstance($this->app); + $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app); + $this->app->shouldReceive('isDebug')->andReturnTrue(); + $this->config = m::mock(Config::class)->makePartial(); + $this->config->shouldReceive('get')->with('app.show_error_msg')->andReturnTrue(); + $this->app->shouldReceive('get')->with('config')->andReturn($this->config); + $this->app->shouldReceive('runningInConsole')->andReturn(false); + } +} diff --git a/vendor/topthink/framework/tests/LogTest.php b/vendor/topthink/framework/tests/LogTest.php index 269306f4..981110f5 100644 --- a/vendor/topthink/framework/tests/LogTest.php +++ b/vendor/topthink/framework/tests/LogTest.php @@ -7,23 +7,16 @@ use Mockery as m; use Mockery\MockInterface; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; -use think\App; -use think\Config; -use think\Container; use think\Log; use think\log\ChannelSet; class LogTest extends TestCase { - /** @var App|MockInterface */ - protected $app; + use InteractsWithApp; /** @var Log|MockInterface */ protected $log; - /** @var Config|MockInterface */ - protected $config; - protected function tearDown(): void { m::close(); @@ -31,13 +24,7 @@ class LogTest extends TestCase protected function setUp() { - $this->app = m::mock(App::class)->makePartial(); - Container::setInstance($this->app); - - $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app); - $this->config = m::mock(Config::class)->makePartial(); - $this->app->shouldReceive('get')->with('config')->andReturn($this->config); - $this->app->shouldReceive('runningInConsole')->andReturn(false); + $this->prepareApp(); $this->log = new Log($this->app); } diff --git a/vendor/topthink/framework/tests/MiddlewareTest.php b/vendor/topthink/framework/tests/MiddlewareTest.php index bbd092d4..aa53059c 100644 --- a/vendor/topthink/framework/tests/MiddlewareTest.php +++ b/vendor/topthink/framework/tests/MiddlewareTest.php @@ -5,9 +5,6 @@ namespace think\tests; use Mockery as m; use Mockery\MockInterface; use PHPUnit\Framework\TestCase; -use think\App; -use think\Config; -use think\Container; use think\Exception; use think\exception\Handle; use think\Middleware; @@ -17,15 +14,11 @@ use think\Response; class MiddlewareTest extends TestCase { - /** @var App|MockInterface */ - protected $app; + use InteractsWithApp; /** @var Middleware|MockInterface */ protected $middleware; - /** @var Config|MockInterface */ - protected $config; - protected function tearDown(): void { m::close(); @@ -33,13 +26,7 @@ class MiddlewareTest extends TestCase protected function setUp() { - $this->app = m::mock(App::class)->makePartial(); - Container::setInstance($this->app); - - $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app); - $this->config = m::mock(Config::class)->makePartial(); - $this->app->shouldReceive('get')->with('config')->andReturn($this->config); - $this->app->shouldReceive('runningInConsole')->andReturn(false); + $this->prepareApp(); $this->middleware = new Middleware($this->app); } diff --git a/vendor/topthink/framework/tests/RouteTest.php b/vendor/topthink/framework/tests/RouteTest.php new file mode 100644 index 00000000..e587131b --- /dev/null +++ b/vendor/topthink/framework/tests/RouteTest.php @@ -0,0 +1,285 @@ +prepareApp(); + $this->route = new Route($this->app); + } + + /** + * @param $path + * @param string $method + * @param string $host + * @return m\Mock|Request + */ + protected function makeRequest($path, $method = 'GET', $host = 'localhost') + { + $request = m::mock(Request::class)->makePartial(); + $request->shouldReceive('host')->andReturn($host); + $request->shouldReceive('pathinfo')->andReturn($path); + $request->shouldReceive('url')->andReturn('/' . $path); + $request->shouldReceive('method')->andReturn(strtoupper($method)); + return $request; + } + + public function testSimpleRequest() + { + $this->route->get('foo', function () { + return 'get-foo'; + }); + + $this->route->put('foo', function () { + return 'put-foo'; + }); + + $this->route->group(function () { + $this->route->post('foo', function () { + return 'post-foo'; + }); + }); + + $request = $this->makeRequest('foo', 'post'); + $response = $this->route->dispatch($request); + $this->assertEquals(200, $response->getCode()); + $this->assertEquals('post-foo', $response->getContent()); + + $request = $this->makeRequest('foo', 'get'); + $response = $this->route->dispatch($request); + $this->assertEquals(200, $response->getCode()); + $this->assertEquals('get-foo', $response->getContent()); + } + + public function testOptionsRequest() + { + $this->route->get('foo', function () { + return 'get-foo'; + }); + + $this->route->put('foo', function () { + return 'put-foo'; + }); + + $this->route->group(function () { + $this->route->post('foo', function () { + return 'post-foo'; + }); + }); + $this->route->group('abc', function () { + $this->route->post('foo/:id', function () { + return 'post-abc-foo'; + }); + }); + + $this->route->post('foo/:id', function () { + return 'post-abc-foo'; + }); + + $this->route->resource('bar', 'SomeClass'); + + $request = $this->makeRequest('foo', 'options'); + $response = $this->route->dispatch($request); + $this->assertEquals(204, $response->getCode()); + $this->assertEquals('GET, PUT, POST', $response->getHeader('Allow')); + + $request = $this->makeRequest('bar', 'options'); + $response = $this->route->dispatch($request); + $this->assertEquals(204, $response->getCode()); + $this->assertEquals('GET, POST', $response->getHeader('Allow')); + + $request = $this->makeRequest('bar/1', 'options'); + $response = $this->route->dispatch($request); + $this->assertEquals(204, $response->getCode()); + $this->assertEquals('GET, PUT, DELETE', $response->getHeader('Allow')); + + $request = $this->makeRequest('xxxx', 'options'); + $response = $this->route->dispatch($request); + $this->assertEquals(204, $response->getCode()); + $this->assertEquals('GET, POST, PUT, DELETE', $response->getHeader('Allow')); + } + + public function testAllowCrossDomain() + { + $this->route->get('foo', function () { + return 'get-foo'; + })->allowCrossDomain(['some' => 'bar']); + + $request = $this->makeRequest('foo', 'get'); + $response = $this->route->dispatch($request); + + $this->assertEquals('bar', $response->getHeader('some')); + $this->assertArrayHasKey('Access-Control-Allow-Credentials', $response->getHeader()); + + $request = $this->makeRequest('foo2', 'options'); + $response = $this->route->dispatch($request); + + $this->assertEquals(204, $response->getCode()); + $this->assertArrayHasKey('Access-Control-Allow-Credentials', $response->getHeader()); + $this->assertEquals('GET, POST, PUT, DELETE', $response->getHeader('Allow')); + } + + public function testControllerDispatch() + { + $this->route->get('foo', 'foo/bar'); + + $controller = m::Mock(\stdClass::class); + + $this->app->shouldReceive('parseClass')->with('controller', 'Foo')->andReturn($controller->mockery_getName()); + $this->app->shouldReceive('make')->with($controller->mockery_getName(), [], true)->andReturn($controller); + + $controller->shouldReceive('bar')->andReturn('bar'); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + $this->assertEquals('bar', $response->getContent()); + } + + public function testEmptyControllerDispatch() + { + $this->route->get('foo', 'foo/bar'); + + $controller = m::Mock(\stdClass::class); + + $this->app->shouldReceive('parseClass')->with('controller', 'Error')->andReturn($controller->mockery_getName()); + $this->app->shouldReceive('make')->with($controller->mockery_getName(), [], true)->andReturn($controller); + + $controller->shouldReceive('bar')->andReturn('bar'); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + $this->assertEquals('bar', $response->getContent()); + } + + protected function createMiddleware($times = 1) + { + $middleware = m::mock(Str::random(5)); + $middleware->shouldReceive('handle')->times($times)->andReturnUsing(function ($request, Closure $next) { + return $next($request); + }); + $this->app->shouldReceive('make')->with($middleware->mockery_getName())->andReturn($middleware); + + return $middleware; + } + + public function testControllerWithMiddleware() + { + $this->route->get('foo', 'foo/bar'); + + $controller = m::mock(FooClass::class); + + $controller->middleware = [ + $this->createMiddleware()->mockery_getName() . ":params1:params2", + $this->createMiddleware(0)->mockery_getName() => ['except' => 'bar'], + $this->createMiddleware()->mockery_getName() => ['only' => 'bar'], + ]; + + $this->app->shouldReceive('parseClass')->with('controller', 'Foo')->andReturn($controller->mockery_getName()); + $this->app->shouldReceive('make')->with($controller->mockery_getName(), [], true)->andReturn($controller); + + $controller->shouldReceive('bar')->once()->andReturn('bar'); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + $this->assertEquals('bar', $response->getContent()); + } + + public function testUrlDispatch() + { + $controller = m::mock(FooClass::class); + $controller->shouldReceive('index')->andReturn('bar'); + + $this->app->shouldReceive('parseClass')->once()->with('controller', 'Foo')->andReturn($controller->mockery_getName()); + $this->app->shouldReceive('make')->with($controller->mockery_getName(), [], true)->andReturn($controller); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + $this->assertEquals('bar', $response->getContent()); + } + + public function testRedirectDispatch() + { + $this->route->redirect('foo', 'http://localhost', 302); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + + $this->assertInstanceOf(Redirect::class, $response); + $this->assertEquals(302, $response->getCode()); + $this->assertEquals('http://localhost', $response->getData()); + } + + public function testViewDispatch() + { + $this->route->view('foo', 'index/hello', ['city' => 'shanghai']); + + $request = $this->makeRequest('foo'); + $response = $this->route->dispatch($request); + + $this->assertInstanceOf(View::class, $response); + $this->assertEquals(['city' => 'shanghai'], $response->getVars()); + $this->assertEquals('index/hello', $response->getData()); + } + + public function testResponseDispatch() + { + $this->route->get('hello/:name', response() + ->data('Hello,ThinkPHP') + ->code(200) + ->contentType('text/plain')); + + $request = $this->makeRequest('hello/some'); + $response = $this->route->dispatch($request); + + $this->assertEquals('Hello,ThinkPHP', $response->getContent()); + $this->assertEquals(200, $response->getCode()); + } + + public function testDomainBindResponse() + { + $this->route->domain('test', function () { + $this->route->get('/', function () { + return 'Hello,ThinkPHP'; + }); + }); + + $request = $this->makeRequest('', 'get', 'test.domain.com'); + $response = $this->route->dispatch($request); + + $this->assertEquals('Hello,ThinkPHP', $response->getContent()); + $this->assertEquals(200, $response->getCode()); + } + +} + +class FooClass +{ + public $middleware = []; + + public function bar() + { + + } +} diff --git a/vendor/topthink/framework/tests/bootstrap.php b/vendor/topthink/framework/tests/bootstrap.php index 991ea439..34590612 100644 --- a/vendor/topthink/framework/tests/bootstrap.php +++ b/vendor/topthink/framework/tests/bootstrap.php @@ -1,3 +1,3 @@
学科 得分得分率班级位置
{$vo.title} {$vo.defen}{$vo.defenlv}{$vo.bweizhi}