mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改通用更新方法where兼容新版本TP规则
This commit is contained in:
parent
3a6eeb4f54
commit
f930700255
@ -95,18 +95,18 @@ class DataService
|
||||
{
|
||||
$request = app('request');
|
||||
$db = is_string($dbQuery) ? Db::name($dbQuery) : $dbQuery;
|
||||
list($pk, $table) = [$db->getPk(), $db->getTable()];
|
||||
list($pk, $table, $map) = [$db->getPk(), $db->getTable(), []];
|
||||
list($field, $value) = [$request->post('field', ''), $request->post('value', '')];
|
||||
$where[] = [empty($pk) ? 'id' : $pk, 'in', explode(',', $request->post('id', ''))];
|
||||
$map[] = [empty($pk) ? 'id' : $pk, 'in', explode(',', $request->post('id', ''))];
|
||||
// 删除模式,如果存在 is_deleted 字段使用软删除
|
||||
if ($field === 'delete') {
|
||||
if (method_exists($db, 'getTableFields') && in_array('is_deleted', $db->getTableFields())) {
|
||||
return Db::table($table)->where($where)->update(['is_deleted' => '1']) !== false;
|
||||
return Db::table($table)->where($where)->where($map)->update(['is_deleted' => '1']) !== false;
|
||||
}
|
||||
return Db::table($table)->where($where)->delete() !== false;
|
||||
return Db::table($table)->where($where)->where($map)->delete() !== false;
|
||||
}
|
||||
// 更新模式,更新指定字段内容
|
||||
return Db::table($table)->where($where)->update([$field => $value]) !== false;
|
||||
return Db::table($table)->where($where)->where($map)->update([$field => $value]) !== false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user