diff --git a/app/home/controller/Admin.php b/app/home/controller/Admin.php index a3cf4ac..7bb4b27 100644 --- a/app/home/controller/Admin.php +++ b/app/home/controller/Admin.php @@ -41,7 +41,7 @@ class Admin extends BaseController } $rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit']; $admin = AdminList::where($where) - ->order('create_time asc') + ->order('id desc') ->paginate($rows, false, ['query' => $param]) ->each(function ($item, $key) { $item->department = Db::name('Department')->where(['id' => $item->did])->value('title'); @@ -59,55 +59,13 @@ class Admin extends BaseController //添加 public function add() { - $id = empty(get_params('id')) ? 0 : get_params('id'); - $department = set_recursion(get_department()); - $position = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select(); - if ($id > 0) { - $detail = get_admin($id); - View::assign('detail', $detail); - } else { - //初始化密码 - $reg_pwd = set_salt(6); - View::assign('reg_pwd', $reg_pwd); - } - View::assign('department', $department); - View::assign('position', $position); - View::assign('id', $id); - return view(); - } - //生成头像 - public function to_avatars($char) - { - $defaultData = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'S', 'Y', 'Z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾', - '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'); - if (isset($char)) { - $Char = $char; - } else { - $Char = $defaultData[mt_rand(0, count($defaultData) - 1)]; - } - $OutputSize = min(512, empty($_GET['size']) ? 36 : intval($_GET['size'])); - - $Avatar = new MDAvatars($Char, 256, 1); - $avatar_name = '/avatars/avatar_256_' . set_salt(10) . time() . '.png'; - $path = get_config('filesystem.disks.public.url') . $avatar_name; - $res = $Avatar->Save('.' . $path, 256); - $Avatar->Free(); - return $path; - } - - //提交添加 - public function post_submit() - { + $param = get_params(); if (request()->isAjax()) { - $param = get_params(); - $param['entry_time'] = strtotime($param['entry_time']); - $param['nickname'] = $param['name']; - $pinyin = new Pinyin(); - $username = $pinyin->name($param['name'], PINYIN_UMLAUT_V); - $param['username'] = implode('', $username); + $param['entry_time'] = strtotime($param['entry_time']); + $param['nickname'] = $param['name']; + $pinyin = new Pinyin(); + $username = $pinyin->name($param['name'], PINYIN_UMLAUT_V); + $param['username'] = implode('', $username); if (!empty($param['id']) && $param['id'] > 0) { try { validate(AdminCheck::class)->scene('edit')->check($param); @@ -118,10 +76,10 @@ class Admin extends BaseController // 启动事务 Db::startTrans(); try { - $count = Db::name('Admin')->where([['username','=',$param['username']],['id','<>',$param['id']]])->count(); - if ($count > 0) { - $param['username'] = implode('', $username) . $count; - } + $count = Db::name('Admin')->where([['username', '=', $param['username']], ['id', '<>', $param['id']]])->count(); + if ($count > 0) { + $param['username'] = implode('', $username) . $count; + } Db::name('Admin')->where(['id' => $param['id']])->strict(false)->field(true)->update($param); if (!isset($param['thumb']) || $param['thumb'] == '') { $char = mb_substr($param['name'], 0, 1, 'utf-8'); @@ -145,10 +103,10 @@ class Admin extends BaseController // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } - $count = Db::name('Admin')->where('username', $param['username'])->count(); - if ($count > 0) { - $param['username'] = implode('', $username) . $count; - } + $count = Db::name('Admin')->where('username', $param['username'])->count(); + if ($count > 0) { + $param['username'] = implode('', $username) . $count; + } $param['salt'] = set_salt(20); $param['pwd'] = set_password($param['reg_pwd'], $param['salt']); // 启动事务 @@ -169,8 +127,46 @@ class Admin extends BaseController } } return to_assign(); + } else { + $id = isset($param['id']) ? $param['id'] : 0; + $department = set_recursion(get_department()); + $position = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select(); + if ($id > 0) { + $detail = get_admin($id); + View::assign('detail', $detail); + } else { + //初始化密码 + $reg_pwd = set_salt(6); + View::assign('reg_pwd', $reg_pwd); + } + View::assign('department', $department); + View::assign('position', $position); + View::assign('id', $id); + return view(); } } + //生成头像 + public function to_avatars($char) + { + $defaultData = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'S', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾', + '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'); + if (isset($char)) { + $Char = $char; + } else { + $Char = $defaultData[mt_rand(0, count($defaultData) - 1)]; + } + $OutputSize = min(512, empty($_GET['size']) ? 36 : intval($_GET['size'])); + + $Avatar = new MDAvatars($Char, 256, 1); + $avatar_name = '/avatars/avatar_256_' . set_salt(10) . time() . '.png'; + $path = get_config('filesystem.disks.public.url') . $avatar_name; + $res = $Avatar->Save('.' . $path, 256); + $Avatar->Free(); + return $path; + } //查看 public function view() diff --git a/app/home/controller/Expense.php b/app/home/controller/Expense.php new file mode 100644 index 0000000..2c3e585 --- /dev/null +++ b/app/home/controller/Expense.php @@ -0,0 +1,344 @@ +isAjax()) { + $cate = Db::name('ExpenseCate')->order('create_time asc')->select(); + return to_assign(0, '', $cate); + } else { + return view(); + } + } + //提交保存分类 + public function cate_add() + { + if (request()->isAjax()) { + $param = get_params(); + if (!empty($param['id']) && $param['id'] > 0) { + try { + validate(ExpenseCateCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $data['update_time'] = time(); + $res = ExpenseCate::strict(false)->field(true)->update($param); + if ($res) { + add_log('edit', $param['id'], $param); + } + return to_assign(); + } else { + try { + validate(ExpenseCateCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['create_time'] = time(); + $insertId = ExpenseCate::strict(false)->field(true)->insertGetId($param); + if ($insertId) { + add_log('add', $insertId, $param); + } + return to_assign(); + } + } + } + + public function get_list($param = [], $where = []) + { + $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; + $expense = ExpenseList::where($where) + ->order('create_time asc') + ->paginate($rows, false, ['query' => $param]) + ->each(function ($item, $key) { + $item->income_month = empty($item->income_month) ? '-' : date('Y-m', $item->income_month); + $item->expense_time = empty($item->expense_time) ? '-' : date('Y-m-d', $item->expense_time); + $item->user_name = Db::name('Admin')->where(['id' => $item->uid])->value('name'); + $item->admin_name = Db::name('Admin')->where(['id' => $item->admin_id])->value('name'); + $item->department = Db::name('Department')->where(['id' => $item->did])->value('title'); + $item->check_name = Db::name('Admin')->where(['id' => $item->check_admin_id])->value('name'); + $item->check_time = empty($item->check_time) ? '-' : date('Y-m-d H:i', $item->check_time); + $item->pay_name = Db::name('Admin')->where(['id' => $item->pay_admin_id])->value('name'); + $item->pay_time = empty($item->pay_time) ? '-' : date('Y-m-d H:i', $item->pay_time); + $item->amount = Db::name('ExpenseInterfix')->where(['exid' => $item->id])->sum('amount'); + }); + return $expense; + } + + public function detail($id = 0) + { + $expense = Db::name('Expense')->where(['id' => $id])->find(); + if ($expense) { + $expense['income_month'] = empty($expense['income_month']) ? '-' : date('Y-m', $expense['income_month']); + $expense['expense_time'] = empty($expense['expense_time']) ? '-' : date('Y-m-d', $expense['expense_time']); + $expense['user_name'] = Db::name('Admin')->where(['id' => $expense['uid']])->value('name'); + $expense['department'] = Db::name('Department')->where(['id' => $expense['did']])->value('title'); + $expense['amount'] = Db::name('ExpenseInterfix')->where(['exid' => $expense['id']])->sum('amount'); + + if ($expense['check_admin_id'] > 0) { + $expense['check_admin'] = Db::name('Admin')->where(['id' => $expense['check_admin_id']])->value('name'); + $expense['check_time'] = date('Y-m-d H:i:s', $expense['check_time']); + } + if ($expense['pay_admin_id'] > 0) { + $expense['pay_admin'] = Db::name('Admin')->where(['id' => $expense['pay_admin_id']])->value('name'); + $expense['pay_time'] = date('Y-m-d H:i:s', $expense['pay_time']); + } + $expense['list'] = Db::name('ExpenseInterfix') + ->field('a.*,c.title as cate_title') + ->alias('a') + ->join('ExpenseCate c', 'a.cate_id = c.id') + ->where(['a.exid' => $expense['id']]) + ->select(); + } + return $expense; + } + + public function index() + { + if (request()->isAjax()) { + $param = get_params(); + $where = []; + $where[] = ['status', '=', 1]; + //按时间检索 + $start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0; + $end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0; + if ($start_time > 0 && $end_time > 0) { + $where[] = ['expense_time', 'between', [$start_time, $end_time]]; + } + $expense = $this->get_list($param, $where); + return table_assign(0, '', $expense); + } else { + return view(); + } + } + + function list() { + if (request()->isAjax()) { + $param = get_params(); + $where = []; + $where[] = ['admin_id', '=', $this->uid]; + $where[] = ['status', '=', 1]; + //按时间检索 + $start_time = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0; + $end_time = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0; + if ($start_time > 0 && $end_time > 0) { + $where[] = ['expense_time', 'between', [$start_time, $end_time]]; + } + $expense = $this->get_list($param, $where); + return table_assign(0, '', $expense); + } else { + return view(); + } + } + + //添加 + public function add() + { + $id = empty(get_params('id')) ? 0 : get_params('id'); + if ($id > 0) { + $expense = $this->detail($id); + View::assign('expense', $expense); + } + $expense_cate = Db::name('ExpenseCate')->where(['status' => 1])->select()->toArray(); + View::assign('user', get_admin($this->uid)); + View::assign('expense_cate', $expense_cate); + View::assign('id', $id); + return view(); + } + + //提交添加 + public function post_submit() + { + $admin_id = $this->uid; + $dbRes = false; + $param = get_params(); + $param['admin_id'] = $admin_id; + $param['income_month'] = isset($param['income_month']) ? strtotime(urldecode($param['income_month'])) : 0; + $param['expense_time'] = isset($param['expense_time']) ? strtotime(urldecode($param['expense_time'])) : 0; + $param['check_status'] = 1; + if (!empty($param['id']) && $param['id'] > 0) { + try { + validate(ExpenseCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['update_time'] = time(); + Db::startTrans(); + try { + $res = ExpenseList::where('id', $param['id'])->strict(false)->field(true)->update($param); + if ($res !== false) { + $exid = $param['id']; + //相关内容多个数组; + $amountData = isset($param['amount']) ? $param['amount'] : ''; + $remarksData = isset($param['remarks']) ? $param['remarks'] : ''; + $cateData = isset($param['cate_id']) ? $param['cate_id'] : ''; + $idData = isset($param['expense_id']) ? $param['expense_id'] : 0; + if ($amountData) { + foreach ($amountData as $key => $value) { + if (!$value) { + continue; + } + + $data = []; + $data['id'] = $idData[$key]; + $data['exid'] = $exid; + $data['admin_id'] = $admin_id; + $data['amount'] = $amountData[$key]; + $data['cate_id'] = $cateData[$key]; + $data['remarks'] = $remarksData[$key]; + if ($data['amount'] == 0) { + Db::rollback(); + return to_assign(1, '第' . ($key + 1) . '条报销金额不能为零'); + } + if ($data['id'] > 0) { + $data['update_time'] = time(); + $resa = Db::name('ExpenseInterfix')->strict(false)->field(true)->update($data); + } else { + $data['create_time'] = time(); + $eid = Db::name('ExpenseInterfix')->strict(false)->field(true)->insertGetId($data); + } + } + } + add_log('edit', $exid, $param); + Db::commit(); + $dbRes = true; + } else { + Db::rollback(); + } + } catch (\Exception $e) { ##这里参数不能删除($e:错误信息) + Db::rollback(); + return to_assign(1, $e->getMessage()); + } + } else { + try { + validate(ExpenseCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['create_time'] = time(); + Db::startTrans(); + try { + $exid = ExpenseList::strict(false)->field(true)->insertGetId($param); + if ($exid) { + //相关内容多个数组; + $amountData = isset($param['amount']) ? $param['amount'] : ''; + $remarksData = isset($param['remarks']) ? $param['remarks'] : ''; + $cateData = isset($param['cate_id']) ? $param['cate_id'] : ''; + if ($amountData) { + foreach ($amountData as $key => $value) { + if (!$value) { + continue; + } + + $data = []; + $data['exid'] = $exid; + $data['admin_id'] = $admin_id; + $data['amount'] = $amountData[$key]; + $data['cate_id'] = $cateData[$key]; + $data['remarks'] = $remarksData[$key]; + $data['create_time'] = time(); + if ($data['amount'] == 0) { + Db::rollback(); + return to_assign(1, '第' . ($key + 1) . '条报销金额不能为零'); + } + $eid = Db::name('ExpenseInterfix')->strict(false)->field(true)->insertGetId($data); + } + } + add_log('add', $exid, $param); + Db::commit(); + $dbRes = true; + } else { + Db::rollback(); + } + } catch (\Exception $e) { ##这里参数不能删除($e:错误信息) + Db::rollback(); + return to_assign(1, $e->getMessage()); + } + } + if ($dbRes == true) { + return to_assign(); + } else { + return to_assign(1, '保存失败'); + } + } + + //查看 + public function view() + { + $id = empty(get_params('id')) ? 0 : get_params('id'); + $expense = $this->detail($id); + View::assign('uid', $this->uid); + View::assign('expense', $expense); + return view(); + } + + //删除 + public function delete() + { + $id = get_params("id"); + $expense = $this->detail($id); + if ($expense['check_status'] == 2) { + return to_assign(1, "已审核的报销记录不能删除"); + } + if ($expense['check_status'] == 3) { + return to_assign(1, "已打款的报销记录不能删除"); + } + $data['status'] = '-1'; + $data['id'] = $id; + $data['update_time'] = time(); + if (Db::name('expense')->update($data) !== false) { + add_log('delete', $id); + return to_assign(0, "删除成功"); + } else { + return to_assign(1, "删除失败"); + } + } + //设置 + public function check() + { + $param = get_params(); + if (request()->isAjax()) { + if ($param['check_status'] == 2 || $param['check_status'] == 0) { + $param['check_admin_id'] = $this->uid; + $param['check_time'] = time(); + } + if ($param['check_status'] == 3) { + $param['pay_admin_id'] = $this->uid; + $param['pay_time'] = time(); + } + $res = ExpenseList::where('id', $param['id'])->strict(false)->field(true)->update($param); + if ($res !== false) { + return to_assign(); + } else { + return to_assign(1, "操作失败"); + } + } else { + $expense = $this->detail($param['id']); + View::assign('expense', $expense); + View::assign('uid', $this->uid); + return view(); + } + } +} diff --git a/app/home/controller/Schedule.php b/app/home/controller/Schedule.php index 587ccfc..4510592 100644 --- a/app/home/controller/Schedule.php +++ b/app/home/controller/Schedule.php @@ -29,6 +29,7 @@ class Schedule extends BaseController ->alias('s') ->join('Department d', 's.did = d.id', 'LEFT') ->where($where) + ->order('id desc') ->paginate($rows, false, ['query' => $param]); return table_assign(0, '', $content); } else { @@ -58,6 +59,7 @@ class Schedule extends BaseController } } else { $id = isset($param['id']) ? $param['id'] : 0; + $did = isset($param['did']) ? $param['did'] : 0; $department = set_recursion(get_department()); if ($id > 0) { $detail = Db::name('ScheduleCate')->where(['id' => $id])->find(); @@ -65,6 +67,7 @@ class Schedule extends BaseController } View::assign('department', $department); View::assign('id', $id); + View::assign('did', $did); return view(); } } diff --git a/app/home/view/admin/add.html b/app/home/view/admin/add.html index fc36a24..5ce1ec2 100644 --- a/app/home/view/admin/add.html +++ b/app/home/view/admin/add.html @@ -217,7 +217,7 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "{:url('home/admin/post_submit')}", + url: "{:url('home/admin/add')}", type: 'post', data: data.field, success: function (e) { diff --git a/app/home/view/check/add.html b/app/home/view/check/add.html index ad31f93..428d79e 100644 --- a/app/home/view/check/add.html +++ b/app/home/view/check/add.html @@ -90,9 +90,10 @@ employee_url:"{:url('/home/api/get_employee')}", ids:idsArray, names:namesArray, + type:0, callback:function(ids,names){ - $('[name="uids"]').val(ids.join(',')), - $('[name="person_name"]').val(names.join(',')); + $('[name="uid"]').val(ids), + $('[name="name"]').val(names); } }); } @@ -103,13 +104,13 @@ //监听提交 form.on('submit(webform)', function (data) { $.ajax({ - url: "{:url('home/conf/add')}", + url: "{:url('home/check/add')}", type: 'post', data: data.field, success: function (e) { if (e.code == 0) { layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) { - window.location.href="{:url('home/conf/index')}"; + window.location.href="{:url('home/check/index')}"; }); } else { layer.msg(e.msg); diff --git a/app/home/view/schedule/cate.html b/app/home/view/schedule/cate.html index 2043cef..d910661 100644 --- a/app/home/view/schedule/cate.html +++ b/app/home/view/schedule/cate.html @@ -32,7 +32,7 @@ limit: 20, cols: [ [{field: 'id',width: 80,title: 'ID编号',align: 'center'} - , { field: 'name', width: 180, title: '工作类型名称'} + , { field: 'title', width: 180, title: '工作类型名称'} , { field: 'department',width: 300,title: '关联部门'} , { field: 'remark', title: '备注'} , { diff --git a/app/home/view/schedule/cate_add.html b/app/home/view/schedule/cate_add.html index 0faa4f3..36f93b1 100644 --- a/app/home/view/schedule/cate_add.html +++ b/app/home/view/schedule/cate_add.html @@ -11,10 +11,10 @@