fix: 修改批量更新的方法名称

This commit is contained in:
邹景立 2025-02-21 12:36:24 +08:00
parent 352f13a4d3
commit 287951f7e3
3 changed files with 30 additions and 2 deletions

View File

@ -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));
}
}

View File

@ -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];

View File

@ -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);