From 287951f7e34d075038d9b98861754321372899d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Fri, 21 Feb 2025 12:36:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E6=96=B9=E6=B3=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/Model.php | 28 +++++++++++++++++++ .../think-library/src/helper/QueryHelper.php | 2 +- .../src/service/SystemService.php | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugin/think-library/src/Model.php b/plugin/think-library/src/Model.php index 0acf08869..d5e9d6727 100644 --- a/plugin/think-library/src/Model.php +++ b/plugin/think-library/src/Model.php @@ -19,6 +19,7 @@ declare (strict_types=1); namespace think\admin; use think\admin\helper\QueryHelper; +use think\db\Express; /** * 基础模型类 @@ -107,6 +108,7 @@ abstract class Model extends \think\Model * @param string $method 方法名称 * @param array $args 调用参数 * @return mixed|false|integer|QueryHelper + * @throws \think\db\exception\DbException */ public static function __callStatic($method, $args) { @@ -114,4 +116,30 @@ abstract class Model extends \think\Model return parent::__callStatic($method, $args); }); } + + + /** + * 字段值增长 + * @param string $field 字段名 + * @param float $step 增长值 + * @param int $lazyTime 延迟时间(秒) + * @return $this + */ + public function inc(string $field, float $step = 1, int $lazyTime = 0) + { + return $this->set($field, new Express('+', $step, $lazyTime)); + } + + /** + * 字段值减少. + * + * @param string $field 字段名 + * @param float $step 增长值 + * @param int $lazyTime 延迟时间(秒) + * @return $this + */ + public function dec(string $field, float $step = 1, int $lazyTime = 0) + { + return $this->set($field, new Express('-', $step, $lazyTime)); + } } diff --git a/plugin/think-library/src/helper/QueryHelper.php b/plugin/think-library/src/helper/QueryHelper.php index 46fa860e4..f075e4094 100644 --- a/plugin/think-library/src/helper/QueryHelper.php +++ b/plugin/think-library/src/helper/QueryHelper.php @@ -386,7 +386,7 @@ class QueryHelper extends Helper 'mSave' => [SaveHelper::class, 'init'], 'mQuery' => [QueryHelper::class, 'init'], 'mDelete' => [DeleteHelper::class, 'init'], - 'mUpdate' => [SystemService::class, 'batchUpdate'], + 'mUpdate' => [SystemService::class, 'update'], ]; if (isset($hooks[$method])) { [$class, $method] = $hooks[$method]; diff --git a/plugin/think-library/src/service/SystemService.php b/plugin/think-library/src/service/SystemService.php index 3f4dcc0f0..055f4e8fc 100644 --- a/plugin/think-library/src/service/SystemService.php +++ b/plugin/think-library/src/service/SystemService.php @@ -186,7 +186,7 @@ class SystemService extends Service * @return boolean|integer 失败返回 false, 成功返回主键值或 true * @throws \think\admin\Exception */ - public static function batchUpdate($query, array $data, string $key = 'id', $map = []) + public static function update($query, array $data, string $key = 'id', $map = []) { try { $query = Helper::buildQuery($query)->master()->strict(false)->where($map);