diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php index 8db3d76..6805edc 100644 --- a/application/admin/controller/workers/Worker.php +++ b/application/admin/controller/workers/Worker.php @@ -79,17 +79,16 @@ class Worker extends Backend return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - - $list = $this->model + $area_code = request()->get('area_code'); + $build = $this->model ->with(['area']) ->where($where) - ->order($sort, $order) - ->paginate($limit); - - foreach ($list as $row) { - - + ->order($sort, $order); + if ($area_code){ + $build->where('area_id','like',$this->getSelectAreaCode($area_code).'%'); } + $list = $build + ->paginate($limit); $result = array("total" => $list->total(), "rows" => $list->items()); diff --git a/application/admin/lang/zh-cn/workers/worker.php b/application/admin/lang/zh-cn/workers/worker.php index 4899002..bc87f02 100644 --- a/application/admin/lang/zh-cn/workers/worker.php +++ b/application/admin/lang/zh-cn/workers/worker.php @@ -16,5 +16,6 @@ return [ 'Star' => '信用(5星制)', 'Create_time' => '创建时间', 'Update_time' => '更新时间', - 'Deletetime' => '删除时间' + 'Deletetime' => '删除时间', + 'Area.short_merge_name' => '区域' ]; diff --git a/application/admin/model/BaseModel.php b/application/admin/model/BaseModel.php new file mode 100644 index 0000000..d424958 --- /dev/null +++ b/application/admin/model/BaseModel.php @@ -0,0 +1,57 @@ +getTable()} ({$columnList}) VALUES " . implode(', ', array_fill(0, count($chunk), $placeholders)); + // 将数据展开填充 + $values = []; + foreach ($chunk as $row) { + $values = array_merge($values, array_values($row)); + } + Db::execute($sql,$values); + } + + Db::commit(); + return $totalInserted; + + } catch (Exception $e) { + Db::rollback(); + throw new Exception('批量插入失败:' . $e->getMessage()); + } + } +} diff --git a/application/admin/model/Worker.php b/application/admin/model/Worker.php index ef829e6..e5f554e 100644 --- a/application/admin/model/Worker.php +++ b/application/admin/model/Worker.php @@ -2,13 +2,10 @@ namespace app\admin\model; -use Exception; -use think\Db; -use think\Model; use traits\model\SoftDelete; -class Worker extends Model +class Worker extends BaseModel { use SoftDelete; @@ -50,59 +47,7 @@ class Worker extends Model public function area() { - return $this->belongsTo('Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0); - } - - - /** - * 批量插入数据到数据库 - * - * @param string $table 数据表名 - * @param array $data 待插入的数据 - * @param int $batchSize 每次插入的数据量(默认 500) - * @return int 成功插入的总行数 - * @throws Exception 插入失败时抛出异常 - */ - function batchInsert( array $data, int $batchSize = 500): int - { - if (empty($data)) { - throw new Exception('插入数据不能为空'); - } - - // 提取字段名(确保所有数据的字段一致) - $columns = array_keys($data[0]); - $columnList = implode(', ', $columns); - $placeholders = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')'; - - $totalInserted = 0; - - Db::startTrans(); - try { - // 数据分批插入 - foreach (array_chunk($data, $batchSize) as $chunk) { - $sql = "INSERT INTO {$this->getTable()} ({$columnList}) VALUES " . implode(', ', array_fill(0, count($chunk), $placeholders)); - $stmt = $this->prepare($sql); - - // 将数据展开填充 - $values = []; - foreach ($chunk as $row) { - $values = array_merge($values, array_values($row)); - } - - if ($stmt->execute($values)) { - $totalInserted += $stmt->rowCount(); - } else { - throw new Exception('批量插入失败'); - } - } - - Db::commit(); - return $totalInserted; - - } catch (Exception $e) { - Db::rollback(); - throw new Exception('批量插入失败:' . $e->getMessage()); - } + return $this->belongsTo('Area', 'area_id', 'area_code'); } } diff --git a/application/admin/model/WorkerItem.php b/application/admin/model/WorkerItem.php index 2d3068a..82a89c1 100644 --- a/application/admin/model/WorkerItem.php +++ b/application/admin/model/WorkerItem.php @@ -3,57 +3,11 @@ namespace app\admin\model; use think\Db; -use think\Model; -use traits\model\SoftDelete; -class WorkerItem extends Model +class WorkerItem extends BaseModel { // 表名 protected $name = 'worker_item'; - - /** - * 批量插入数据到数据库 - * - * @param string $table 数据表名 - * @param array $data 待插入的数据 - * @param int $batchSize 每次插入的数据量(默认 500) - * @return int 成功插入的总行数 - * @throws Exception 插入失败时抛出异常 - */ - function batchInsert( array $data, int $batchSize = 500): int - { - if (empty($data)) { - throw new Exception('插入数据不能为空'); - } - - // 提取字段名(确保所有数据的字段一致) - $columns = array_keys($data[0]); - $columnList = implode(', ', $columns); - $placeholders = '(' . implode(', ', array_fill(0, count($columns), '?')) . ')'; - - $totalInserted = 0; - - Db::startTrans(); - try { - // 数据分批插入 - foreach (array_chunk($data, $batchSize) as $chunk) { - $sql = "INSERT INTO {$this->getTable()} ({$columnList}) VALUES " . implode(', ', array_fill(0, count($chunk), $placeholders)); - // 将数据展开填充 - $values = []; - foreach ($chunk as $row) { - $values = array_merge($values, array_values($row)); - } - Db::execute($sql,$values); - } - - Db::commit(); - return $totalInserted; - - } catch (Exception $e) { - Db::rollback(); - throw new Exception('批量插入失败:' . $e->getMessage()); - } - } } diff --git a/application/admin/view/workers/worker/edit.html b/application/admin/view/workers/worker/edit.html index dd3b50e..d1c51f4 100644 --- a/application/admin/view/workers/worker/edit.html +++ b/application/admin/view/workers/worker/edit.html @@ -21,15 +21,15 @@