Compare commits

...

2 Commits

Author SHA1 Message Date
yin5th f4f6f431ac feat(后台): 工资部分发放 2023-01-14 11:36:48 +08:00
yin5th 36a61f46b6 fix: 1.后台工资统计 30% 2.离职变更状态完善 2023-01-14 10:38:36 +08:00
4 changed files with 153 additions and 11 deletions

View File

@ -792,6 +792,7 @@ class Manager extends Base
Account::whereIn('id', $accountIds)->where('role', Account::ROLE_WORKER)->update([
'role' => Account::ROLE_NORMAL,
'worksite_id' => Account::COMMON_OFF,
'checking' => Account::COMMON_OFF,
]);
return $this->json();
} catch (Exception $e) {

View File

@ -29,7 +29,7 @@ use think\response\View;
*/
class Pay extends Base
{
protected $noNeedLogin = ['getAccountList', 'list'];
protected $noNeedLogin = ['getAccountList', 'list', 'listModify', 'payAll'];
/**
* 详情
@ -74,12 +74,13 @@ class Pay extends Base
}
$all = PayMonthLog::where('account_id', $info['account_id'])->where('time', $info['time'])
->fieldRaw('sum(amount) as amount,sum(base_amount) as base_amount,sum(overtime_amount) as overtime_amount')
->fieldRaw('sum(amount) as amount,sum(base_amount) as base_amount,sum(overtime_amount) as overtime_amount,sum(paid_amount) as paid_amount')
->find();
$info['amount'] = $all['amount'];
$info['base_amount'] = $all['base_amount'];
$info['overtime_amount'] = $all['overtime_amount'];
$info['paid_amount'] = $all['paid_amount'];
if ($this->request->isPost()) {
$item = input('post.');
@ -143,6 +144,65 @@ class Pay extends Base
return $this->json(4000, '非法请求');
}
/**
* 工资详情中的单个字段编辑
*
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws Exception
*/
public function listModify(): Json
{
if ($this->request->isPost()) {
$item = input('post.');
$validate = $this->validateByApi($item, [
'field' => 'require',
'value' => 'require',
]);
if ($validate !== true) {
return $validate;
}
if (!$info = PayMonthLog::findById($item['id'])) {
return $this->json(4001, '记录不存在');
}
if ($item['field'] != 'paid_amount') {
return $this->json(4001, '该项不支持修改');
}
$update = [$item['field'] => (float) $item['value']];
if ($item['field'] == 'paid_amount') {
if ($item['value'] < 0) {
return $this->json(4001, '发放工资不能小于0');
}
if ($item['value'] > $info['amount']) {
return $this->json(4001, '发放工资不能大于总工资');
}
if ($item['value'] == $info['amount']) {
$update['status'] = 1;//全部发放
}
if ($item['value'] < $info['amount']) {
$update['status'] = 2;//部分发放
}
}
try {
$info->save($update);
return $this->json();
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
return $this->json(4000, '非法请求');
}
/**
* 列表
*
@ -379,4 +439,25 @@ class Pay extends Base
$this->data['positionList'] = $position;
return $this->view();
}
// 全部发放
public function payAll(): Json
{
if ($this->request->isPost()) {
$time = input('time/d', 0);
$accountId = input('user_id/d', 0);
if (!$time) {
return $this->json(4004, '参数错误');
}
PayMonthLog::where('time', $time)->where('account_id', $accountId)->update([
'status' => 1,
'paid_amount' => Db::raw('`amount`'),
]);
return $this->json();
}
return $this->json(4001, '操作错误');
}
}

View File

@ -45,8 +45,8 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'
page: true,
cols: [[
{type: 'checkbox'},
{field: 'id', minWidth: 80, title: '用户ID'},
{field: 'time_text', minWidth: 120, title: '月份'},
{field: 'id', minWidth: 80, title: '记录ID'},
{field: 'time_text', minWidth: 120, title: '时间'},
{field: 'nickname', minWidth: 80, title: '昵称'},
{field: 'real_name', minWidth: 100, title: '姓名'},
{field: 'mobile', minWidth: 120, title: '电话'},
@ -254,7 +254,7 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'
let listUrl = $('#table-container').data('url');
let insTb = table.render({
elem: '#table-container',
toolbar: '#toolbar-tpl',
toolbar: '#toolbar-tpl1',
defaultToolbar: ['filter', 'exports', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可
title: '搜索'
, layEvent: 'search'
@ -279,8 +279,8 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'
page: false,
cols: [[
{type: 'checkbox'},
{field: 'id', minWidth: 80, title: '用户ID'},
{field: 'time_text', minWidth: 120, title: '月份'},
{field: 'id', minWidth: 80, title: '记录ID'},
{field: 'time_text', minWidth: 120, title: '时间'},
{field: 'nickname', minWidth: 80, title: '昵称'},
// {field: 'real_name', minWidth: 100, title: '姓名'},
// {field: 'mobile', minWidth: 120, title: '电话'},
@ -289,12 +289,59 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'
{field: 'amount', minWidth: 100, title: '总计'},
{field: 'base_amount', minWidth: 100, title: '基本工资'},
{field: 'overtime_amount', minWidth: 100, title: '加班工资'},
{field: 'status_text', minWidth: 100, title: '状态'},
{field: 'paid_amount', minWidth: 100, title: '已发工资', edit: 'text'},
// {field: 'status_text', minWidth: 100, title: '状态'},
]],
done: function () {
Tools.setInsTb(insTb);
}
});
table.on('toolbar(table-container-filter)', function (obj) {
let layEvent = obj.event;
let insTb = Tools.getInsTb();
let url = $($(this).context).data('href')
// debugger;
switch (layEvent) {
// toolbar 刷新
case 'pay-all':
let index = layer.confirm('确认一件全部发放吗?此操作将下列所有工地工资全部发放', {
btn: ['确认', '取消'], //按钮
title: '操作提示',
}, function () {
$.post(url, function (res) {
layer.close(index)
layer.msg(res.msg)
if (res.code === 0) {
insTb.reload();
}
})
}, function () {
layer.close(index)
return false;
});
return false;
case 'refresh':
refreshTab(insTb);
return false;
// toolbar 搜索
case 'search':
let search = $('.table-search-fieldset');
if (search.hasClass('div-show')) {
search.css('display', 'none').removeClass('div-show');
} else {
search.css('display', 'block').addClass('div-show');
}
return false;
// 其他 默认为打开弹出层
default:
if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') {
openLayer(url, title, width, height);
return false;
}
}
});
}
});

View File

@ -33,8 +33,10 @@
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-block">
<input type="radio" name="status" value="0" title="待发放" {if $item.status == '0'} checked {/if}>
<input type="radio" name="status" value="1" title="已发放" {if $item.status == '1'} checked {/if}>
<input type="text" readonly class="layui-input" value="{if $item.amount == $item.paid_amount}{/if}
{if $item.paid_amount <= 0}待发放{/if}
{if $item.paid_amount > 0 && $item.paid_amount < $item.amount}部分发放{/if}">
</div>
</div>
@ -43,7 +45,8 @@
<div class="layui-form-item" style="margin-bottom: -20px;">
<label class="layui-form-label"></label>
<div class="layui-input-block">
<h3>{$item.time} 总计:{$item.amount} 基本工资:{$item.base_amount} 加班工资:{$item.overtime_amount}</h3>
<h3>【时间:{$item.time}】 【总计:{$item.amount}】 【基本工资:{$item.base_amount}】 【加班工资:{$item.overtime_amount}】 【已发工资:{$item.paid_amount}】</h3>
<h4 style="color: red"> 注:下列每条数据为工人在不同工地工作的工资,外层的工资列表是工人所有工地工资的汇总</h4>
</div>
</div>
@ -59,4 +62,14 @@
</div>
</div>
<!-- 隐藏列 -->
<!-- 编辑单元格提交url -->
<input type="hidden" id="row-modify" data-url="/manager/pay/list-modify">
<!-- toolbar -->
<script type="text/html" id="toolbar-tpl1">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-table-refresh lay-event="refresh"><i class="fa fa-refresh"></i></a>
<a class="layui-btn layui-btn-normal layui-btn-sm" data-href="/manager/pay/pay-all.html?time={$item.time ?? 0}&user_id={$item.account_id}" data-title="一键发放" lay-event="pay-all">全部发放</a>
</script>
<script src="__MANAGER__/js/pay/pay.js?v={:mt_rand()}"></script>