diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 0c2002977..88da7b678 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -449,6 +449,7 @@ return array( 'think\\event\\AppInit' => $vendorDir . '/topthink/framework/src/think/event/AppInit.php', 'think\\event\\HttpEnd' => $vendorDir . '/topthink/framework/src/think/event/HttpEnd.php', 'think\\event\\HttpRun' => $vendorDir . '/topthink/framework/src/think/event/HttpRun.php', + 'think\\event\\LogRecord' => $vendorDir . '/topthink/framework/src/think/event/LogRecord.php', 'think\\event\\LogWrite' => $vendorDir . '/topthink/framework/src/think/event/LogWrite.php', 'think\\event\\RouteLoaded' => $vendorDir . '/topthink/framework/src/think/event/RouteLoaded.php', 'think\\exception\\ClassNotFoundException' => $vendorDir . '/topthink/framework/src/think/exception/ClassNotFoundException.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 095220d47..c0ba72e95 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -578,6 +578,7 @@ class ComposerStaticInit3e3e984682c06e656fe76c5d84347fb3 'think\\event\\AppInit' => __DIR__ . '/..' . '/topthink/framework/src/think/event/AppInit.php', 'think\\event\\HttpEnd' => __DIR__ . '/..' . '/topthink/framework/src/think/event/HttpEnd.php', 'think\\event\\HttpRun' => __DIR__ . '/..' . '/topthink/framework/src/think/event/HttpRun.php', + 'think\\event\\LogRecord' => __DIR__ . '/..' . '/topthink/framework/src/think/event/LogRecord.php', 'think\\event\\LogWrite' => __DIR__ . '/..' . '/topthink/framework/src/think/event/LogWrite.php', 'think\\event\\RouteLoaded' => __DIR__ . '/..' . '/topthink/framework/src/think/event/RouteLoaded.php', 'think\\exception\\ClassNotFoundException' => __DIR__ . '/..' . '/topthink/framework/src/think/exception/ClassNotFoundException.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 0330cac1d..e5a12c2e3 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -515,17 +515,17 @@ }, { "name": "topthink/framework", - "version": "v6.0.7", - "version_normalized": "6.0.7.0", + "version": "v6.0.8", + "version_normalized": "6.0.8.0", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "db8fe22520a9660dd5e4c87e304034ac49e39270" + "reference": "4789343672aef06d571d556da369c0e156609bce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/db8fe22520a9660dd5e4c87e304034ac49e39270", - "reference": "db8fe22520a9660dd5e4c87e304034ac49e39270", + "url": "https://api.github.com/repos/top-think/framework/zipball/4789343672aef06d571d556da369c0e156609bce", + "reference": "4789343672aef06d571d556da369c0e156609bce", "shasum": "", "mirrors": [ { @@ -551,7 +551,7 @@ "mockery/mockery": "^1.2", "phpunit/phpunit": "^7.0" }, - "time": "2021-01-25T14:48:29+00:00", + "time": "2021-04-27T00:41:08+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -631,17 +631,17 @@ }, { "name": "topthink/think-orm", - "version": "v2.0.39", - "version_normalized": "2.0.39.0", + "version": "v2.0.40", + "version_normalized": "2.0.40.0", "source": { "type": "git", "url": "https://github.com/top-think/think-orm.git", - "reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7" + "reference": "1119d979b850849f3725856460cf108eec1c3eb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/think-orm/zipball/39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7", - "reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7", + "url": "https://api.github.com/repos/top-think/think-orm/zipball/1119d979b850849f3725856460cf108eec1c3eb8", + "reference": "1119d979b850849f3725856460cf108eec1c3eb8", "shasum": "", "mirrors": [ { @@ -661,7 +661,7 @@ "require-dev": { "phpunit/phpunit": "^7|^8|^9.5" }, - "time": "2021-02-26T10:20:00+00:00", + "time": "2021-04-19T13:29:37+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -834,12 +834,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "c4bfb714326a86598fe14a085be4b5439f656c77" + "reference": "361caa1f19e990422b0ca089b44961666861e28d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/c4bfb714326a86598fe14a085be4b5439f656c77", - "reference": "c4bfb714326a86598fe14a085be4b5439f656c77", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/361caa1f19e990422b0ca089b44961666861e28d", + "reference": "361caa1f19e990422b0ca089b44961666861e28d", "shasum": "", "mirrors": [ { @@ -856,7 +856,7 @@ "ext-mbstring": "*", "topthink/framework": "^6.0" }, - "time": "2021-04-08T06:20:57+00:00", + "time": "2021-04-26T09:07:36+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index 7d8f381bd..bbca8f615 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\admin\\Library', diff --git a/vendor/topthink/framework/src/think/App.php b/vendor/topthink/framework/src/think/App.php index 69e9b9539..cdcfeb8d2 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.7'; + const VERSION = '6.0.8'; /** * 应用调试模式 @@ -47,6 +47,12 @@ class App extends Container */ protected $appDebug = false; + /** + * 环境变量标识 + * @var string + */ + protected $envName = ''; + /** * 应用开始时间 * @var float @@ -277,6 +283,18 @@ class App extends Container return $this->namespace; } + /** + * 设置环境变量标识 + * @access public + * @param string $name 环境标识 + * @return $this + */ + public function setEnvName(string $name) + { + $this->envName = $name; + return $this; + } + /** * 获取框架版本 * @access public @@ -395,6 +413,22 @@ class App extends Container return $this->beginMem; } + /** + * 加载环境变量定义 + * @access public + * @param string $envName 环境标识 + * @return void + */ + public function loadEnv(string $envName = ''): void + { + // 加载环境变量 + $envFile = $envName ? $this->rootPath . '.env.' . $envName : $this->rootPath . '.env'; + + if (is_file($envFile)) { + $this->env->load($envFile); + } + } + /** * 初始化应用 * @access public @@ -407,10 +441,7 @@ class App extends Container $this->beginTime = microtime(true); $this->beginMem = memory_get_usage(); - // 加载环境变量 - if (is_file($this->rootPath . '.env')) { - $this->env->load($this->rootPath . '.env'); - } + $this->loadEnv($this->envName); $this->configExt = $this->env->get('config_ext', '.php'); @@ -590,7 +621,7 @@ class App extends Container * 是否运行在命令行下 * @return bool */ - public function runningInConsole() + public function runningInConsole(): bool { return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg'; } diff --git a/vendor/topthink/framework/src/think/Request.php b/vendor/topthink/framework/src/think/Request.php index 2787b99a0..a21976df1 100644 --- a/vendor/topthink/framework/src/think/Request.php +++ b/vendor/topthink/framework/src/think/Request.php @@ -869,6 +869,24 @@ class Request implements ArrayAccess return $this->input($this->param, $name, $default, $filter); } + /** + * 获取包含文件在内的请求参数 + * @access public + * @param string|array $name 变量名 + * @param string|array $filter 过滤方法 + * @return mixed + */ + public function all($name = '', $filter = '') + { + $data = array_merge($this->param(), $this->file()); + + if (is_array($name)) { + $data = $this->only($name, $data, $filter); + } + + return $data; + } + /** * 设置路由变量 * @access public diff --git a/vendor/topthink/framework/src/think/Response.php b/vendor/topthink/framework/src/think/Response.php index 2c07f5348..a8a61ffb2 100644 --- a/vendor/topthink/framework/src/think/Response.php +++ b/vendor/topthink/framework/src/think/Response.php @@ -214,7 +214,7 @@ abstract class Response /** * 是否允许请求缓存 * @access public - * @return $this + * @return bool */ public function isAllowCache() { diff --git a/vendor/topthink/framework/src/think/Validate.php b/vendor/topthink/framework/src/think/Validate.php index b7033cc64..078840641 100644 --- a/vendor/topthink/framework/src/think/Validate.php +++ b/vendor/topthink/framework/src/think/Validate.php @@ -1591,7 +1591,7 @@ class Validate * @param string $msg 错误信息 * @param mixed $rule 验证规则数据 * @param string $title 字段描述名 - * @return string + * @return string|array */ protected function parseErrorMsg(string $msg, $rule, string $title) { diff --git a/vendor/topthink/framework/src/think/console/input/Argument.php b/vendor/topthink/framework/src/think/console/input/Argument.php index 4fa3e3cd5..86cca36cb 100644 --- a/vendor/topthink/framework/src/think/console/input/Argument.php +++ b/vendor/topthink/framework/src/think/console/input/Argument.php @@ -13,14 +13,37 @@ namespace think\console\input; class Argument { - + // 必传参数 const REQUIRED = 1; + + // 可选参数 const OPTIONAL = 2; + + // 数组参数 const IS_ARRAY = 4; + /** + * 参数名 + * @var string + */ private $name; + + /** + * 参数类型 + * @var int + */ private $mode; + + /** + * 参数默认值 + * @var mixed + */ private $default; + + /** + * 参数描述 + * @var string + */ private $description; /** diff --git a/vendor/topthink/framework/src/think/event/LogRecord.php b/vendor/topthink/framework/src/think/event/LogRecord.php new file mode 100644 index 000000000..237468dd5 --- /dev/null +++ b/vendor/topthink/framework/src/think/event/LogRecord.php @@ -0,0 +1,29 @@ + +// +---------------------------------------------------------------------- +namespace think\event; + +/** + * LogRecord事件类 + */ +class LogRecord +{ + /** @var string */ + public $type; + + /** @var string */ + public $message; + + public function __construct($type, $message) + { + $this->type = $type; + $this->message = $message; + } +} diff --git a/vendor/topthink/framework/src/think/log/Channel.php b/vendor/topthink/framework/src/think/log/Channel.php index 505d83870..1de96f1a5 100644 --- a/vendor/topthink/framework/src/think/log/Channel.php +++ b/vendor/topthink/framework/src/think/log/Channel.php @@ -15,6 +15,7 @@ namespace think\log; use Psr\Log\LoggerInterface; use think\contract\LogHandlerInterface; use think\Event; +use think\event\LogRecord; use think\event\LogWrite; class Channel implements LoggerInterface @@ -94,6 +95,9 @@ class Channel implements LoggerInterface if (!empty($msg) || 0 === $msg) { $this->log[$type][] = $msg; + if ($this->event) { + $this->event->trigger(new LogRecord($type, $msg)); + } } if (!$this->lazy || !$lazy) { diff --git a/vendor/topthink/framework/src/think/route/RuleGroup.php b/vendor/topthink/framework/src/think/route/RuleGroup.php index 7b9deea40..cd9ddbd1b 100644 --- a/vendor/topthink/framework/src/think/route/RuleGroup.php +++ b/vendor/topthink/framework/src/think/route/RuleGroup.php @@ -171,7 +171,9 @@ class RuleGroup extends Rule } } - if ($this->miss && in_array($this->miss->getMethod(), ['*', $method])) { + if (!empty($option['dispatcher'])) { + $result = $this->parseRule($request, '', $option['dispatcher'], $url, $option); + } elseif ($this->miss && in_array($this->miss->getMethod(), ['*', $method])) { // 未匹配所有路由的路由规则处理 $result = $this->parseRule($request, '', $this->miss->getRoute(), $url, $this->miss->getOption()); } else { @@ -244,6 +246,11 @@ class RuleGroup extends Rule */ public function parseGroupRule($rule): void { + if (is_string($rule) && is_subclass_of($rule, Dispatch::class)) { + $this->dispatcher($rule); + return; + } + $origin = $this->router->getGroup(); $this->router->setGroup($this); @@ -466,6 +473,17 @@ class RuleGroup extends Rule return $this->setOption('merge_rule_regex', $merge); } + /** + * 设置分组的Dispatch调度 + * @access public + * @param string $dispatch 调度类 + * @return $this + */ + public function dispatcher(string $dispatch) + { + return $this->setOption('dispatcher', $dispatch); + } + /** * 获取完整分组Name * @access public diff --git a/vendor/topthink/framework/src/think/session/driver/File.php b/vendor/topthink/framework/src/think/session/driver/File.php index 1a0734ed8..788f3230e 100644 --- a/vendor/topthink/framework/src/think/session/driver/File.php +++ b/vendor/topthink/framework/src/think/session/driver/File.php @@ -98,7 +98,7 @@ class File implements SessionHandlerInterface /** @var SplFileInfo $item */ foreach ($items as $item) { if ($item->isDir() && !$item->isLink()) { - yield from$this->findFiles($item->getPathname(), $filter); + yield from $this->findFiles($item->getPathname(), $filter); } else { if ($filter($item)) { yield $item; diff --git a/vendor/topthink/think-orm/src/Model.php b/vendor/topthink/think-orm/src/Model.php index 5319edc6e..35c9b256d 100644 --- a/vendor/topthink/think-orm/src/Model.php +++ b/vendor/topthink/think-orm/src/Model.php @@ -267,7 +267,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab public function newInstance(array $data = [], $where = null): Model { $model = new static($data); - $model->readDataType(); if ($this->connection) { $model->setConnection($this->connection); @@ -457,8 +456,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab $this->data = $this->db()->find($this->getKey())->getData(); $this->origin = $this->data; $this->get = []; - $this->set = []; - $this->readDataType(); if ($relation) { $this->relation = []; @@ -546,7 +543,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab // 重新记录原始数据 $this->origin = $this->data; - $this->set = []; + $this->get = []; $this->lazySave = false; return true; @@ -613,8 +610,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab return true; } - $data = $this->writeDataType($data); - if ($this->autoWriteTimestamp && $this->updateTime) { // 自动写入更新时间 $data[$this->updateTime] = $this->autoWriteTimestamp(); @@ -677,7 +672,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab } $this->checkData(); - $data = $this->writeDataType($this->data); + $data = $this->data; // 时间戳自动写入 if ($this->autoWriteTimestamp) { @@ -709,6 +704,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab $pk = $this->getPk(); if (is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) { + unset($this->get[$pk]); $this->data[$pk] = $result; } } @@ -721,6 +717,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab // 标记数据已经存在 $this->exists = true; + $this->origin = $this->data; // 新增回调 $this->trigger('AfterInsert'); @@ -969,7 +966,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab { unset($this->data[$name], $this->get[$name], - $this->set[$name], $this->relation[$name]); } diff --git a/vendor/topthink/think-orm/src/db/BaseQuery.php b/vendor/topthink/think-orm/src/db/BaseQuery.php index 42b7ba030..4e9a20daa 100644 --- a/vendor/topthink/think-orm/src/db/BaseQuery.php +++ b/vendor/topthink/think-orm/src/db/BaseQuery.php @@ -1163,10 +1163,6 @@ abstract class BaseQuery $this->parseView($options); } - if (!isset($options['field'])) { - $options['field'] = '*'; - } - foreach (['data', 'order', 'join', 'union'] as $name) { if (!isset($options[$name])) { $options[$name] = []; diff --git a/vendor/topthink/think-orm/src/db/Builder.php b/vendor/topthink/think-orm/src/db/Builder.php index 914dd705f..73244f4d7 100644 --- a/vendor/topthink/think-orm/src/db/Builder.php +++ b/vendor/topthink/think-orm/src/db/Builder.php @@ -136,7 +136,7 @@ abstract class Builder } if (empty($fields)) { - if ('*' == $options['field']) { + if (empty($options['field']) || '*' == $options['field']) { $fields = array_keys($bind); } else { $fields = $options['field']; @@ -1125,7 +1125,7 @@ abstract class Builder $this->parseTable($query, $options['table']), $this->parseDistinct($query, $options['distinct']), $this->parseExtra($query, $options['extra']), - $this->parseField($query, $options['field']), + $this->parseField($query, $options['field'] ?? '*'), $this->parseJoin($query, $options['join']), $this->parseWhere($query, $options['where']), $this->parseGroup($query, $options['group']), @@ -1187,7 +1187,7 @@ abstract class Builder $bind = $query->getFieldsBindType(); // 获取合法的字段 - if ('*' == $options['field']) { + if (empty($options['field']) || '*' == $options['field']) { $allowFields = array_keys($bind); } else { $allowFields = $options['field']; diff --git a/vendor/topthink/think-orm/src/db/Connection.php b/vendor/topthink/think-orm/src/db/Connection.php index 4400ece52..aa86ba8e5 100644 --- a/vendor/topthink/think-orm/src/db/Connection.php +++ b/vendor/topthink/think-orm/src/db/Connection.php @@ -290,7 +290,7 @@ abstract class Connection implements ConnectionInterface protected function getCacheKey(BaseQuery $query, string $method = ''): string { if (!empty($query->getOptions('key')) && empty($method)) { - $key = 'think:' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key'); + $key = 'think_' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key'); } else { $key = $query->getQueryGuid(); } diff --git a/vendor/topthink/think-orm/src/db/builder/Mysql.php b/vendor/topthink/think-orm/src/db/builder/Mysql.php index 10c8d1dba..136b0dee0 100644 --- a/vendor/topthink/think-orm/src/db/builder/Mysql.php +++ b/vendor/topthink/think-orm/src/db/builder/Mysql.php @@ -89,7 +89,7 @@ class Mysql extends Builder $this->parsePartition($query, $options['partition']), $this->parseDistinct($query, $options['distinct']), $this->parseExtra($query, $options['extra']), - $this->parseField($query, $options['field']), + $this->parseField($query, $options['field'] ?? '*'), $this->parseJoin($query, $options['join']), $this->parseWhere($query, $options['where']), $this->parseGroup($query, $options['group']), @@ -155,7 +155,7 @@ class Mysql extends Builder $bind = $query->getFieldsBindType(); // 获取合法的字段 - if ('*' == $options['field']) { + if (empty($options['field']) || '*' == $options['field']) { $allowFields = array_keys($bind); } else { $allowFields = $options['field']; diff --git a/vendor/topthink/think-orm/src/model/concern/Attribute.php b/vendor/topthink/think-orm/src/model/concern/Attribute.php index 737e29d3e..8f6f918de 100644 --- a/vendor/topthink/think-orm/src/model/concern/Attribute.php +++ b/vendor/topthink/think-orm/src/model/concern/Attribute.php @@ -100,12 +100,6 @@ trait Attribute */ private $get = []; - /** - * 修改器执行记录 - * @var array - */ - private $set = []; - /** * 动态获取器 * @var array @@ -363,10 +357,6 @@ trait Attribute { $name = $this->getRealFieldName($name); - if (isset($this->set[$name])) { - return; - } - // 检测修改器 $method = 'set' . Str::studly($name) . 'Attr'; @@ -375,10 +365,12 @@ trait Attribute $value = $this->$method($value, array_merge($this->data, $data)); - $this->set[$name] = true; if (is_null($value) && $array !== $this->data) { return; } + } elseif (isset($this->type[$name])) { + // 类型转换 + $value = $this->writeTransform($value, $this->type[$name]); } // 设置数据对象属性 @@ -512,6 +504,11 @@ trait Attribute } $value = $this->$method($value, $this->data); + } elseif (isset($this->type[$fieldName])) { + // 类型转换 + $value = $this->readTransform($value, $this->type[$fieldName]); + } elseif ($this->autoWriteTimestamp && in_array($fieldName, [$this->createTime, $this->updateTime])) { + $value = $this->getTimestampValue($value); } elseif ($relation) { $value = $this->getRelationValue($relation); // 保存关联对象值 @@ -523,40 +520,6 @@ trait Attribute return $value; } - /** - * 读取数据类型处理 - * @access protected - * @return void - */ - protected function readDataType(): void - { - foreach ($this->data as $key => $value) { - if (isset($this->type[$key])) { - $this->get[$key] = $this->readTransform($value, $this->type[$key]); - } elseif ($this->autoWriteTimestamp && in_array($key, [$this->createTime, $this->updateTime])) { - $this->get[$key] = $this->getTimestampValue($value); - } - } - } - - /** - * 写入数据类型处理 - * @access protected - * @param array $data 数据 - * @return array - */ - protected function writeDataType(array $data): array - { - foreach ($data as $name => &$value) { - if (isset($this->type[$name])) { - // 类型转换 - $value = $this->writeTransform($value, $this->type[$name]); - } - } - - return $data; - } - /** * 获取JSON字段属性值 * @access protected diff --git a/vendor/topthink/think-orm/src/model/concern/RelationShip.php b/vendor/topthink/think-orm/src/model/concern/RelationShip.php index f3da1c401..33c1b890e 100644 --- a/vendor/topthink/think-orm/src/model/concern/RelationShip.php +++ b/vendor/topthink/think-orm/src/model/concern/RelationShip.php @@ -136,7 +136,7 @@ trait RelationShip public function relationQuery(array $relations, array $withRelationAttr = []): void { foreach ($relations as $key => $relation) { - $subRelation = ''; + $subRelation = []; $closure = null; if ($relation instanceof Closure) { @@ -161,7 +161,7 @@ trait RelationShip $relationResult->withAttr($withRelationAttr[$relationName]); } - $this->relation[$relation] = $relationResult->getRelation($subRelation, $closure); + $this->relation[$relation] = $relationResult->getRelation((array) $subRelation, $closure); } } @@ -810,19 +810,20 @@ trait RelationShip /** * 自动关联数据删除(支持一对一及一对多关联) * @access protected + * @param bool $force 强制删除 * @return void */ - protected function autoRelationDelete(): void + protected function autoRelationDelete($force = false): void { foreach ($this->relationWrite as $key => $name) { $name = is_numeric($key) ? $name : $key; $result = $this->getRelation($name, true); if ($result instanceof Model) { - $result->delete(); + $result->force($force)->delete(); } elseif ($result instanceof Collection) { foreach ($result as $model) { - $model->delete(); + $model->force($force)->delete(); } } } diff --git a/vendor/topthink/think-orm/src/model/concern/SoftDelete.php b/vendor/topthink/think-orm/src/model/concern/SoftDelete.php index ce5d392ea..5a9a56dc2 100644 --- a/vendor/topthink/think-orm/src/model/concern/SoftDelete.php +++ b/vendor/topthink/think-orm/src/model/concern/SoftDelete.php @@ -107,9 +107,10 @@ trait SoftDelete return false; } - $name = $this->getDeleteTimeField(); + $name = $this->getDeleteTimeField(); + $force = $this->isForce(); - if ($name && !$this->isForce()) { + if ($name && !$force) { // 软删除 $this->set($name, $this->autoWriteTimestamp($name)); @@ -131,7 +132,7 @@ trait SoftDelete // 关联删除 if (!empty($this->relationWrite)) { - $this->autoRelationDelete(); + $this->autoRelationDelete($force); } $this->trigger('AfterDelete'); diff --git a/vendor/topthink/think-orm/src/model/relation/MorphOne.php b/vendor/topthink/think-orm/src/model/relation/MorphOne.php index 6789c761f..bc89c0ba1 100644 --- a/vendor/topthink/think-orm/src/model/relation/MorphOne.php +++ b/vendor/topthink/think-orm/src/model/relation/MorphOne.php @@ -41,6 +41,12 @@ class MorphOne extends Relation */ protected $type; + /** + * 绑定的关联属性 + * @var array + */ + protected $bindAttr = []; + /** * 构造函数 * @access public @@ -78,6 +84,11 @@ class MorphOne extends Relation $relationModel = $this->query->relation($subRelation)->find(); if ($relationModel) { + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($this->parent, $relationModel); + } + $relationModel->setParent(clone $this->parent); } @@ -154,7 +165,13 @@ class MorphOne extends Relation $relationModel->exists(true); } - $result->setRelation($relation, $relationModel); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($result, $relationModel); + } else { + // 设置关联属性 + $result->setRelation($relation, $relationModel); + } } } } @@ -188,7 +205,13 @@ class MorphOne extends Relation $relationModel = null; } - $result->setRelation($relation, $relationModel); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($result, $relationModel); + } else { + // 设置关联属性 + $result->setRelation($relation, $relationModel); + } } } @@ -277,4 +300,48 @@ class MorphOne extends Relation } } + /** + * 绑定关联表的属性到父模型属性 + * @access public + * @param array $attr 要绑定的属性列表 + * @return $this + */ + public function bind(array $attr) + { + $this->bindAttr = $attr; + + return $this; + } + + /** + * 获取绑定属性 + * @access public + * @return array + */ + public function getBindAttr(): array + { + return $this->bindAttr; + } + + /** + * 绑定关联属性到父模型 + * @access protected + * @param Model $result 父模型对象 + * @param Model $model 关联模型对象 + * @return void + * @throws Exception + */ + protected function bindAttr(Model $result, Model $model = null): void + { + foreach ($this->bindAttr as $key => $attr) { + $key = is_numeric($key) ? $attr : $key; + $value = $result->getOrigin($key); + + if (!is_null($value)) { + throw new Exception('bind attr has exists:' . $key); + } + + $result->setAttr($key, $model ? $model->$attr : null); + } + } } diff --git a/vendor/zoujingli/think-library/src/service/ProcessService.php b/vendor/zoujingli/think-library/src/service/ProcessService.php index 86e7e199e..fcec6b7a7 100644 --- a/vendor/zoujingli/think-library/src/service/ProcessService.php +++ b/vendor/zoujingli/think-library/src/service/ProcessService.php @@ -104,13 +104,14 @@ class ProcessService extends Service /** * 查询相关进程列表 * @param string $command 任务指令 + * @param string $name 执行名称 * @return array */ - public function query(string $command): array + public function query(string $command, $name = 'php.exe'): array { $list = []; if ($this->iswin()) { - $lines = $this->exec('wmic process where name="php.exe" get processid,CommandLine', true); + $lines = $this->exec('wmic process where name="' . $name . '" get processid,CommandLine', true); foreach ($lines as $line) if ($this->_issub($line, $command) !== false) { $attr = explode(' ', $this->_space($line)); $list[] = ['pid' => array_pop($attr), 'cmd' => join(' ', $attr)];