feature: 工资管理
This commit is contained in:
parent
10fcccf53a
commit
c7ee06d512
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
30
application/admin/view/salary/detail/custom_edit.html
Normal file
30
application/admin/view/salary/detail/custom_edit.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Target_admin_id')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input id="c-target_admin_id" readonly="readonly" data-rule="required" data-source="auth/admin/selectpage" data-field="nickname" class="form-control selectpage" name="row[target_admin_id]" type="text" value="{$row.target_admin_id|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Salary_month')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input id="c-salary_month" readonly="readonly" class="form-control datetimepicker" data-date-format="YYYY-MM" data-use-current="true" name="row[salary_month]" type="text" value="{$row.salary_month|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
{foreach $items as $item}
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{$item['name']}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input id="c-item_value" class="form-control" step="0.01" name="row[item_{$item['id']}]" type="number" value="{$row['item_' . $item.id]|htmlentities}">
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
|
||||
<div class="form-group layer-footer">
|
||||
<label class="control-label col-xs-12 col-sm-2"></label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
60
application/admin/view/salary/detail/custom_index.html
Normal file
60
application/admin/view/salary/detail/custom_index.html
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<div class="panel panel-default panel-intro">
|
||||
{:build_heading()}
|
||||
|
||||
|
||||
<textarea id="salaryitem" name="salaryitem" class="form-control" cols="30" rows="5" style="display:none;">{$salaryitem}</textarea>
|
||||
|
||||
|
||||
<div class="panel-body">
|
||||
<div id="myTabContent" class="tab-content">
|
||||
<div class="tab-pane fade active in" id="one">
|
||||
<div class="widget-body no-padding">
|
||||
<div id="toolbar" class="toolbar">
|
||||
|
||||
</div>
|
||||
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
|
||||
width="100%">
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script id="customformtpl" type="text/html">
|
||||
<!--form表单必须添加form-commsearch这个类-->
|
||||
<form action="" class="form-commonsearch">
|
||||
<div style="border-radius:2px;margin-bottom:10px;background:#f5f5f5;padding:15px 20px;">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6 col-md-3" style="min-height:68px;">
|
||||
<!--这里添加68px是为了避免刷新时出现元素错位闪屏-->
|
||||
<div class="form-group">
|
||||
<label class="control-label">时间范围</label>
|
||||
<!-- 指定这个字段是 month,操作符为 = -->
|
||||
<input type="hidden" class="operate" data-name="month" value="="/>
|
||||
<div>
|
||||
<input id="c-month"
|
||||
class="form-control datetimepicker"
|
||||
data-date-format="YYYY-MM"
|
||||
data-use-current="true"
|
||||
name="month"
|
||||
type="text"
|
||||
value="{:date('Y-m')}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6 col-md-3">
|
||||
<div class="form-group">
|
||||
<label class="control-label"></label>
|
||||
<div class="row">
|
||||
<div class="col-xs-6">
|
||||
<input type="submit" class="btn btn-success btn-block" value="查询"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</script>
|
||||
|
||||
|
|
@ -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();
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user