feature: 结算按钮

This commit is contained in:
zhuyu 2025-05-30 10:13:20 +08:00
parent 94c3b86d1c
commit 3487f07a2c
2 changed files with 79 additions and 4 deletions

View File

@ -103,13 +103,24 @@ class Detail extends Backend
$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]['admin_id'] = $adminId;
$res[$adminId]['target_admin_id'] = $adminId;
$res[$adminId]['name'] = $adminNames[$adminId];
$res[$adminId]['month'] = $month;
@ -132,6 +143,7 @@ class Detail extends Backend
$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);
@ -297,4 +309,38 @@ class Detail extends Backend
}
public function settle()
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$targetAdminId = $this->request->get('target_admin_id');
$month = $this->request->get('month');
$settle = Db::name('salary_settle')
->where('salary_month', $month)
->where('target_admin_id', $targetAdminId)
->field('target_admin_id,salary_month')->find();
if (!empty($settle)) {
Db::name('salary_settle')
->where('salary_month', $month)
->where('target_admin_id', $targetAdminId)
->save([
'settle_status' => 1,
]);
$this->success();
}
Db::name('salary_settle')->insert([
'target_admin_id' => $targetAdminId,
'salary_month' => $month,
'settle_status' => 1,
]);
$this->success();
}
}

View File

@ -87,15 +87,44 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{
name: 'custom_edit',
text: '编辑',
title: '编辑薪资',
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;
return 'salary/detail/custom_edit?target_admin_id=' + row.target_admin_id + '&month=' + row.month;
},
extend: 'data-area=\'["800px", "600px"]\'',
}
},
{
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) {
//返回true时按钮显示,返回false隐藏
if (row.settle_status != 1) {
return true;
}
return false;
}
},
],
events: Table.api.events.operate,
formatter: Table.api.formatter.operate