Skip to content

Commit c915421

Browse files
committed
fix: 修改批量更新的方法名称
1 parent c58419d commit c915421

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/Model.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace think\admin;
2020

2121
use think\admin\helper\QueryHelper;
22+
use think\db\Express;
2223

2324
/**
2425
* 基础模型类
@@ -107,11 +108,38 @@ public function __call($method, $args)
107108
* @param string $method 方法名称
108109
* @param array $args 调用参数
109110
* @return mixed|false|integer|QueryHelper
111+
* @throws \think\db\exception\DbException
110112
*/
111113
public static function __callStatic($method, $args)
112114
{
113115
return QueryHelper::make(static::class, $method, $args, function ($method, $args) {
114116
return parent::__callStatic($method, $args);
115117
});
116118
}
119+
120+
121+
/**
122+
* 字段值增长
123+
* @param string $field 字段名
124+
* @param float $step 增长值
125+
* @param int $lazyTime 延迟时间(秒)
126+
* @return $this
127+
*/
128+
public function inc(string $field, float $step = 1, int $lazyTime = 0)
129+
{
130+
return $this->set($field, new Express('+', $step, $lazyTime));
131+
}
132+
133+
/**
134+
* 字段值减少.
135+
*
136+
* @param string $field 字段名
137+
* @param float $step 增长值
138+
* @param int $lazyTime 延迟时间(秒)
139+
* @return $this
140+
*/
141+
public function dec(string $field, float $step = 1, int $lazyTime = 0)
142+
{
143+
return $this->set($field, new Express('-', $step, $lazyTime));
144+
}
117145
}

src/helper/QueryHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public static function make($model, string $method = 'init', array $args = [], ?
386386
'mSave' => [SaveHelper::class, 'init'],
387387
'mQuery' => [QueryHelper::class, 'init'],
388388
'mDelete' => [DeleteHelper::class, 'init'],
389-
'mUpdate' => [SystemService::class, 'batchUpdate'],
389+
'mUpdate' => [SystemService::class, 'update'],
390390
];
391391
if (isset($hooks[$method])) {
392392
[$class, $method] = $hooks[$method];

src/service/SystemService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static function save($query, array &$data, string $key = 'id', $map = [])
186186
* @return boolean|integer 失败返回 false, 成功返回主键值或 true
187187
* @throws \think\admin\Exception
188188
*/
189-
public static function batchUpdate($query, array $data, string $key = 'id', $map = [])
189+
public static function update($query, array $data, string $key = 'id', $map = [])
190190
{
191191
try {
192192
$query = Helper::buildQuery($query)->master()->strict(false)->where($map);

0 commit comments

Comments
 (0)