代码同步

This commit is contained in:
wong
2025-10-15 16:39:10 +08:00
parent d26e5a324d
commit db22100846
5 changed files with 166 additions and 76 deletions

View File

@@ -708,7 +708,7 @@ class AccountController extends BaseController
$deleteTime = isset($item['deleteTime']) ? strtotime($item['deleteTime']) : null;
$sqlData = [];
foreach ($data as $item) {
$sqlData[] = [
$rows[] = [
'id' => $item['id'],
'accountType' => isset($item['accountType']) ? $item['accountType'] : 0,
'status' => isset($item['status']) ? $item['status'] : 0,
@@ -733,9 +733,28 @@ class AccountController extends BaseController
];
}
// 拆分插入/更新:按主键 id 判断
$ids = array_column($rows, 'id');
$existingIds = CompanyAccountModel::whereIn('id', $ids)->column('id');
$existSet = array_flip($existingIds);
// 使用tenantId作为唯一性判断
$account = new CompanyAccountModel();
$account->saveAll($account);
$toInsert = [];
$toUpdate = [];
foreach ($rows as $r) {
if (isset($existSet[$r['id']])) $toUpdate[] = $r; else $toInsert[] = $r;
}
$changed = false;
if (!empty($toInsert)) {
$m = new CompanyAccountModel();
$m->insertAll($toInsert, true); // 允许外部主键
$changed = true;
}
if (!empty($toUpdate)) {
$m = new CompanyAccountModel();
$res = $m->saveAll($toUpdate);
if ($res) $changed = true;
}
return $changed;
}
}