|
|
|
|
@ -242,16 +242,8 @@ class TeacherController extends BaseController
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
// 获取数据表的所有字段
|
|
|
|
|
$tableName = $this->model->getTable();
|
|
|
|
|
$existingColumns = (new CustomFormField)->getRowTableFieldsByComment($tableName);
|
|
|
|
|
// 过滤掉不存在的字段
|
|
|
|
|
$filteredRecords = array_map(function ($record) use ($existingColumns) {
|
|
|
|
|
return array_intersect_key($record, $existingColumns);
|
|
|
|
|
}, $records);
|
|
|
|
|
// 去除空数据
|
|
|
|
|
$filteredRecords = array_filter($filteredRecords);
|
|
|
|
|
// 分段导入
|
|
|
|
|
foreach ($filteredRecords as $item) {
|
|
|
|
|
foreach ($records as $item) {
|
|
|
|
|
$where = ['name' => $item['name']];
|
|
|
|
|
$data = [
|
|
|
|
|
'name' => $item['name'],
|
|
|
|
|
@ -263,7 +255,7 @@ class TeacherController extends BaseController
|
|
|
|
|
$this->model->firstOrCreate($where, $data);
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
return $this->success(['total' => count($records), 'filter_total' => count($filteredRecords)]);
|
|
|
|
|
return $this->success(['total' => count($records), 'filter_total' => count($records)]);
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
|
|
|
|