From 10fcccf53a1d271edd9d354634269b7a09b4e3e9 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Wed, 28 May 2025 17:30:03 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feature:=20=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/salary/Detail.php | 84 +++++++++++++++++++ application/admin/controller/salary/Item.php | 37 ++++++++ .../admin/lang/zh-cn/salary/detail.php | 12 +++ application/admin/lang/zh-cn/salary/item.php | 10 +++ application/admin/model/salary/Detail.php | 40 +++++++++ application/admin/model/salary/Item.php | 40 +++++++++ application/admin/validate/salary/Detail.php | 27 ++++++ application/admin/validate/salary/Item.php | 27 ++++++ application/admin/view/salary/detail/add.html | 45 ++++++++++ .../admin/view/salary/detail/custom_add.html | 30 +++++++ .../admin/view/salary/detail/edit.html | 45 ++++++++++ .../admin/view/salary/detail/index.html | 29 +++++++ application/admin/view/salary/item/add.html | 33 ++++++++ application/admin/view/salary/item/edit.html | 33 ++++++++ application/admin/view/salary/item/index.html | 29 +++++++ public/assets/js/backend/salary/detail.js | 60 +++++++++++++ public/assets/js/backend/salary/item.js | 55 ++++++++++++ 17 files changed, 636 insertions(+) create mode 100644 application/admin/controller/salary/Detail.php create mode 100644 application/admin/controller/salary/Item.php create mode 100644 application/admin/lang/zh-cn/salary/detail.php create mode 100644 application/admin/lang/zh-cn/salary/item.php create mode 100644 application/admin/model/salary/Detail.php create mode 100644 application/admin/model/salary/Item.php create mode 100644 application/admin/validate/salary/Detail.php create mode 100644 application/admin/validate/salary/Item.php create mode 100644 application/admin/view/salary/detail/add.html create mode 100644 application/admin/view/salary/detail/custom_add.html create mode 100644 application/admin/view/salary/detail/edit.html create mode 100644 application/admin/view/salary/detail/index.html create mode 100644 application/admin/view/salary/item/add.html create mode 100644 application/admin/view/salary/item/edit.html create mode 100644 application/admin/view/salary/item/index.html create mode 100644 public/assets/js/backend/salary/detail.js create mode 100644 public/assets/js/backend/salary/item.js diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php new file mode 100644 index 0000000..51a5472 --- /dev/null +++ b/application/admin/controller/salary/Detail.php @@ -0,0 +1,84 @@ +model = new \app\admin\model\salary\Detail; + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + public function custom_add() + { + + if (false === $this->request->isPost()) { + + $items = Db::name('salary_item')->field('id,name')->select(); + + $this->view->assign('items', $items); + return $this->view->fetch(); + } + + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + + + $month = $params['salary_month'] . '-01'; + $targetAdminId = $params['target_admin_id']; + $salaryDetails = []; + + foreach ($params as $k => $v) { + if (!str_contains($k, 'item')) { + continue; + } + $salaryDetails[] = [ + 'target_admin_id' => $targetAdminId, + 'salary_month' => $month, + 'item_id' => explode('_', $k)[1], + 'item_value' => $v, + ]; + } + + Db::name('salary_detail') + ->where('salary_month', $month) + ->where('target_admin_id', $targetAdminId) + ->delete(); + + Db::name('salary_detail') + ->insertAll($salaryDetails); + + $this->success(); + } + + +} diff --git a/application/admin/controller/salary/Item.php b/application/admin/controller/salary/Item.php new file mode 100644 index 0000000..0d57c6c --- /dev/null +++ b/application/admin/controller/salary/Item.php @@ -0,0 +1,37 @@ +model = new \app\admin\model\salary\Item; + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + +} diff --git a/application/admin/lang/zh-cn/salary/detail.php b/application/admin/lang/zh-cn/salary/detail.php new file mode 100644 index 0000000..2eff1d4 --- /dev/null +++ b/application/admin/lang/zh-cn/salary/detail.php @@ -0,0 +1,12 @@ + 'ID', + 'Admin_id' => '创建人id', + 'Target_admin_id' => '工资归属人id', + 'Item_id' => '指标id', + 'Item_value' => '值', + 'Salary_month' => '工资月份', + 'Create_time' => '创建时间', + 'Update_time' => '编辑时间' +]; diff --git a/application/admin/lang/zh-cn/salary/item.php b/application/admin/lang/zh-cn/salary/item.php new file mode 100644 index 0000000..86306f6 --- /dev/null +++ b/application/admin/lang/zh-cn/salary/item.php @@ -0,0 +1,10 @@ + 'ID', + 'Admin_id' => '创建人id', + 'Name' => '名称', + 'Desc' => '描述', + 'Create_time' => '创建时间', + 'Update_time' => '编辑时间' +]; diff --git a/application/admin/model/salary/Detail.php b/application/admin/model/salary/Detail.php new file mode 100644 index 0000000..3ea3b25 --- /dev/null +++ b/application/admin/model/salary/Detail.php @@ -0,0 +1,40 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/validate/salary/Item.php b/application/admin/validate/salary/Item.php new file mode 100644 index 0000000..55dbc8a --- /dev/null +++ b/application/admin/validate/salary/Item.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/salary/detail/add.html b/application/admin/view/salary/detail/add.html new file mode 100644 index 0000000..90fed35 --- /dev/null +++ b/application/admin/view/salary/detail/add.html @@ -0,0 +1,45 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/salary/detail/custom_add.html b/application/admin/view/salary/detail/custom_add.html new file mode 100644 index 0000000..74b4e6a --- /dev/null +++ b/application/admin/view/salary/detail/custom_add.html @@ -0,0 +1,30 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ {foreach $items as $item} +
+ +
+ +
+
+ {/foreach} + + +
diff --git a/application/admin/view/salary/detail/edit.html b/application/admin/view/salary/detail/edit.html new file mode 100644 index 0000000..1231b38 --- /dev/null +++ b/application/admin/view/salary/detail/edit.html @@ -0,0 +1,45 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/salary/detail/index.html b/application/admin/view/salary/detail/index.html new file mode 100644 index 0000000..5b1d72d --- /dev/null +++ b/application/admin/view/salary/detail/index.html @@ -0,0 +1,29 @@ +
+ {:build_heading()} + +
+
+
+ +
+ +
+
+
diff --git a/application/admin/view/salary/item/add.html b/application/admin/view/salary/item/add.html new file mode 100644 index 0000000..3c707d4 --- /dev/null +++ b/application/admin/view/salary/item/add.html @@ -0,0 +1,33 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/salary/item/edit.html b/application/admin/view/salary/item/edit.html new file mode 100644 index 0000000..f10a18e --- /dev/null +++ b/application/admin/view/salary/item/edit.html @@ -0,0 +1,33 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/salary/item/index.html b/application/admin/view/salary/item/index.html new file mode 100644 index 0000000..81ae368 --- /dev/null +++ b/application/admin/view/salary/item/index.html @@ -0,0 +1,29 @@ +
+ {:build_heading()} + +
+
+
+ +
+ +
+
+
diff --git a/public/assets/js/backend/salary/detail.js b/public/assets/js/backend/salary/detail.js new file mode 100644 index 0000000..c8ad599 --- /dev/null +++ b/public/assets/js/backend/salary/detail.js @@ -0,0 +1,60 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'salary/detail/index' + location.search, + add_url: 'salary/detail/add', + edit_url: 'salary/detail/edit', + del_url: 'salary/detail/del', + multi_url: 'salary/detail/multi', + import_url: 'salary/detail/import', + table: 'salary_detail', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'admin_id', title: __('Admin_id')}, + {field: 'target_admin_id', title: __('Target_admin_id')}, + {field: 'item_id', title: __('Item_id')}, + {field: 'item_value', title: __('Item_value'), operate:'BETWEEN'}, + {field: 'salary_month', title: __('Salary_month'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {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: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + custom_add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); diff --git a/public/assets/js/backend/salary/item.js b/public/assets/js/backend/salary/item.js new file mode 100644 index 0000000..6ab151e --- /dev/null +++ b/public/assets/js/backend/salary/item.js @@ -0,0 +1,55 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'salary/item/index' + location.search, + add_url: 'salary/item/add', + edit_url: 'salary/item/edit', + del_url: 'salary/item/del', + multi_url: 'salary/item/multi', + import_url: 'salary/item/import', + table: 'salary_item', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'admin_id', title: __('Admin_id')}, + {field: 'name', title: __('Name'), operate: 'LIKE'}, + {field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {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: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); From c7ee06d512d90ff40c9aba155fe99abf30bd0d7d Mon Sep 17 00:00:00 2001 From: zhuyu Date: Thu, 29 May 2025 11:57:45 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feature:=20=E5=B7=A5=E8=B5=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/salary/Detail.php | 153 ++++++++++++++++++ .../admin/view/salary/detail/custom_edit.html | 30 ++++ .../view/salary/detail/custom_index.html | 60 +++++++ public/assets/js/backend/salary/detail.js | 76 +++++++++ 4 files changed, 319 insertions(+) create mode 100644 application/admin/view/salary/detail/custom_edit.html create mode 100644 application/admin/view/salary/detail/custom_index.html diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php index 51a5472..9cf2acd 100644 --- a/application/admin/controller/salary/Detail.php +++ b/application/admin/controller/salary/Detail.php @@ -36,6 +36,93 @@ class Detail extends Backend * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ + public function custom_index() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + + $items = Db::name('salary_item')->field('id,name')->select(); + + + $month = date('Y-m-01'); + + + + if ($this->request->isAjax()) { + + + $filter = $this->request->param('filter'); + $filter = json_decode($filter, true); + + if (!empty($filter['month'])) { + $month = $filter['month'] . '-01'; + } + + $res = []; + + if (!$this->auth->isSuperAdmin()) { + $admins = Db::name('admin')->where('id', $this->auth->id)->field('id,nickname')->select(); + } else{ + $admins = Db::name('admin')->field('id,nickname')->select(); + } + + $admins = array_column($admins, NULL, 'id'); + $adminIds = array_keys($admins); + + $adminNames = array_column($admins, 'nickname', 'id'); + + $builder = $this->model + ->where('salary_month', '=', $month); + if (!$this->auth->isSuperAdmin()) { + $builder = $builder->where('target_admin_id', $this->auth->id); + } + + $queryData = $builder->select(); + $queryRes = []; + foreach ($queryData as $queryDatum) { + $targetAdminId = $queryDatum['target_admin_id']; + $itemId = $queryDatum['item_id']; + $queryRes[$targetAdminId][$itemId] = $queryDatum['item_value']; + } + + + foreach ($adminIds as $adminId) { + foreach ($items as $item) { + + $res[$adminId]['admin_id'] = $adminId; + $res[$adminId]['name'] = $adminNames[$adminId]; + $res[$adminId]['month'] = $month; + + $itemKey = 'item_' . $item['id']; + + if (isset($queryRes[$adminId][$item['id']])) { + $res[$adminId][$itemKey] = $this->clean_number($queryRes[$adminId][$item['id']]); + continue; + } + + $res[$adminId][$itemKey] = 0; + } + } + + $res = array_values($res); + + $result = array("total" => count($res), "rows" => $res); + + return json($result); + } + + + $this->view->assign("month", $month); + $this->view->assign("salaryitem", json_encode($items)); + return $this->view->fetch(); + } + + public function clean_number($num): string { + return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.'); + } + public function custom_add() { @@ -81,4 +168,70 @@ class Detail extends Backend } + public function custom_edit() + { + + if (false === $this->request->isPost()) { + + + $targetAdminId = $this->request->get('target_admin_id'); + $month = $this->request->get('month'); + + $row['salary_month'] = $month; + $row['target_admin_id'] = $targetAdminId; + + + $queryData = $this->model + ->where('salary_month', '=', $month) + ->where('target_admin_id', $targetAdminId) + ->select(); + $items = Db::name('salary_item')->field('id,name')->select(); + $queryData = array_column($queryData, NULL, 'item_id'); + + foreach ($items as $item) { + $itemKey = 'item_' . $item['id']; + $row[$itemKey] = !empty($queryData[$item['id']]) ? $queryData[$item['id']]['item_value'] : 0; + } + + + $items = Db::name('salary_item')->field('id,name')->select(); + $this->view->assign('items', $items); + $this->view->assign('row', $row); + return $this->view->fetch(); + } + + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + + + $month = $params['salary_month'] . '-01'; + $targetAdminId = $params['target_admin_id']; + $salaryDetails = []; + + foreach ($params as $k => $v) { + if (!str_contains($k, 'item')) { + continue; + } + $salaryDetails[] = [ + 'target_admin_id' => $targetAdminId, + 'salary_month' => $month, + 'item_id' => explode('_', $k)[1], + 'item_value' => $v, + ]; + } + + Db::name('salary_detail') + ->where('salary_month', $month) + ->where('target_admin_id', $targetAdminId) + ->delete(); + + Db::name('salary_detail') + ->insertAll($salaryDetails); + + $this->success(); + } + + } diff --git a/application/admin/view/salary/detail/custom_edit.html b/application/admin/view/salary/detail/custom_edit.html new file mode 100644 index 0000000..ed6f0c8 --- /dev/null +++ b/application/admin/view/salary/detail/custom_edit.html @@ -0,0 +1,30 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ {foreach $items as $item} +
+ +
+ +
+
+ {/foreach} + + +
diff --git a/application/admin/view/salary/detail/custom_index.html b/application/admin/view/salary/detail/custom_index.html new file mode 100644 index 0000000..0a72b00 --- /dev/null +++ b/application/admin/view/salary/detail/custom_index.html @@ -0,0 +1,60 @@ +
+ {:build_heading()} + + + + + +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+ + diff --git a/public/assets/js/backend/salary/detail.js b/public/assets/js/backend/salary/detail.js index c8ad599..0ddfda8 100644 --- a/public/assets/js/backend/salary/detail.js +++ b/public/assets/js/backend/salary/detail.js @@ -41,12 +41,88 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // 为表格绑定事件 Table.api.bindevent(table); }, + custom_index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'salary/detail/custom_index' + location.search, + // add_url: 'oa/schedule/add', + // editable: 'oa/schedule/editable', + // del_url: 'oa/schedule/del', + // multi_url: 'oa/schedule/multi', + // import_url: 'oa/schedule/import', + table: 'salary', + } + }); + + var table = $("#table"); + + var defaultColumnArr = []; + defaultColumnArr.push({ + "title":"用户名", + "field":"name", + },{ + "title":"用户id", + "field":"admin_id", + "visible":false + }); + + + // 获取后端传入的字段定义(JSON 字符串) + + var columnJson = $('#salaryitem').val(); + var rawColumns = JSON.parse(columnJson); + rawColumns.forEach(function (item) { + // 可以加入格式化、样式控制等逻辑 + defaultColumnArr.push({ + field: 'item_' + item.id, + title: item.name, + }); + }); + + defaultColumnArr.push({ + field: 'operate', + title: __('Operate'), + table: table, + buttons: [ + { + name: 'custom_edit', + text: '编辑', + title: '编辑薪资', + classname: 'btn btn-xs btn-success btn-dialog', + icon: 'fa fa-edit', + url: function (row) { + // 注意这里拼接 admin_id 和 month + return 'salary/detail/custom_edit?target_admin_id=' + row.admin_id + '&month=' + row.month; + }, + extend: 'data-area=\'["800px", "600px"]\'', + } + ], + events: Table.api.events.operate, + formatter: Table.api.formatter.operate + }); + + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + columns: defaultColumnArr, + searchFormVisible: true, + searchFormTemplate: 'customformtpl', + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, add: function () { Controller.api.bindevent(); }, custom_add: function () { Controller.api.bindevent(); }, + custom_edit: function () { + Controller.api.bindevent(); + }, edit: function () { Controller.api.bindevent(); }, From 60960debe74f08ba53d83c72a934d5ba3c4f3ea0 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Thu, 29 May 2025 14:48:47 +0800 Subject: [PATCH 3/6] =?UTF-8?q?feature:=20=E5=B7=A5=E8=B5=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/salary/Detail.php | 34 ++++++++++++++++--- public/assets/js/backend/salary/detail.js | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php index 9cf2acd..7a0ac7f 100644 --- a/application/admin/controller/salary/Detail.php +++ b/application/admin/controller/salary/Detail.php @@ -43,13 +43,29 @@ class Detail extends Backend //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - $items = Db::name('salary_item')->field('id,name')->select(); + $items = Db::name('salary_item')->field('id,attr,name')->select(); + $salaryItem = []; + foreach ($items as $item) { + $idAttr[$item['id']] = $item['attr']; + if ($item['attr'] == 'JXKHJL') { + $salaryItem[] = [ + 'id' => 'jx_total', + 'name' => '绩效提成', + ]; + } + $salaryItem[] = [ + 'id' => 'item_' . $item['id'], + 'name' => $item['name'], + ]; + } + $salaryItem[] = [ + 'id' => 'total', + 'name' => '总计', + ]; $month = date('Y-m-01'); - - if ($this->request->isAjax()) { @@ -89,6 +105,7 @@ class Detail extends Backend foreach ($adminIds as $adminId) { + $attrValue = []; foreach ($items as $item) { $res[$adminId]['admin_id'] = $adminId; @@ -99,11 +116,20 @@ class Detail extends Backend if (isset($queryRes[$adminId][$item['id']])) { $res[$adminId][$itemKey] = $this->clean_number($queryRes[$adminId][$item['id']]); + $attrValue[$idAttr[$item['id']]] = $queryRes[$adminId][$item['id']]; continue; } + $attrValue[$item['attr']] = 0; $res[$adminId][$itemKey] = 0; } + + + $jxTotal = ($attrValue['ZWJX'] - $attrValue['YYCB']) * $attrValue['TD']; + + $res[$adminId]['jx_total'] = $this->clean_number($jxTotal); + $res[$adminId]['total'] = $this->clean_number(($attrValue['JBGZ'] + $attrValue['JBBZ'] + $attrValue['GWJT'] + $jxTotal + $attrValue['JXKHJL'] + $attrValue['QQ']) + - ($attrValue['SBJ'] + $attrValue['BX'] + $attrValue['KK'] + $attrValue['CDWDK'])); } $res = array_values($res); @@ -115,7 +141,7 @@ class Detail extends Backend $this->view->assign("month", $month); - $this->view->assign("salaryitem", json_encode($items)); + $this->view->assign("salaryitem", json_encode($salaryItem)); return $this->view->fetch(); } diff --git a/public/assets/js/backend/salary/detail.js b/public/assets/js/backend/salary/detail.js index 0ddfda8..8605e5d 100644 --- a/public/assets/js/backend/salary/detail.js +++ b/public/assets/js/backend/salary/detail.js @@ -75,7 +75,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin rawColumns.forEach(function (item) { // 可以加入格式化、样式控制等逻辑 defaultColumnArr.push({ - field: 'item_' + item.id, + field: item.id, title: item.name, }); }); From 448e878813e3bdbcff02df09a3e8780f58a94a90 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Thu, 29 May 2025 15:30:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feature:=20=E5=B7=A5=E8=B5=84=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/salary/Detail.php | 37 +++++++++++++++---- .../admin/view/salary/detail/custom_edit.html | 20 +++++++--- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php index 7a0ac7f..fcbdd29 100644 --- a/application/admin/controller/salary/Detail.php +++ b/application/admin/controller/salary/Detail.php @@ -43,7 +43,7 @@ class Detail extends Backend //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - $items = Db::name('salary_item')->field('id,attr,name')->select(); + $items = Db::name('salary_item')->field('id,attr,type,name')->select(); $salaryItem = []; foreach ($items as $item) { @@ -106,6 +106,7 @@ class Detail extends Backend foreach ($adminIds as $adminId) { $attrValue = []; + $total = 0; foreach ($items as $item) { $res[$adminId]['admin_id'] = $adminId; @@ -114,9 +115,10 @@ class Detail extends Backend $itemKey = 'item_' . $item['id']; - if (isset($queryRes[$adminId][$item['id']])) { + if (!empty($queryRes[$adminId][$item['id']])) { $res[$adminId][$itemKey] = $this->clean_number($queryRes[$adminId][$item['id']]); $attrValue[$idAttr[$item['id']]] = $queryRes[$adminId][$item['id']]; + $total = $this->calc_total($total, $item['type'], $queryRes[$adminId][$item['id']]); continue; } @@ -124,12 +126,9 @@ class Detail extends Backend $res[$adminId][$itemKey] = 0; } - $jxTotal = ($attrValue['ZWJX'] - $attrValue['YYCB']) * $attrValue['TD']; - $res[$adminId]['jx_total'] = $this->clean_number($jxTotal); - $res[$adminId]['total'] = $this->clean_number(($attrValue['JBGZ'] + $attrValue['JBBZ'] + $attrValue['GWJT'] + $jxTotal + $attrValue['JXKHJL'] + $attrValue['QQ']) - - ($attrValue['SBJ'] + $attrValue['BX'] + $attrValue['KK'] + $attrValue['CDWDK'])); + $res[$adminId]['total'] = $this->clean_number($total + $jxTotal); } $res = array_values($res); @@ -145,6 +144,17 @@ class Detail extends Backend return $this->view->fetch(); } + public function calc_total($total, $type, $value){ + if ($type == 1) { + return $total + $value; + } + if ($type == 2) { + return $total - $value; + } + + return $total; + } + public function clean_number($num): string { return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.'); } @@ -211,7 +221,7 @@ class Detail extends Backend ->where('salary_month', '=', $month) ->where('target_admin_id', $targetAdminId) ->select(); - $items = Db::name('salary_item')->field('id,name')->select(); + $items = Db::name('salary_item')->field('id,name,type')->select(); $queryData = array_column($queryData, NULL, 'item_id'); foreach ($items as $item) { @@ -219,8 +229,19 @@ class Detail extends Backend $row[$itemKey] = !empty($queryData[$item['id']]) ? $queryData[$item['id']]['item_value'] : 0; } + $typeMap = [ + 1 => '应发工资', + 2 => '应扣款项', + 3 => '其他' + ]; + $groupedItems = []; + foreach ($items as $item) { + $type = $item['type']; + $label = $typeMap[$type]; + $groupedItems[$label][] = $item; + } - $items = Db::name('salary_item')->field('id,name')->select(); + $this->view->assign('groupedItems', $groupedItems); $this->view->assign('items', $items); $this->view->assign('row', $row); return $this->view->fetch(); diff --git a/application/admin/view/salary/detail/custom_edit.html b/application/admin/view/salary/detail/custom_edit.html index ed6f0c8..9696b96 100644 --- a/application/admin/view/salary/detail/custom_edit.html +++ b/application/admin/view/salary/detail/custom_edit.html @@ -12,14 +12,22 @@ - {foreach $items as $item} -
- -
- -
+ {foreach $groupedItems as $groupName => $group} +
+
+ + {foreach $group as $index => $item} + {if $index % 2 == 0}
{/if} + +
+ +
+ {if $index % 2 == 1 || $index == count($group) - 1}
{/if} {/foreach} + {/foreach} + +
- {foreach $items as $item} -
- -
- -
+ {foreach $groupedItems as $groupName => $group} +
+
+ + {foreach $group as $index => $item} + {if $index % 2 == 0}
{/if} + +
+ +
+ {if $index % 2 == 1 || $index == count($group) - 1}
{/if} + {/foreach} {/foreach}