feature: 复制

This commit is contained in:
zhuyu 2025-06-05 15:53:36 +08:00
parent 665d273459
commit 65fe19b15a
3 changed files with 142 additions and 0 deletions

View File

@ -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()
{

View File

@ -0,0 +1,38 @@
<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" data-rule="required" data-source="auth/admin/norightselectpage" 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" 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 $groupedItems as $groupName => $group}
<div class="form-group" style="border-top: 1px solid #ddd; padding-top: 10px; margin-top: 20px;">
<label class="control-label col-xs-12 col-sm-2 text-left" style="font-weight: bold;">{$groupName}</label>
</div>
{foreach $group as $index => $item}
{if $index % 2 == 0}<div class="form-group">{/if}
<label class="control-label col-xs-12 col-sm-1">{$item.name}:</label>
<div class="col-xs-12 col-sm-4">
<input class="form-control" step="0.01" name="row[item_{$item.id}]" type="number" value="{$row['item_' . $item.id]|htmlentities}">
</div>
{if $index % 2 == 1 || $index == count($group) - 1}</div>{/if}
{/foreach}
{/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>

View File

@ -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]"));