diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php
index 2f771fbf..a891d58b 100644
--- a/application/chengji/controller/Index.php
+++ b/application/chengji/controller/Index.php
@@ -240,7 +240,9 @@ class Index extends Base
$njlist = nianjiList();
$njnum = array_keys($njlist);
$bj = new \app\teach\model\Banji;
- $bjlist = $bj->where('ruxuenian','in',$njnum)->where('paixu','in',$getdt['banji'])->column('id');
+ $bjlist = $bj->where('ruxuenian','in',$njnum)
+ ->where('paixu','in',$getdt['banji'])
+ ->column('id');
//得到搜索的关键词
@@ -366,12 +368,77 @@ class Index extends Base
// 下载成绩表格
public function download($id)
{
- $list = request()->get();
- dump($list);
-
- dump($id);
+ // 模板赋值
+ $this->assign('id',$id);
+ // 渲染模板
+ return $this->fetch();
}
+
+ //生成学生表格
+ public function chengjixls()
+ {
+ set_time_limit(0);
+ $list = input();
+ $id = $list['id'];
+ // 获取数据库信息
+ $chengjiinfo = Chengji::where('kaoshi',$id)
+ ->where('banji','in',$list['banjiids'])
+ ->order(['ruxuenian','stuAvg'=>'desc'])
+ ->append(['cj_student.xingming','cj_banji.title'])
+ ->select();
+
+ // 获取考试标题
+ $ks = Kaoshi::where('id',$id)->find('title');
+
+
+ // 创建表格
+ $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet;
+ $sheet = $spreadsheet->getActiveSheet();
+
+ // 设置表头信息
+ $sheet->setCellValue('A1', $ks.'学生成绩列表');
+ $sheet->setCellValue('A2', '序号');
+ $sheet->setCellValue('B2', '班级');
+ $sheet->setCellValue('C2', '姓名');
+ $sheet->setCellValue('D2', '语文');
+ $sheet->setCellValue('E2', '数学');
+ $sheet->setCellValue('F2', '英语');
+ $sheet->setCellValue('G2', '平均分');
+ $sheet->setCellValue('H2', '总分');
+
+
+ // 循环写出信息
+ $i = 3;
+ foreach ($chengjiinfo as $key => $value) {
+ if($value->stuSum !== null)
+ {
+ // 表格赋值
+ $sheet->setCellValue('A'.$i, $i-2);
+ $sheet->setCellValue('B'.$i, $value['cj_banji']['title']);
+ $sheet->setCellValue('C'.$i, $value['cj_student']['xingming']);
+ $sheet->setCellValue('D'.$i, $value->yuwen);
+ $sheet->setCellValue('E'.$i, $value->shuxue);
+ $sheet->setCellValue('F'.$i, $value->waiyu);
+ $sheet->setCellValue('G'.$i, $value->stuAvg);
+ $sheet->setCellValue('H'.$i, $value->stuSum);
+ $i++;
+ }
+ }
+
+
+ // 保存文件
+ $filename = $ks.'学生成绩列表'.date('ymdHis').'.xls';
+ header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+ header('Content-Disposition: attachment;filename="' . $filename . '"');
+ header('Cache-Control: max-age=0');
+ $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
+ $writer->save('php://output');
+ ob_flush();
+ flush();
+ }
+
+
}
diff --git a/application/chengji/model/Chengji.php b/application/chengji/model/Chengji.php
index e6ce1eb2..77f73e48 100644
--- a/application/chengji/model/Chengji.php
+++ b/application/chengji/model/Chengji.php
@@ -106,7 +106,6 @@ class Chengji extends Base
$search = $search['search'];
-
$data = $this->scope('kaoshi',$kaoshiid)
->when(!empty($schoolid),function($query) use($schoolid){
$query->where('school','in',$schoolid);
@@ -117,9 +116,15 @@ class Chengji extends Base
->when(!empty($banji),function($query) use($banji){
$query->where('banji','in',$banji);
})
- ->when(!empty($searc),function($query) use($search){
- $query->where('student','in',function ($q) use($search){
- $q->name('student')->where('xingming','like','%'.$search.'%')->field('id');
+ ->when(!empty($search) && is_numeric($search), function ($query) use($search){
+ // 满足条件后执行
+ $query->where('yuwen|shuxue|waiyu',$search);
+ })
+ ->when(!empty($search) && !is_numeric($search),function($query) use($search){
+ $query->where('student','in',function ($q) use($search){
+ $q->name('student')
+ ->where('xingming','like','%'.$search.'%')
+ ->field('id');
});
})
->order([$order_field=>$order])
diff --git a/application/chengji/model/Tongji.php b/application/chengji/model/Tongji.php
index f4827d7f..8e868a9a 100644
--- a/application/chengji/model/Tongji.php
+++ b/application/chengji/model/Tongji.php
@@ -68,12 +68,12 @@ class Tongji extends Model
// 计算数据
$sum = array_sum($xkchengji);
- $avg = round($sum/$cnt,2);
- $youxiulv = round($youxiu/$cnt*100,2);
- $jigelv = round($jige/$cnt*100,2);
+ $avg = round($sum/$cnt,1);
+ $youxiulv = round($youxiu/$cnt*100,1);
+ $jigelv = round($jige/$cnt*100,1);
$max = max($xkchengji);
$min = min($xkchengji);
- $biaozhuncha = round($this->getVariance($avg,$xkchengji,true),2);
+ $biaozhuncha = round($this->getVariance($avg,$xkchengji,true),1);
$sifenwei = $this->quartile($xkchengji);
// 数组赋值
$data = [
diff --git a/application/chengji/view/index/download.html b/application/chengji/view/index/download.html
new file mode 100644
index 00000000..22f2ab7f
--- /dev/null
+++ b/application/chengji/view/index/download.html
@@ -0,0 +1,165 @@
+
+
+
+
+
+
+
+
+
+
+
+
+{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui/css/H-ui.min.css" /}
+{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui.admin/css/H-ui.admin.css" /}
+{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/Hui-iconfont/1.0.8/iconfont.css" /}
+{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui.admin/skin/default/skin.css" id="skin" /}
+{css rel="stylesheet" type="text/css" href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui.admin/css/style.css" /}
+{$list.title|default='学生成绩下载'}
+
+
+
+
+
+
+
+
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/jquery/1.9.1/jquery.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/layer/2.4/layer.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui/js/H-ui.min.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/static/h-ui.admin/js/H-ui.admin.js"}
+
+
+
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/My97DatePicker/4.8/WdatePicker.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/jquery.validation/1.14.0/jquery.validate.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/jquery.validation/1.14.0/validate-methods.js"}
+{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/jquery.validation/1.14.0/messages_zh.js"}
+
+
+
diff --git a/application/common.php b/application/common.php
index 14591971..46fee364 100644
--- a/application/common.php
+++ b/application/common.php
@@ -127,3 +127,11 @@ function getAgeByBirth($date,$type = 1){
}
return $age;
}
+
+
+// EXCEL表格列名
+function excelLieming()
+{
+ $liemingarr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
+ return $liemingarr;
+}
diff --git a/application/kaoshi/common.php b/application/kaoshi/common.php
index f145647e..a4abe2da 100644
--- a/application/kaoshi/common.php
+++ b/application/kaoshi/common.php
@@ -1,8 +1,2 @@
save('php://output');
}
diff --git a/composer.lock b/composer.lock
index 378d4ab3..c077bb83 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1053,16 +1053,16 @@
},
{
"name": "topthink/framework",
- "version": "v5.1.29",
+ "version": "v5.1.31",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
- "reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f"
+ "reference": "93339b1a4df5a73e0143db0847a4c5e0b2e46fb0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/top-think/framework/zipball/f1d8ee3a91e8f504507edb5dcc49c50c47b4500f",
- "reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f",
+ "url": "https://api.github.com/repos/top-think/framework/zipball/93339b1a4df5a73e0143db0847a4c5e0b2e46fb0",
+ "reference": "93339b1a4df5a73e0143db0847a4c5e0b2e46fb0",
"shasum": "",
"mirrors": [
{
@@ -1106,7 +1106,7 @@
"orm",
"thinkphp"
],
- "time": "2018-11-11T01:17:33+00:00"
+ "time": "2018-12-09T12:41:21+00:00"
},
{
"name": "topthink/think-captcha",
diff --git a/route/chengji.php b/route/chengji.php
index acee55e4..e09791fc 100644
--- a/route/chengji.php
+++ b/route/chengji.php
@@ -19,5 +19,6 @@ Route::get('chengji/biaolu','chengji/Index/biaolu');
Route::post('chengji/biaolu','chengji/Index/saveAll');
Route::get('chengji/:id/chengjilist','chengji/Index/chengjilist');
Route::get('chengji/:id/download','chengji/Index/download');
+Route::post('chengji/chengjixls','chengji/Index/chengjixls');
Route::get('cjtongji/:id/nianji','chengji/Tongji/nianji');
\ No newline at end of file
diff --git a/thinkphp/helper.php b/thinkphp/helper.php
index 4aa73722..9c465335 100644
--- a/thinkphp/helper.php
+++ b/thinkphp/helper.php
@@ -313,9 +313,9 @@ if (!function_exists('download')) {
* @param integer $expire 有效期(秒)
* @return \think\response\Download
*/
- function download($filename, $name = '', $content = false, $expire = 180)
+ function download($filename, $name = '', $content = false, $expire = 360, $openinBrower = false)
{
- return Response::create($filename, 'download')->name($name)->isContent($content)->expire($expire);
+ return Response::create($filename, 'download')->name($name)->isContent($content)->expire($expire)->openinBrower($openinBrower);
}
}
diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php
index c9522fa9..cfa2601e 100644
--- a/thinkphp/library/think/App.php
+++ b/thinkphp/library/think/App.php
@@ -20,7 +20,7 @@ use think\route\Dispatch;
*/
class App extends Container
{
- const VERSION = '5.1.29 LTS';
+ const VERSION = '5.1.31 LTS';
/**
* 当前模块路径
diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php
index 61f7fedc..6ba6e7d7 100644
--- a/thinkphp/library/think/Request.php
+++ b/thinkphp/library/think/Request.php
@@ -1314,6 +1314,21 @@ class Request
return isset($this->header[$name]) ? $this->header[$name] : $default;
}
+ /**
+ * 递归重置数组指针
+ * @access public
+ * @param array $data 数据源
+ * @return void
+ */
+ public function arrayReset(array &$data) {
+ foreach ($data as &$value) {
+ if (is_array($value)) {
+ $this->arrayReset($value);
+ }
+ }
+ reset($data);
+ }
+
/**
* 获取变量 支持过滤和默认值
* @access public
@@ -1353,7 +1368,10 @@ class Request
if (is_array($data)) {
array_walk_recursive($data, [$this, 'filterValue'], $filter);
- reset($data);
+ if (version_compare(PHP_VERSION, '7.1.0', '<')) {
+ // 恢复PHP版本低于 7.1 时 array_walk_recursive 中消耗的内部指针
+ $this->arrayReset($data);
+ }
} else {
$this->filterValue($data, $name, $filter);
}
diff --git a/thinkphp/library/think/Route.php b/thinkphp/library/think/Route.php
index 5122aec9..7bd468ba 100644
--- a/thinkphp/library/think/Route.php
+++ b/thinkphp/library/think/Route.php
@@ -424,9 +424,9 @@ class Route
* @param string $domain 域名
* @return mixed
*/
- public function getName($name = null, $domain = null)
+ public function getName($name = null, $domain = null, $method = '*')
{
- return $this->app['rule_name']->get($name, $domain);
+ return $this->app['rule_name']->get($name, $domain, $method);
}
/**
diff --git a/thinkphp/library/think/Url.php b/thinkphp/library/think/Url.php
index 2724b3f6..a339f8de 100644
--- a/thinkphp/library/think/Url.php
+++ b/thinkphp/library/think/Url.php
@@ -354,7 +354,7 @@ class Url
continue;
}
- if ($this->app['request']->port() != 80) {
+ if (!in_array($this->app['request']->port(), [80, 443])) {
$domain .= ':' . $this->app['request']->port();
}
diff --git a/thinkphp/library/think/Validate.php b/thinkphp/library/think/Validate.php
index 205ec072..4672a5cb 100644
--- a/thinkphp/library/think/Validate.php
+++ b/thinkphp/library/think/Validate.php
@@ -517,6 +517,8 @@ class Validate
}
$i = 0;
+ $result = true;
+
foreach ($rules as $key => $rule) {
if ($rule instanceof \Closure) {
$result = call_user_func_array($rule, [$value, $data]);
@@ -527,17 +529,18 @@ class Validate
if (isset($this->append[$field]) && in_array($info, $this->append[$field])) {
- } elseif (isset($this->remove[$field]) && in_array($info, $this->remove[$field])) {
+ } elseif (array_key_exists($field, $this->remove) && (null === $this->remove[$field] || in_array($info, $this->remove[$field]))) {
// 规则已经移除
$i++;
continue;
}
- if ('must' == $info || 0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) {
- // 验证类型
- $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];
+ // 验证类型
+ if (isset(self::$type[$type])) {
+ $result = call_user_func_array(self::$type[$type], [$value, $rule, $data, $field, $title]);
+ } elseif ('must' == $info || 0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) {
// 验证数据
- $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]);
+ $result = call_user_func_array([$this, $type], [$value, $rule, $data, $field, $title]);
} else {
$result = true;
}
diff --git a/thinkphp/library/think/console/command/optimize/Autoload.php b/thinkphp/library/think/console/command/optimize/Autoload.php
index b15ddce3..b51fd259 100644
--- a/thinkphp/library/think/console/command/optimize/Autoload.php
+++ b/thinkphp/library/think/console/command/optimize/Autoload.php
@@ -38,8 +38,8 @@ EOF;
$app = Container::get('app');
$namespacesToScan = [
$app->getNamespace() . '\\' => realpath(rtrim($app->getAppPath())),
- 'think\\' => $app->getAppPath() . 'library/think',
- 'traits\\' => $app->getAppPath() . 'library/traits',
+ 'think\\' => $app->getThinkPath() . 'library/think',
+ 'traits\\' => $app->getThinkPath() . 'library/traits',
'' => realpath(rtrim($app->getRootPath() . 'extend')),
];
diff --git a/thinkphp/library/think/db/Builder.php b/thinkphp/library/think/db/Builder.php
index 05d52d1b..3dbbf768 100644
--- a/thinkphp/library/think/db/Builder.php
+++ b/thinkphp/library/think/db/Builder.php
@@ -411,8 +411,11 @@ abstract class Builder
}
if (is_scalar($value) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) {
- $name = $query->bind($value, $bindType);
- $value = ':' . $name;
+ if (0 === strpos($value, ':') && $query->isBind(substr($value, 1))) {
+ } else {
+ $name = $query->bind($value, $bindType);
+ $value = ':' . $name;
+ }
}
// 解析查询表达式
diff --git a/thinkphp/library/think/db/Connection.php b/thinkphp/library/think/db/Connection.php
index 914007af..af27fd62 100644
--- a/thinkphp/library/think/db/Connection.php
+++ b/thinkphp/library/think/db/Connection.php
@@ -1309,12 +1309,12 @@ abstract class Connection
* @access public
* @param Query $query 查询对象
* @param string $aggregate 聚合方法
- * @param string $field 字段名
+ * @param mixed $field 字段名
* @return mixed
*/
public function aggregate(Query $query, $aggregate, $field)
{
- if (0 === stripos($field, 'DISTINCT ')) {
+ if (is_string($field) && 0 === stripos($field, 'DISTINCT ')) {
list($distinct, $field) = explode(' ', $field);
}
@@ -1463,10 +1463,12 @@ abstract class Connection
$value = is_array($val) ? $val[0] : $val;
$type = is_array($val) ? $val[1] : PDO::PARAM_STR;
- if (PDO::PARAM_INT == $type || self::PARAM_FLOAT == $type) {
+ if (self::PARAM_FLOAT == $type) {
$value = (float) $value;
} elseif (PDO::PARAM_STR == $type) {
$value = '\'' . addslashes($value) . '\'';
+ } elseif (PDO::PARAM_INT == $type && '' === $value) {
+ $value = 0;
}
// 判断占位符
diff --git a/thinkphp/library/think/db/Query.php b/thinkphp/library/think/db/Query.php
index 9d653447..00483328 100644
--- a/thinkphp/library/think/db/Query.php
+++ b/thinkphp/library/think/db/Query.php
@@ -326,7 +326,7 @@ class Query
*/
public function execute($sql, $bind = [])
{
- return $this->connection->execute($sql, $bind);
+ return $this->connection->execute($sql, $bind, $this);
}
/**
@@ -656,9 +656,9 @@ class Query
$query->fetchSql(true);
}
- $count = $query->aggregate('COUNT', '*');
+ $count = $query->aggregate('COUNT', '*', true);
} else {
- $count = $this->aggregate('COUNT', $field);
+ $count = $this->aggregate('COUNT', $field, true);
}
return is_string($count) ? $count : (int) $count;
@@ -1008,11 +1008,13 @@ class Query
if ($tableName) {
// 添加统一的前缀
$prefix = $prefix ?: $tableName;
- foreach ($field as $key => $val) {
- if (is_numeric($key)) {
- $val = $prefix . '.' . $val . ($alias ? ' AS ' . $alias . $val : '');
+ foreach ($field as $key => &$val) {
+ if (is_numeric($key) && $alias) {
+ $field[$prefix . '.' . $val] = $alias . $val;
+ unset($field[$key]);
+ } elseif (is_numeric($key)) {
+ $val = $prefix . '.' . $val;
}
- $field[$key] = $val;
}
}
@@ -3548,6 +3550,10 @@ class Query
*/
protected function parseView(&$options)
{
+ if (!isset($options['map'])) {
+ return;
+ }
+
foreach (['AND', 'OR'] as $logic) {
if (isset($options['where'][$logic])) {
foreach ($options['where'][$logic] as $key => $val) {
@@ -3567,7 +3573,7 @@ class Query
$options['order'] = explode(',', $options['order']);
}
foreach ($options['order'] as $key => $val) {
- if (is_numeric($key)) {
+ if (is_numeric($key) && is_string($val)) {
if (strpos($val, ' ')) {
list($field, $sort) = explode(' ', $val);
if (array_key_exists($field, $options['map'])) {
diff --git a/thinkphp/library/think/db/connector/Sqlsrv.php b/thinkphp/library/think/db/connector/Sqlsrv.php
index aba405fd..123affb8 100644
--- a/thinkphp/library/think/db/connector/Sqlsrv.php
+++ b/thinkphp/library/think/db/connector/Sqlsrv.php
@@ -56,6 +56,8 @@ class Sqlsrv extends Connection
public function getFields($tableName)
{
list($tableName) = explode(' ', $tableName);
+ $tableNames = explode('.', $tableName);
+ $tableName = isset($tableNames[1]) ? $tableNames[1] : $tableNames[0];
$sql = "SELECT column_name, data_type, column_default, is_nullable
FROM information_schema.tables AS t
diff --git a/thinkphp/library/think/model/concern/Attribute.php b/thinkphp/library/think/model/concern/Attribute.php
index 02f62b14..75b02ab5 100644
--- a/thinkphp/library/think/model/concern/Attribute.php
+++ b/thinkphp/library/think/model/concern/Attribute.php
@@ -371,7 +371,7 @@ trait Attribute
case 'datetime':
case 'date':
$format = !empty($param) ? $param : $this->dateFormat;
- $value = $this->formatDateTime(time(), $format);
+ $value = $this->formatDateTime($format . '.u');
break;
case 'timestamp':
case 'integer':
@@ -384,9 +384,9 @@ trait Attribute
'date',
'timestamp',
])) {
- $value = $this->formatDateTime(time(), $this->dateFormat);
+ $value = $this->formatDateTime($this->dateFormat . '.u');
} else {
- $value = $this->formatDateTime(time(), $this->dateFormat, true);
+ $value = time();
}
return $value;
@@ -433,7 +433,7 @@ trait Attribute
case 'datetime':
$format = !empty($param) ? $param : $this->dateFormat;
$value = is_numeric($value) ? $value : strtotime($value);
- $value = $this->formatDateTime($value, $format);
+ $value = $this->formatDateTime($format, $value);
break;
case 'object':
if (is_object($value)) {
@@ -500,9 +500,9 @@ trait Attribute
'date',
'timestamp',
])) {
- $value = $this->formatDateTime(strtotime($value), $this->dateFormat);
+ $value = $this->formatDateTime($this->dateFormat, $value);
} else {
- $value = $this->formatDateTime($value, $this->dateFormat);
+ $value = $this->formatDateTime($this->dateFormat, $value, true);
}
} elseif ($notFound) {
$value = $this->getRelationAttribute($name, $item);
@@ -588,13 +588,13 @@ trait Attribute
case 'timestamp':
if (!is_null($value)) {
$format = !empty($param) ? $param : $this->dateFormat;
- $value = $this->formatDateTime($value, $format);
+ $value = $this->formatDateTime($format, $value, true);
}
break;
case 'datetime':
if (!is_null($value)) {
$format = !empty($param) ? $param : $this->dateFormat;
- $value = $this->formatDateTime(strtotime($value), $format);
+ $value = $this->formatDateTime($format, $value);
}
break;
case 'json':
diff --git a/thinkphp/library/think/model/concern/SoftDelete.php b/thinkphp/library/think/model/concern/SoftDelete.php
index ca55204e..7dc96e12 100644
--- a/thinkphp/library/think/model/concern/SoftDelete.php
+++ b/thinkphp/library/think/model/concern/SoftDelete.php
@@ -140,7 +140,7 @@ trait SoftDelete
public static function destroy($data, $force = false)
{
// 包含软删除数据
- $query = self::withTrashed();
+ $query = (new static())->db(false);
if (is_array($data) && key($data) !== 0) {
$query->where($data);
diff --git a/thinkphp/library/think/model/concern/TimeStamp.php b/thinkphp/library/think/model/concern/TimeStamp.php
index e55082cc..99a31fa7 100644
--- a/thinkphp/library/think/model/concern/TimeStamp.php
+++ b/thinkphp/library/think/model/concern/TimeStamp.php
@@ -11,6 +11,8 @@
namespace think\model\concern;
+use DateTime;
+
/**
* 自动时间戳
*/
@@ -43,24 +45,31 @@ trait TimeStamp
/**
* 时间日期字段格式化处理
* @access protected
- * @param mixed $time 时间日期表达式
* @param mixed $format 日期格式
+ * @param mixed $time 时间日期表达式
* @param bool $timestamp 是否进行时间戳转换
* @return mixed
*/
- protected function formatDateTime($time, $format, $timestamp = false)
+ protected function formatDateTime($format, $time = 'now', $timestamp = false)
{
if (empty($time)) {
return;
}
- if (false !== strpos($format, '\\')) {
- $time = new $format($time);
- } elseif (!$timestamp && false !== $format) {
- $time = date($format, $time);
+ if (false === $format) {
+ return $time;
+ } elseif (false !== strpos($format, '\\')) {
+ return new $format($time);
}
- return $time;
+ if ($timestamp) {
+ $dateTime = new DateTime();
+ $dateTime->setTimestamp($time);
+ } else {
+ $dateTime = new DateTime($time);
+ }
+
+ return $dateTime->format($format);
}
/**
diff --git a/thinkphp/library/think/model/relation/BelongsToMany.php b/thinkphp/library/think/model/relation/BelongsToMany.php
index a66b0d01..b7cdebe1 100644
--- a/thinkphp/library/think/model/relation/BelongsToMany.php
+++ b/thinkphp/library/think/model/relation/BelongsToMany.php
@@ -559,7 +559,7 @@ class BelongsToMany extends Relation
foreach ($ids as $id) {
$pivot[$this->foreignKey] = $id;
- $this->pivot->insert($pivot, true);
+ $this->pivot->replace()->save($pivot);
$result[] = $this->newPivot($pivot, true);
}
diff --git a/thinkphp/library/think/model/relation/HasMany.php b/thinkphp/library/think/model/relation/HasMany.php
index f679e95b..72d83144 100644
--- a/thinkphp/library/think/model/relation/HasMany.php
+++ b/thinkphp/library/think/model/relation/HasMany.php
@@ -240,6 +240,18 @@ class HasMany extends Relation
* @return Model|false
*/
public function save($data, $replace = true)
+ {
+ $model = $this->make($data);
+
+ return $model->replace($replace)->save() ? $model : false;
+ }
+
+ /**
+ * 创建关联对象实例
+ * @param array $data
+ * @return Model
+ */
+ public function make($data = [])
{
if ($data instanceof Model) {
$data = $data->getData();
@@ -248,9 +260,7 @@ class HasMany extends Relation
// 保存关联表数据
$data[$this->foreignKey] = $this->parent->{$this->localKey};
- $model = new $this->model;
-
- return $model->replace($replace)->save($data) ? $model : false;
+ return new $this->model($data);
}
/**
diff --git a/thinkphp/library/think/model/relation/MorphMany.php b/thinkphp/library/think/model/relation/MorphMany.php
index e1ca0912..1a7f15eb 100644
--- a/thinkphp/library/think/model/relation/MorphMany.php
+++ b/thinkphp/library/think/model/relation/MorphMany.php
@@ -272,10 +272,22 @@ class MorphMany extends Relation
/**
* 保存(新增)当前关联数据对象
* @access public
- * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键
+ * @param mixed $data 数据
* @return Model|false
*/
public function save($data)
+ {
+ $model = $this->make($data);
+
+ return $model->save($data) ? $model : false;
+ }
+
+ /**
+ * 创建关联对象实例
+ * @param array $data
+ * @return Model
+ */
+ public function make($data = [])
{
if ($data instanceof Model) {
$data = $data->getData();
@@ -284,12 +296,10 @@ class MorphMany extends Relation
// 保存关联表数据
$pk = $this->parent->getPk();
- $model = new $this->model;
-
$data[$this->morphKey] = $this->parent->$pk;
$data[$this->morphType] = $this->type;
- return $model->save($data) ? $model : false;
+ return new $this->model($data);
}
/**
diff --git a/thinkphp/library/think/model/relation/MorphOne.php b/thinkphp/library/think/model/relation/MorphOne.php
index 738040db..716539f4 100644
--- a/thinkphp/library/think/model/relation/MorphOne.php
+++ b/thinkphp/library/think/model/relation/MorphOne.php
@@ -206,22 +206,33 @@ class MorphOne extends Relation
/**
* 保存(新增)当前关联数据对象
* @access public
- * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键
+ * @param mixed $data 数据
* @return Model|false
*/
public function save($data)
+ {
+ $model = $this->make($data);
+ return $model->save() ? $model : false;
+ }
+
+ /**
+ * 创建关联对象实例
+ * @param array $data
+ * @return Model
+ */
+ public function make($data = [])
{
if ($data instanceof Model) {
$data = $data->getData();
}
+
// 保存关联表数据
$pk = $this->parent->getPk();
- $model = new $this->model;
-
$data[$this->morphKey] = $this->parent->$pk;
$data[$this->morphType] = $this->type;
- return $model->save($data) ? $model : false;
+
+ return new $this->model($data);
}
/**
diff --git a/thinkphp/library/think/response/Download.php b/thinkphp/library/think/response/Download.php
index 02a440df..d5fcb444 100644
--- a/thinkphp/library/think/response/Download.php
+++ b/thinkphp/library/think/response/Download.php
@@ -20,7 +20,7 @@ class Download extends Response
protected $name;
protected $mimeType;
protected $isContent = false;
-
+ protected $openinBrower = false;
/**
* 处理数据
* @access protected
@@ -53,7 +53,7 @@ class Download 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->openinBrower ? 'inline' : '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';
@@ -134,4 +134,15 @@ class Download extends Response
return $this;
}
+
+ /**
+ * 设置是否在浏览器中显示文件
+ * @access public
+ * @param bool $openinBrower 是否在浏览器中显示文件
+ * @return $this
+ */
+ public function openinBrower($openinBrower) {
+ $this->openinBrower = $openinBrower;
+ return $this;
+ }
}
diff --git a/thinkphp/library/think/route/RuleName.php b/thinkphp/library/think/route/RuleName.php
index 46481f8c..202fb0e2 100644
--- a/thinkphp/library/think/route/RuleName.php
+++ b/thinkphp/library/think/route/RuleName.php
@@ -107,13 +107,14 @@ class RuleName
* @param string $domain 域名
* @return array|null
*/
- public function get($name = null, $domain = null)
+ public function get($name = null, $domain = null, $method = '*')
{
if (is_null($name)) {
return $this->item;
}
$name = strtolower($name);
+ $method = strtolower($method);
if (isset($this->item[$name])) {
if (is_null($domain)) {
@@ -121,7 +122,7 @@ class RuleName
} else {
$result = [];
foreach ($this->item[$name] as $item) {
- if ($item[2] == $domain) {
+ if ($item[2] == $domain && ('*' == $item[4] || $method == $item[4])) {
$result[] = $item;
}
}
diff --git a/thinkphp/library/think/route/dispatch/Module.php b/thinkphp/library/think/route/dispatch/Module.php
index 396ce11d..dc1974ce 100644
--- a/thinkphp/library/think/route/dispatch/Module.php
+++ b/thinkphp/library/think/route/dispatch/Module.php
@@ -67,7 +67,12 @@ class Module extends Dispatch
// 是否自动转换控制器和操作名
$convert = is_bool($this->convert) ? $this->convert : $this->rule->getConfig('url_convert');
// 获取控制器名
- $controller = strip_tags($result[1] ?: $this->rule->getConfig('default_controller'));
+ $controller = strip_tags($result[1] ?: $this->rule->getConfig('default_controller'));
+
+ if (!preg_match('/^[A-Za-z](\w|\.)*$/', $controller)) {
+ throw new HttpException(404, 'controller not exists:' . $controller);
+ }
+
$this->controller = $convert ? strtolower($controller) : $controller;
// 获取操作名
diff --git a/thinkphp/library/think/route/dispatch/Url.php b/thinkphp/library/think/route/dispatch/Url.php
index 0fb6e0c2..95ee9e53 100644
--- a/thinkphp/library/think/route/dispatch/Url.php
+++ b/thinkphp/library/think/route/dispatch/Url.php
@@ -116,7 +116,9 @@ class Url extends Dispatch
$host = $this->request->host(true);
- if ($this->rule->getRouter()->getName($name, $host) || $this->rule->getRouter()->getName($name2, $host)) {
+ $method = $this->request->method();
+
+ if ($this->rule->getRouter()->getName($name, $host, $method) || $this->rule->getRouter()->getName($name2, $host, $method)) {
return true;
}
diff --git a/thinkphp/library/think/template/TagLib.php b/thinkphp/library/think/template/TagLib.php
index 3653b7d2..bbbb2c03 100644
--- a/thinkphp/library/think/template/TagLib.php
+++ b/thinkphp/library/think/template/TagLib.php
@@ -298,7 +298,7 @@ class TagLib
*/
public function parseCondition($condition)
{
- if (strpos($condition, ':')) {
+ if (!strpos($condition, '::') && strpos($condition, ':')) {
$condition = ' ' . substr(strstr($condition, ':'), 1);
}
diff --git a/thinkphp/library/think/validate/ValidateRule.php b/thinkphp/library/think/validate/ValidateRule.php
index 5253465f..7cd70174 100644
--- a/thinkphp/library/think/validate/ValidateRule.php
+++ b/thinkphp/library/think/validate/ValidateRule.php
@@ -36,25 +36,25 @@ namespace think\validate;
* @method ValidateRule regex(mixed $rule, string $msg = '') static 使用正则验证数据
* @method ValidateRule token(mixed $rule='__token__', string $msg = '') static 验证表单令牌
* @method ValidateRule is(mixed $rule, string $msg = '') static 验证字段值是否为有效格式
- * @method ValidateRule isRequire(mixed $rule, string $msg = '') static 验证字段必须
- * @method ValidateRule isNumber(mixed $rule, string $msg = '') static 验证字段值是否为数字
- * @method ValidateRule isArray(mixed $rule, string $msg = '') static 验证字段值是否为数组
- * @method ValidateRule isInteger(mixed $rule, string $msg = '') static 验证字段值是否为整形
- * @method ValidateRule isFloat(mixed $rule, string $msg = '') static 验证字段值是否为浮点数
- * @method ValidateRule isMobile(mixed $rule, string $msg = '') static 验证字段值是否为手机
- * @method ValidateRule isIdCard(mixed $rule, string $msg = '') static 验证字段值是否为身份证号码
- * @method ValidateRule isChs(mixed $rule, string $msg = '') static 验证字段值是否为中文
- * @method ValidateRule isChsDash(mixed $rule, string $msg = '') static 验证字段值是否为中文字母及下划线
- * @method ValidateRule isChsAlpha(mixed $rule, string $msg = '') static 验证字段值是否为中文和字母
- * @method ValidateRule isChsAlphaNum(mixed $rule, string $msg = '') static 验证字段值是否为中文字母和数字
- * @method ValidateRule isDate(mixed $rule, string $msg = '') static 验证字段值是否为有效格式
- * @method ValidateRule isBool(mixed $rule, string $msg = '') static 验证字段值是否为布尔值
- * @method ValidateRule isAlpha(mixed $rule, string $msg = '') static 验证字段值是否为字母
- * @method ValidateRule isAlphaDash(mixed $rule, string $msg = '') static 验证字段值是否为字母和下划线
- * @method ValidateRule isAlphaNum(mixed $rule, string $msg = '') static 验证字段值是否为字母和数字
- * @method ValidateRule isAccepted(mixed $rule, string $msg = '') static 验证字段值是否为yes, on, 或是 1
- * @method ValidateRule isEmail(mixed $rule, string $msg = '') static 验证字段值是否为有效邮箱格式
- * @method ValidateRule isUrl(mixed $rule, string $msg = '') static 验证字段值是否为有效URL地址
+ * @method ValidateRule isRequire(mixed $rule = null, string $msg = '') static 验证字段必须
+ * @method ValidateRule isNumber(mixed $rule = null, string $msg = '') static 验证字段值是否为数字
+ * @method ValidateRule isArray(mixed $rule = null, string $msg = '') static 验证字段值是否为数组
+ * @method ValidateRule isInteger(mixed $rule = null, string $msg = '') static 验证字段值是否为整形
+ * @method ValidateRule isFloat(mixed $rule = null, string $msg = '') static 验证字段值是否为浮点数
+ * @method ValidateRule isMobile(mixed $rule = null, string $msg = '') static 验证字段值是否为手机
+ * @method ValidateRule isIdCard(mixed $rule = null, string $msg = '') static 验证字段值是否为身份证号码
+ * @method ValidateRule isChs(mixed $rule = null, string $msg = '') static 验证字段值是否为中文
+ * @method ValidateRule isChsDash(mixed $rule = null, string $msg = '') static 验证字段值是否为中文字母及下划线
+ * @method ValidateRule isChsAlpha(mixed $rule = null, string $msg = '') static 验证字段值是否为中文和字母
+ * @method ValidateRule isChsAlphaNum(mixed $rule = null, string $msg = '') static 验证字段值是否为中文字母和数字
+ * @method ValidateRule isDate(mixed $rule = null, string $msg = '') static 验证字段值是否为有效格式
+ * @method ValidateRule isBool(mixed $rule = null, string $msg = '') static 验证字段值是否为布尔值
+ * @method ValidateRule isAlpha(mixed $rule = null, string $msg = '') static 验证字段值是否为字母
+ * @method ValidateRule isAlphaDash(mixed $rule = null, string $msg = '') static 验证字段值是否为字母和下划线
+ * @method ValidateRule isAlphaNum(mixed $rule = null, string $msg = '') static 验证字段值是否为字母和数字
+ * @method ValidateRule isAccepted(mixed $rule = null, string $msg = '') static 验证字段值是否为yes, on, 或是 1
+ * @method ValidateRule isEmail(mixed $rule = null, string $msg = '') static 验证字段值是否为有效邮箱格式
+ * @method ValidateRule isUrl(mixed $rule = null, string $msg = '') static 验证字段值是否为有效URL地址
* @method ValidateRule activeUrl(mixed $rule, string $msg = '') static 验证是否为合格的域名或者IP
* @method ValidateRule ip(mixed $rule, string $msg = '') static 验证是否有效IP
* @method ValidateRule fileExt(mixed $rule, string $msg = '') static 验证文件后缀
@@ -69,7 +69,7 @@ namespace think\validate;
* @method ValidateRule requireIf(mixed $rule, string $msg = '') static 验证某个字段等于某个值的时候必须
* @method ValidateRule requireCallback(mixed $rule, string $msg = '') static 通过回调方法验证某个字段是否必须
* @method ValidateRule requireWith(mixed $rule, string $msg = '') static 验证某个字段有值的情况下必须
- * @method ValidateRule must(mixed $rule=null, string $msg = '') static 必须验证
+ * @method ValidateRule must(mixed $rule = null, string $msg = '') static 必须验证
*/
class ValidateRule
{
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index e18e159a..d4a5362c 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -1078,17 +1078,17 @@
},
{
"name": "topthink/framework",
- "version": "v5.1.29",
- "version_normalized": "5.1.29.0",
+ "version": "v5.1.31",
+ "version_normalized": "5.1.31.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
- "reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f"
+ "reference": "93339b1a4df5a73e0143db0847a4c5e0b2e46fb0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/top-think/framework/zipball/f1d8ee3a91e8f504507edb5dcc49c50c47b4500f",
- "reference": "f1d8ee3a91e8f504507edb5dcc49c50c47b4500f",
+ "url": "https://api.github.com/repos/top-think/framework/zipball/93339b1a4df5a73e0143db0847a4c5e0b2e46fb0",
+ "reference": "93339b1a4df5a73e0143db0847a4c5e0b2e46fb0",
"shasum": "",
"mirrors": [
{
@@ -1110,7 +1110,7 @@
"sebastian/phpcpd": "2.*",
"squizlabs/php_codesniffer": "2.*"
},
- "time": "2018-11-11T01:17:33+00:00",
+ "time": "2018-12-09T12:41:21+00:00",
"type": "think-framework",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",