From f4f6f431ac34b7cfd11e82ce74838da9a0e7e6e8 Mon Sep 17 00:00:00 2001 From: yin5th <541304803@qq.com> Date: Sat, 14 Jan 2023 11:36:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=90=8E=E5=8F=B0):=20=E5=B7=A5=E8=B5=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8F=91=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/manager/Pay.php | 82 ++++++++++++++++++++++++++++- public/static/manager/js/pay/pay.js | 52 ++++++++++++++++-- view/manager/pay/edit.html | 16 ++++-- 3 files changed, 143 insertions(+), 7 deletions(-) diff --git a/app/controller/manager/Pay.php b/app/controller/manager/Pay.php index a575a56..db99c0a 100644 --- a/app/controller/manager/Pay.php +++ b/app/controller/manager/Pay.php @@ -29,7 +29,7 @@ use think\response\View; */ class Pay extends Base { - protected $noNeedLogin = ['getAccountList', 'list']; + protected $noNeedLogin = ['getAccountList', 'list', 'listModify', 'payAll']; /** * 详情 @@ -144,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, '非法请求'); + } + /** * 列表 * @@ -380,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, '操作错误'); + } } \ No newline at end of file diff --git a/public/static/manager/js/pay/pay.js b/public/static/manager/js/pay/pay.js index 6d69c4e..ca1cfd0 100644 --- a/public/static/manager/js/pay/pay.js +++ b/public/static/manager/js/pay/pay.js @@ -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' @@ -289,13 +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: 'paid_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; + } + } + }); } }); \ No newline at end of file diff --git a/view/manager/pay/edit.html b/view/manager/pay/edit.html index 4c11ac8..e622a3e 100644 --- a/view/manager/pay/edit.html +++ b/view/manager/pay/edit.html @@ -33,9 +33,9 @@
- - - +
@@ -62,4 +62,14 @@ + + + + + + + \ No newline at end of file