From a339bdf316bd5326b22995e9526da830f3840426 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Wed, 4 Jun 2025 09:29:26 +0800 Subject: [PATCH] feature: auth --- application/admin/controller/oa/Schedule.php | 147 ---------- .../admin/controller/salary/Detail.php | 258 ------------------ .../admin/view/oa/schedule/custom_index.html | 52 ---- .../admin/view/salary/detail/custom_add.html | 36 --- .../admin/view/salary/detail/custom_edit.html | 38 --- .../view/salary/detail/custom_index.html | 66 ----- public/assets/js/backend/oa/schedule.js | 138 ---------- public/assets/js/backend/salary/detail.js | 116 -------- 8 files changed, 851 deletions(-) delete mode 100644 application/admin/view/oa/schedule/custom_index.html delete mode 100644 application/admin/view/salary/detail/custom_add.html delete mode 100644 application/admin/view/salary/detail/custom_edit.html delete mode 100644 application/admin/view/salary/detail/custom_index.html diff --git a/application/admin/controller/oa/Schedule.php b/application/admin/controller/oa/Schedule.php index 184095c..d4955db 100644 --- a/application/admin/controller/oa/Schedule.php +++ b/application/admin/controller/oa/Schedule.php @@ -72,98 +72,6 @@ class Schedule extends Backend return $this->view->fetch(); } - public function custom_index() - { - //当前是否为关联查询 - $this->relationSearch = true; - //设置过滤方法 - $this->request->filter(['strip_tags', 'trim']); - if ($this->request->isAjax()) { - - - $filter = $this->request->param('filter'); - $filter = json_decode($filter, true); - - $startDate = date('Y-m-01'); - $endDate = date('Y-m-t'); - - if (isset($filter['timetype']) && $filter['timetype'] == 2) { - $startDate = date('Y-m-d', strtotime('monday this week')); - $endDate = date('Y-m-d', strtotime('sunday this week')); - } - - $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'); - - $tmpDate = $startDate; - $dates = []; - while(true) { - - if ($tmpDate > $endDate) { - break; - } - - foreach ($adminIds as $adminId) { - $res[$adminId][$tmpDate] = '无'; - $res[$adminId]['admin_id'] = $adminId; - $res[$adminId]['name'] = $adminNames[$adminId]; - $res[$adminId]['editable'] = $this->auth->check('oa/schedule/custom_edit') ? 1 : 0; - } - - $dates[] = $tmpDate; - $tmpDate = date('Y-m-d', strtotime($tmpDate) + 86400); - } - - $builder = $this->model - ->with([ - 'admin' - ]) - ->where('date', '>=', $startDate) - ->where('date', '<=', $endDate); - - if (!$this->auth->isSuperAdmin()) { - $builder = $builder->where('exec_admin_id', $this->auth->id); - } - - $queryData = $builder->select(); - foreach ($queryData as $queryDatum) { - $queryDatum = $queryDatum->toArray(); - - $adminId = $queryDatum['admin']['id']; - $date = $queryDatum['date']; - $type = $queryDatum['type']; - - if (isset($res[$adminId][$date])) { - $res[$adminId][$date] = $this->model->getTypeList()[$type]; - } - } - - - $res = array_values($res); - - $result = array("total" => count($res), "rows" => $res); - - return json($result); - } - - $timeType = [ - 1 => '本月排班', - 2 => '本周排班', - ]; - $this->view->assign("timetype", $timeType); - return $this->view->fetch(); - } - /** * 添加 * @@ -262,59 +170,4 @@ class Schedule extends Backend } $this->success(); } - - - public function editable() - { - - $params = $this->request->post('row/a'); - if (empty($params)) { - $this->error(__('Parameter %s can not be empty', '')); - } - - - $date = $params['field']; - $adminId = $params['admin_id']; - - $value = $params[$date] ?? '无'; - $valueMap = [ - '无' => 0, - '早班' => 1, - '中班' => 2, - '晚班' => 3, - '行政班' => 4, - ]; - - if ($value == '无') { - $this->model->where('exec_admin_id', $adminId)->delete(); - $this->success(); - } - - $dbValue = $valueMap[$value]; - - $data = $this->model - ->where('date', '=', $date) - ->where('exec_admin_id', '=', $adminId) - ->find(); - - $nowTime = date('Y-m-d H:i:s'); - if (!empty($data)) { - $data->save([ - "date" => $date, - "exec_admin_id" => $adminId, - "type" => $dbValue, - "update_time" => $nowTime, - ]); - } - - $this->model->insert([ - "date" => $date, - "exec_admin_id" => $adminId, - "type" => $dbValue, - "create_time" => $nowTime, - "update_time" => $nowTime, - ]); - - $this->success(); - } } diff --git a/application/admin/controller/salary/Detail.php b/application/admin/controller/salary/Detail.php index 0f909de..745ce72 100644 --- a/application/admin/controller/salary/Detail.php +++ b/application/admin/controller/salary/Detail.php @@ -36,130 +36,6 @@ 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,attr,type,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()) { - - - $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']; - } - - $querySettleData = Db::name('salary_settle') - ->whereIn('target_admin_id', $adminIds) - ->where('salary_month', '=', $month) - ->field('id,target_admin_id,settle_status') - ->select(); - $querySettleRes = []; - foreach ($querySettleData as $querySettleDatum) { - $targetAdminId = $querySettleDatum['target_admin_id']; - $querySettleRes[$targetAdminId] = $querySettleDatum['settle_status']; - } - - - foreach ($adminIds as $adminId) { - $attrValue = []; - $total = 0; - foreach ($items as $item) { - - $res[$adminId]['target_admin_id'] = $adminId; - $res[$adminId]['name'] = $adminNames[$adminId]; - $res[$adminId]['month'] = $month; - - $itemKey = 'item_' . $item['id']; - - $value = 0; - - if (!empty($queryRes[$adminId][$item['id']])) { - $value = $this->clean_number($queryRes[$adminId][$item['id']]); - $total = $this->calc_total($total, $item['type'], $queryRes[$adminId][$item['id']]); - } - - $attrValue[$item['attr']] = $value; - if ($item['attr'] == 'TD') { - $value = $value . '%'; - } - $res[$adminId][$itemKey] = $value; - } - - $jxTotal = ($attrValue['ZWJX'] - $attrValue['YYCB']) * $attrValue['TD'] / 100; - $res[$adminId]['jx_total'] = $this->clean_number($jxTotal); - $res[$adminId]['total'] = $this->clean_number($total + $jxTotal); - $res[$adminId]['settle_status'] = $querySettleRes[$adminId] ?? 0; - } - - $res = array_values($res); - - $result = array("total" => count($res), "rows" => $res); - - - return json($result); - } - - $this->assignconfig("manage", $this->auth->check('salary/detail/custom_edit')); - $this->view->assign("month", $month); - $this->view->assign("salaryitem", json_encode($salaryItem)); - return $this->view->fetch(); - } - public function calc_total($total, $type, $value){ if ($type == 1) { return $total + $value; @@ -175,140 +51,6 @@ class Detail extends Backend return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.'); } - public function custom_add() - { - - if (false === $this->request->isPost()) { - - $items = Db::name('salary_item')->field('id,type,name')->select(); - - $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); - 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(); - } - - - 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,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); - - $this->success(); - } - public function settle() { diff --git a/application/admin/view/oa/schedule/custom_index.html b/application/admin/view/oa/schedule/custom_index.html deleted file mode 100644 index 9b6bbbb..0000000 --- a/application/admin/view/oa/schedule/custom_index.html +++ /dev/null @@ -1,52 +0,0 @@ -
- {:build_heading()} - -
-
-
-
-
- -
- -
-
-
- -
-
-
- diff --git a/application/admin/view/salary/detail/custom_add.html b/application/admin/view/salary/detail/custom_add.html deleted file mode 100644 index 25e6326..0000000 --- a/application/admin/view/salary/detail/custom_add.html +++ /dev/null @@ -1,36 +0,0 @@ -
- -
- -
- -
-
-
- -
- -
-
- {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/application/admin/view/salary/detail/custom_edit.html b/application/admin/view/salary/detail/custom_edit.html deleted file mode 100644 index 5a2ad7b..0000000 --- a/application/admin/view/salary/detail/custom_edit.html +++ /dev/null @@ -1,38 +0,0 @@ -
- -
- -
- -
-
-
- -
- -
-
- {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/application/admin/view/salary/detail/custom_index.html b/application/admin/view/salary/detail/custom_index.html deleted file mode 100644 index 83776f6..0000000 --- a/application/admin/view/salary/detail/custom_index.html +++ /dev/null @@ -1,66 +0,0 @@ -
- {:build_heading()} - - - - - -
-
-
-
-
- - {:__('Add')} - - - - - -
- -
-
-
- -
-
-
- - diff --git a/public/assets/js/backend/oa/schedule.js b/public/assets/js/backend/oa/schedule.js index 777dd23..79aee53 100644 --- a/public/assets/js/backend/oa/schedule.js +++ b/public/assets/js/backend/oa/schedule.js @@ -39,144 +39,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function // 为表格绑定事件 Table.api.bindevent(table); }, - custom_index: function () { - // 初始化表格参数配置 - Table.api.init({ - extend: { - index_url: 'oa/schedule/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: 'schedule', - } - }); - - var table = $("#table"); - - var defaultColumnArr = []; - defaultColumnArr.push({ - "title":"用户名", - "field":"name", - },{ - "title":"用户id", - "field":"admin_id", - "visible":false - }); - - const startDate = new Date(); - startDate.setDate(1); - startDate.setHours(0, 0, 0, 0); - - const endDate = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0); - endDate.setHours(0, 0, 0, 0); - - for (let d = new Date(startDate); d <= endDate; ) { - const current = new Date(d); // 深拷贝 - const tmpDate = current.toLocaleDateString('sv-SE'); - - console.log('Current Date:', tmpDate); - defaultColumnArr.push({ - "title": tmpDate, - "field": tmpDate, - "editable" :{ - type: 'select', - pk: 1, - source: [ - {value: '无', text: '无'}, - {value: '早班', text: '早班'}, - {value: '中班', text: '中班'}, - {value: '晚班', text: '晚班'}, - {value: '行政班', text: '行政班'}, - ], - noeditFormatter: function (value, row, index) { - if (row.editable === 1) { - return false; - } else { - return value; - } - }, - } - }); - - d.setDate(d.getDate() + 1); // 最后再改 d 的值 - } - - // 初始化表格 - table.bootstrapTable({ - url: $.fn.bootstrapTable.defaults.extend.index_url, - columns: defaultColumnArr, - searchFormVisible: true, - searchFormTemplate: 'customformtpl', - }); - - // 为表格绑定事件 - Table.api.bindevent(table); - - $(document).on("click", ".btn-block", function () { - - let selectedValue = $('#c-flag').val(); - - let changeColumn = []; - if (selectedValue == 2) { - changeColumn = [{ - "title":"用户名", - "field":"name", - },{ - "title":"用户id", - "field":"admin_id", - "visible":false - }]; - - const today = new Date(); - const startDate = new Date(today.setDate(today.getDate() - today.getDay() + 1)); // 星期一 - const endDate = new Date(today.setDate(today.getDate() - today.getDay() + 7)); // 星期天 - - for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) { - let tmpDate = d.toISOString().split('T')[0]; // 使用 d,而不是 date - changeColumn.push({ - "title": tmpDate, - "field": tmpDate, - "editable" :{ - type: 'select', - pk: 1, - source: [ - {value: '无', text: '无'}, - {value: '早班', text: '早班'}, - {value: '中班', text: '中班'}, - {value: '晚班', text: '晚班'}, - {value: '行政班', text: '行政班'}, - ] - } - }); - } - - } else { - changeColumn = defaultColumnArr; - } - - var options = table.bootstrapTable('getOptions'); - var queryParams = options.queryParams; - options.queryParams = function (params) { - //这一行必须要存在,否则在点击下一页时会丢失搜索栏数据 - params = queryParams(params); - - var filter = params.filter ? JSON.parse(params.filter) : {}; - filter.timetype = selectedValue; - - params.filter = JSON.stringify(filter); - return params; - }; - - table.bootstrapTable('refreshOptions', { - columns: changeColumn, - }); - - $('#c-flag').val(selectedValue).change(); - return false; - }); - }, add: function () { Controller.api.bindevent(); }, diff --git a/public/assets/js/backend/salary/detail.js b/public/assets/js/backend/salary/detail.js index eebc6a8..7635019 100644 --- a/public/assets/js/backend/salary/detail.js +++ b/public/assets/js/backend/salary/detail.js @@ -41,125 +41,9 @@ 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: 'salary/detail/custom_add', - // 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":"target_admin_id", - "visible":false - }); - - - // 获取后端传入的字段定义(JSON 字符串) - - var columnJson = $('#salaryitem').val(); - var rawColumns = JSON.parse(columnJson); - rawColumns.forEach(function (item) { - // 可以加入格式化、样式控制等逻辑 - defaultColumnArr.push({ - field: 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.target_admin_id + '&month=' + row.month; - }, - extend: 'data-area=\'["800px", "600px"]\'', - visible:function(row){ - if (!Config.manage) { - return false; - } - return true; - } - }, - { - name: 'complete', - text:"结算", - title:"结算", - extend: 'data-toggle="tooltip" data-container="body"', - classname: 'btn btn-xs btn-success btn-magic btn-ajax', - icon: 'fa fa-cny', - url: function (row) { - // 注意这里拼接 admin_id 和 month - return 'salary/detail/settle?target_admin_id=' + row.target_admin_id + '&month=' + row.month; - }, - confirm: '确认结算?', - refresh: true, - success: function (data, ret) { - $("#table").bootstrapTable('refresh'); - return false; - }, - error: function (data, ret) { - Layer.alert(ret.msg); - return false; - }, - visible: function (row) { - if (!Config.manage) { - return false; - } - //返回true时按钮显示,返回false隐藏 - if (row.settle_status != 1) { - return true; - } - return false; - } - }, - ], - 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(); },