diff --git a/app/home/controller/Department.php b/app/home/controller/Department.php
index 40e7912..e039f56 100644
--- a/app/home/controller/Department.php
+++ b/app/home/controller/Department.php
@@ -18,14 +18,14 @@ use think\facade\View;
class Department extends BaseController
{
public function index()
- {
+ {
if (request()->isAjax()) {
$list = Db::name('Department')
- ->field('d.*,a.name as leader')
- ->alias('d')
- ->join('Admin a', 'a.id = d.uid','LEFT')
- ->order('create_time asc')
- ->select();
+ ->field('d.*,a.name as leader')
+ ->alias('d')
+ ->join('Admin a', 'a.id = d.leader_id', 'LEFT')
+ ->order('id asc')
+ ->select();
return to_assign(0, '', $list);
} else {
return view();
@@ -35,41 +35,23 @@ class Department extends BaseController
//添加部门
public function add()
{
- $id = empty(get_params('id')) ? 0 : get_params('id');
- $pid = empty(get_params('pid')) ? 0 : get_params('pid');
- $department = set_recursion(get_department());
- if($id > 0) {
- $detail = Db::name('Department')->where(['id' => $id])->find();
- $users=Db::name('Admin')->where(['did'=>$id,'status'=>1])->select();
- View::assign('users', $users);
- View::assign('detail', $detail);
- }
- View::assign('department', $department);
- View::assign('pid', $pid);
- View::assign('id', $id);
- return view();
- }
-
- public function post_submit()
- {
+ $param = get_params();
if (request()->isAjax()) {
- $param = get_params();
if ($param['id'] > 0) {
- try {
- validate(DepartmentCheck::class)->scene('edit')->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- $param['update_time'] = time();
- $department_array=get_department_son($param['id']);
- if (in_array($param['pid'], $department_array)){
- return to_assign(1,'上级部门不能是该部门本身或其下属部门');
- }
- else{
- Db::name('Department')->strict(false)->field(true)->update($param);
- add_log('edit', $param['id'], $param);
- }
+ try {
+ validate(DepartmentCheck::class)->scene('edit')->check($param);
+ } catch (ValidateException $e) {
+ // 验证失败 输出错误信息
+ return to_assign(1, $e->getError());
+ }
+ $param['update_time'] = time();
+ $department_array = get_department_son($param['id']);
+ if (in_array($param['pid'], $department_array)) {
+ return to_assign(1, '上级部门不能是该部门本身或其下属部门');
+ } else {
+ Db::name('Department')->strict(false)->field(true)->update($param);
+ add_log('edit', $param['id'], $param);
+ }
} else {
try {
validate(DepartmentCheck::class)->scene('add')->check($param);
@@ -81,6 +63,20 @@ class Department extends BaseController
add_log('add', $did, $param);
}
return to_assign();
+ } else {
+ $id = isset($param['id']) ? $param['id'] : 0;
+ $pid = isset($param['pid']) ? $param['pid'] : 0;
+ $department = set_recursion(get_department());
+ if ($id > 0) {
+ $detail = Db::name('Department')->where(['id' => $id])->find();
+ $users = Db::name('Admin')->where(['did' => $id, 'status' => 1])->select();
+ View::assign('users', $users);
+ View::assign('detail', $detail);
+ }
+ View::assign('department', $department);
+ View::assign('pid', $pid);
+ View::assign('id', $id);
+ return view();
}
}
@@ -88,19 +84,19 @@ class Department extends BaseController
public function delete()
{
$id = get_params("id");
- $count = Db::name('Department')->where([['pid','=',$id],['status','>=',0]])->count();
+ $count = Db::name('Department')->where([['pid', '=', $id], ['status', '>=', 0]])->count();
if ($count > 0) {
- return to_assign(1,"该部门下还有子部门,无法删除");
+ return to_assign(1, "该部门下还有子部门,无法删除");
}
- $users = Db::name('Admin')->where([['did','=',$id],['status','>=',0]])->count();
+ $users = Db::name('Admin')->where([['did', '=', $id], ['status', '>=', 0]])->count();
if ($users > 0) {
- return to_assign(1,"该部门下还有员工,无法删除");
+ return to_assign(1, "该部门下还有员工,无法删除");
}
if (Db::name('Department')->delete($id) !== false) {
- add_log('delete',$id);
- return to_assign(0,"删除部门成功");
+ add_log('delete', $id);
+ return to_assign(0, "删除部门成功");
} else {
- return to_assign(1,"删除失败");
+ return to_assign(1, "删除失败");
}
}
}
diff --git a/app/home/controller/Position.php b/app/home/controller/Position.php
index 06a3a6d..b65e611 100644
--- a/app/home/controller/Position.php
+++ b/app/home/controller/Position.php
@@ -20,47 +20,24 @@ class Position extends BaseController
public function index()
{
if (request()->isAjax()) {
- $list = Db::name('Position')->where('status','>=',0)->order('create_time asc')->select()->toArray();
- foreach ($list as &$val) {
- $groupId = Db::name('PositionGroup')->where(['pid' => $val['id']])->column('group_id');
- $groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title');
- $val['groupName'] = implode(',', $groupName);
- }
- $res['data'] = $list;
+ $list = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select()->toArray();
+ foreach ($list as &$val) {
+ $groupId = Db::name('PositionGroup')->where(['pid' => $val['id']])->column('group_id');
+ $groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title');
+ $val['groupName'] = implode(',', $groupName);
+ }
+ $res['data'] = $list;
return table_assign(0, '', $res);
} else {
return view();
}
}
- //添加
+ //添加&编辑
public function add()
{
- $id = empty(get_params('id')) ? 0 : get_params('id');
- $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
- if($id > 0) {
- $detail = Db::name('Position')->where(['id' => $id])->find();
- $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
- foreach ($group as &$val) {
- if(in_array($val['id'],$detail['group_id'])){
- $val['checked'] = 1;
- }
- else{
- $val['checked'] = 0;
- }
- }
- View::assign('detail', $detail);
- }
- View::assign('group', $group);
- View::assign('id', $id);
- return view();
- }
-
- //提交添加
- public function post_submit()
- {
+ $param = get_params();
if (request()->isAjax()) {
- $param = get_params();
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(PositionCheck::class)->scene('edit')->check($param);
@@ -77,7 +54,7 @@ class Position extends BaseController
$data[$k] = [
'pid' => $param['id'],
'group_id' => $v,
- 'create_time' => time()
+ 'create_time' => time(),
];
}
Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data);
@@ -107,7 +84,7 @@ class Position extends BaseController
$data[$k] = [
'pid' => $uid,
'group_id' => $v,
- 'create_time' => time()
+ 'create_time' => time(),
];
}
Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data);
@@ -122,57 +99,75 @@ class Position extends BaseController
}
return to_assign();
}
+ else{
+ $id = isset($param['id']) ? $param['id'] : 0;
+ $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
+ if ($id > 0) {
+ $detail = Db::name('Position')->where(['id' => $id])->find();
+ $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
+ foreach ($group as &$val) {
+ if (in_array($val['id'], $detail['group_id'])) {
+ $val['checked'] = 1;
+ } else {
+ $val['checked'] = 0;
+ }
+ }
+ View::assign('detail', $detail);
+ }
+ View::assign('group', $group);
+ View::assign('id', $id);
+ return view();
+ }
}
//查看
public function view()
- {
- $id = get_params('id');
- $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
+ {
+ $id = get_params('id');
+ $group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
$detail = Db::name('Position')->where(['id' => $id])->find();
- $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
- foreach ($group as &$val) {
- if(in_array($val['id'],$detail['group_id'])){
- $val['checked'] = 1;
- }
- else{
- $val['checked'] = 0;
- }
- }
-
- $menu = get_admin_menu();
- $rule = get_admin_rule();
- $user_groups = Db::name('PositionGroup')
- ->alias('a')
- ->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
- ->where("a.pid='{$id}' and g.status='1'")
- ->select()
- ->toArray();
- $groups = $user_groups ?: [];
+ $detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
+ foreach ($group as &$val) {
+ if (in_array($val['id'], $detail['group_id'])) {
+ $val['checked'] = 1;
+ } else {
+ $val['checked'] = 0;
+ }
+ }
- $menus = [];
- $rules = [];
- foreach ($groups as $g) {
- $menus = array_merge($menus, explode(',', trim($g['menus'], ',')));
- $rules = array_merge($rules, explode(',', trim($g['rules'], ',')));
- }
- $menus = array_unique($menus);
- $rules = array_unique($rules);
-
- $role_menu = create_tree_list(0, $menu, $menus);
- $role_rule = create_tree_list(0, $rule, $rules);
+ $menu = get_admin_menu();
+ $rule = get_admin_rule();
+ $user_groups = Db::name('PositionGroup')
+ ->alias('a')
+ ->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
+ ->where("a.pid='{$id}' and g.status='1'")
+ ->select()
+ ->toArray();
+ $groups = $user_groups ?: [];
+
+ $menus = [];
+ $rules = [];
+ foreach ($groups as $g) {
+ $menus = array_merge($menus, explode(',', trim($g['menus'], ',')));
+ $rules = array_merge($rules, explode(',', trim($g['rules'], ',')));
+ }
+ $menus = array_unique($menus);
+ $rules = array_unique($rules);
+
+ $role_menu = create_tree_list(0, $menu, $menus);
+ $role_rule = create_tree_list(0, $rule, $rules);
View::assign('role_menu', $role_menu);
View::assign('role_rule', $role_rule);
View::assign('detail', $detail);
- View::assign('group', $group);
- add_log('view', $id);
+ View::assign('group', $group);
+ add_log('view', $id);
return view();
}
//删除
public function delete()
{
$id = get_params("id");
- if($id == 1){
+ if ($id == 1) {
return to_assign(0, "超级岗位,不能删除");
}
$data['status'] = '-1';
diff --git a/app/home/controller/expense.php b/app/home/controller/expense.php
deleted file mode 100644
index 2c3e585..0000000
--- a/app/home/controller/expense.php
+++ /dev/null
@@ -1,344 +0,0 @@
-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/view/department/add.html b/app/home/view/department/add.html
index 2120213..1b635c2 100644
--- a/app/home/view/department/add.html
+++ b/app/home/view/department/add.html
@@ -12,9 +12,9 @@
上级部门* |
|
@@ -34,9 +34,9 @@
上级部门* |
|
@@ -78,7 +78,7 @@
//监听提交
form.on('submit(webform)', function(data) {
$.ajax({
- url: "{:url('home/department/post_submit')}",
+ url: "{:url('home/department/add')}",
type: 'post',
data: data.field,
success: function(e) {
diff --git a/app/home/view/position/add.html b/app/home/view/position/add.html
index 5cf28ce..07c03ef 100644
--- a/app/home/view/position/add.html
+++ b/app/home/view/position/add.html
@@ -5,22 +5,22 @@
{if condition="$id eq 0"}