From 65fe19b15a8c68ebd4730bc6cfb1e77bae6d0cbe Mon Sep 17 00:00:00 2001 From: zhuyu Date: Thu, 5 Jun 2025 15:53:36 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/salary/CustomDetail.php | 83 +++++++++++++++++++ .../admin/view/salary/custom_detail/copy.html | 38 +++++++++ .../assets/js/backend/salary/custom_detail.js | 21 +++++ 3 files changed, 142 insertions(+) create mode 100644 application/admin/view/salary/custom_detail/copy.html diff --git a/application/admin/controller/salary/CustomDetail.php b/application/admin/controller/salary/CustomDetail.php index c72856a..5c65b6d 100644 --- a/application/admin/controller/salary/CustomDetail.php +++ b/application/admin/controller/salary/CustomDetail.php @@ -314,6 +314,89 @@ class CustomDetail extends Backend $this->success(); } + public function copy($ids = null) + { + + 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,type')->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; + } + + $typeMap = [ + 1 => '应发工资', + 2 => '应扣款项', + 3 => '其他' + ]; + $groupedItems = []; + foreach ($items as $item) { + $type = $item['type']; + $label = $typeMap[$type]; + $groupedItems[$label][] = $item; + } + + $this->view->assign('groupedItems', $groupedItems); + $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); + + Db::name('salary_status')->insert([ + 'target_admin_id' => $targetAdminId, + 'salary_month' => $month, + 'settle_status' => 0, + 'create_status' => 1, + ]); + + $this->success(); + } + public function settle() { diff --git a/application/admin/view/salary/custom_detail/copy.html b/application/admin/view/salary/custom_detail/copy.html new file mode 100644 index 0000000..70bcd0c --- /dev/null +++ b/application/admin/view/salary/custom_detail/copy.html @@ -0,0 +1,38 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ {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} + + + + +
diff --git a/public/assets/js/backend/salary/custom_detail.js b/public/assets/js/backend/salary/custom_detail.js index 869dbb7..ea3ca7f 100644 --- a/public/assets/js/backend/salary/custom_detail.js +++ b/public/assets/js/backend/salary/custom_detail.js @@ -62,6 +62,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin return true; } }, + { + name: 'copy', + text: '复制', + title: '复制', + classname: 'btn btn-xs btn-warning btn-dialog', + icon: 'fa fa-copy', + url: function (row) { + // 注意这里拼接 admin_id 和 month + return 'salary/custom_detail/copy?target_admin_id=' + row.target_admin_id + '&month=' + row.month; + }, + extend: 'data-area=\'["800px", "600px"]\'', + visible:function(row){ + if (!Config.manage) { + return false; + } + return true; + } + }, { name: 'complete', text:"结算", @@ -117,6 +135,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin edit: function () { Controller.api.bindevent(); }, + copy: function () { + Controller.api.bindevent(); + }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]"));