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 @@
{foreach name="statusList" item="vo"} - + {/foreach}
- +
+
@@ -40,17 +40,16 @@
- +
- +
+
@@ -68,6 +67,5 @@
\ No newline at end of file diff --git a/application/admin/view/workers/worker/index.html b/application/admin/view/workers/worker/index.html index 09cb7b2..87d4ae8 100644 --- a/application/admin/view/workers/worker/index.html +++ b/application/admin/view/workers/worker/index.html @@ -20,7 +20,6 @@ {:__('Add')} {:__('Edit')} {:__('Delete')} - {:__('Recycle bin')} + +
+
+ +
+ +
+

重置

+
+
+
request->token(); } + + public function getSelectAreaCode($area_code){ + if (strlen($area_code) != 6){ + return $area_code; + } + $chunks = str_split($area_code, 2); + $res = $chunks[0]; + + if ($chunks[2] == '00'){ + if ($chunks[1] != '00'){ + $res .= $chunks[1]; + } + }else{ + $res .= $chunks[1] . $chunks[2]; + } + return $res; + + } } diff --git a/public/assets/js/backend/workers/worker.js b/public/assets/js/backend/workers/worker.js index f09ba4c..321cb43 100644 --- a/public/assets/js/backend/workers/worker.js +++ b/public/assets/js/backend/workers/worker.js @@ -53,15 +53,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','jstree'], function ($ {field: 'star', title: __('Star'), operate:'BETWEEN'}, {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, - {field: 'delete_time', title: __('Delete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); + $("#c-city").on("cp:updated", function() { + var citypicker = $(this).data("citypicker"); + var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province"); + table.bootstrapTable('refresh',{query: {area_code: code}}); + }); + $("#reset").on("click", function() { + $("#c-city").citypicker('reset'); + table.bootstrapTable('refresh'); + }); // 为表格绑定事件 Table.api.bindevent(table); + Form.events.citypicker($("form")); }, add: function () { $("#c-city").on("cp:updated", function() {