人事模块优化

This commit is contained in:
hdm 2021-11-17 23:26:19 +08:00
parent 5dd6b3515c
commit 56ad54fb6f
8 changed files with 416 additions and 70 deletions

View File

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

View File

@ -0,0 +1,344 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\home\BaseController;
use app\home\model\Expense as ExpenseList;
use app\home\model\ExpenseCate;
use app\home\validate\ExpenseCateCheck;
use app\home\validate\ExpenseCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Expense extends BaseController
{
public function cate()
{
if (request()->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();
}
}
}

View File

@ -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();
}
}

View File

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

View File

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

View File

@ -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: '备注'}
, {

View File

@ -11,10 +11,10 @@
</td>
<td class="layui-td-gray2">关联部门<font>*</font></td>
<td>
<select name="pid" lay-verify="required" lay-reqText="请选择部门">
<select name="did" lay-verify="required" lay-reqText="请选择部门">
<option value="">请选择</option>
{volist name="department" id="v"}
<option value="{$v.id}" {eq name="pid" value="$v.id" }selected {/eq}>{$v.title}</option>
<option value="{$v.id}" {eq name="did" value="$v.id" }selected {/eq}>{$v.title}</option>
{/volist}
</select>
</td>
@ -40,9 +40,11 @@
</td>
<td class="layui-td-gray2">关联部门<font>*</font></td>
<td>
<select name="type" lay-verify="required" lay-reqText="请选择部门">
<select name="did" lay-verify="required" lay-reqText="请选择部门">
<option value="">请选择</option>
<option value="{$v.id}" {eq name="detail.did" value="$v.id"} selected{/eq}>{$v.title}</option>
{volist name="department" id="v"}
<option value="{$v.id}" {eq name="detail.did" value="$v.id" }selected {/eq}>{$v.title}</option>
{/volist}
</select>
</td>
<td class="layui-td-gray2">状态<font>*</font></td>
@ -85,7 +87,7 @@
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/schedule/cate')}";
});
} else {
layer.msg(e.msg);

View File

@ -117,9 +117,9 @@ class Index
$update_time = time();
$create_admin_sql = "INSERT INTO " . $data['DB_PREFIX'] . "admin " .
"(username,salt,pwd,name,nickname,position_id,thumb,create_time,update_time) "
"(username,salt,pwd,name,nickname,position_id,mobile,thumb,create_time,update_time) "
. "VALUES "
. "('$username','$salt','$password','$name','$nickname',1,'$thumb','$create_time','$update_time')";
. "('$username','$salt','$password','$name','$nickname',1,'13800138000','$thumb','$create_time','$update_time')";
if (!$link->query($create_admin_sql)) {
return to_assign(1, '创建管理员信息失败');
}