diff --git a/plugs/think-plugs-staff/src/controller/Dept.php b/plugs/think-plugs-staff/src/controller/Dept.php new file mode 100644 index 0000000..cdbb600 --- /dev/null +++ b/plugs/think-plugs-staff/src/controller/Dept.php @@ -0,0 +1,120 @@ +layTable(function () { + $this->title = '员工部门'; + }, static function (QueryHelper $query) { + $query->with('parent.parent')->append(['headman_name']); + $query->equal('status')->like('name'); + }); + } + + /** + * 添加部门 + * @auth true + * @menu true + * @return void + */ + public function add() + { + StaffDept::mForm('form'); + } + + /** + * 编辑部门 + * @auth true + * @return void + */ + public function edit() + { + StaffDept::mForm('form'); + } + + protected function _form_filter(array &$data) + { + if ($this->request->isPost()) { + $this->_vali([ + 'name.require' => '部门名称不能为空!', + ]); + } else { + $this->depts = StaffDept::topItems(); + } + } + + /** + * 部门排序 + * @auth true + * @return void + */ + public function sort() + { + StaffDept::mSave($this->_vali([ + 'sort.require' => '排序参数不能为空!', + 'sort.number' => '排序参数格式错误!', + ])); + } + + /** + * 设置部门领导人 + * @auth true + * @return void + */ + public function headman() + { + $data = $this->_vali([ + 'id.require' => '部门不能为空!', + ]); + if ($this->request->isGet()) { + $this->title = '设置部门负责人'; + $this->dept = StaffDept::mk()->where(['id' => $data['id']])->findOrEmpty(); + if ($this->dept->isEmpty()) $this->error('部门不存在!'); + $this->users = StaffUser::mk()->where(['status' => 1, 'dept_id' => $this->dept['id']])->select(); + $this->fetch(); + } else { + StaffDept::mSave($this->_vali([ + 'headman_id.require' => '部门领导人不能为空!', + 'headman_id.number' => '部门领导人格式错误!', + ])); + } + } + + /** + * 启用禁用部门 + * @auth true + * @return void + */ + public function state() + { + StaffDept::mSave($this->_vali([ + 'status.in:0,1' => '状态值范围异常!', + 'status.require' => '状态值不能为空!', + ])); + } + + /** + * 删除部门 + * @auth true + * @return void + */ + public function del() + { + StaffDept::mDelete(); + } + +} \ No newline at end of file diff --git a/plugs/think-plugs-staff/src/model/StaffDept.php b/plugs/think-plugs-staff/src/model/StaffDept.php index 1b5a3c6..19c86ca 100644 --- a/plugs/think-plugs-staff/src/model/StaffDept.php +++ b/plugs/think-plugs-staff/src/model/StaffDept.php @@ -13,7 +13,15 @@ class StaffDept extends Model protected $updateTime = false; protected $oplogName = '部门'; protected $oplogType = '部门管理'; - protected $globalScope = ['not_deleted']; + protected $globalScope = ['notDeleted']; + + public static function topItems() + { + return self::where(['pid' => 0])->field("id, name")->select()->unshift([ + 'id' => 0, + 'name' => '顶级部门', + ]); + } public function scopeDeleted(Query $query): void { @@ -58,4 +66,12 @@ class StaffDept extends Model { return static::mk()->where(['is_deleted' => 0, 'pid' => 0])->with('children.children')->select(); } + + public function getHeadmanNameAttr() + { + if (!$this->headman_id) { + return '无'; + } + return $this->headman ? $this->headman['name'] : '无'; + } } \ No newline at end of file diff --git a/plugs/think-plugs-staff/src/view/dept/form.html b/plugs/think-plugs-staff/src/view/dept/form.html new file mode 100644 index 0000000..f1cfa63 --- /dev/null +++ b/plugs/think-plugs-staff/src/view/dept/form.html @@ -0,0 +1,29 @@ +
+
+
+ 基础信息 + + +
+
+ +
+ {notempty name='vo.id'}{/notempty} + +
+ + +
+
\ No newline at end of file diff --git a/plugs/think-plugs-staff/src/view/dept/headman.html b/plugs/think-plugs-staff/src/view/dept/headman.html new file mode 100644 index 0000000..b1dd2c5 --- /dev/null +++ b/plugs/think-plugs-staff/src/view/dept/headman.html @@ -0,0 +1,26 @@ +
+
+
+ 部门:{$dept.name} + +
+
+ +
+ {notempty name='get.id'}{/notempty} + +
+ + +
+
\ No newline at end of file diff --git a/plugs/think-plugs-staff/src/view/dept/index.html b/plugs/think-plugs-staff/src/view/dept/index.html new file mode 100644 index 0000000..2adc397 --- /dev/null +++ b/plugs/think-plugs-staff/src/view/dept/index.html @@ -0,0 +1,89 @@ +{extend name='table'} + +{block name="button"} + + + +{/block} + +{block name="content"} +
+ {include file="dept/index_search"} +
+
+ + + + + +{/block} \ No newline at end of file diff --git a/plugs/think-plugs-staff/src/view/dept/index_search.html b/plugs/think-plugs-staff/src/view/dept/index_search.html new file mode 100644 index 0000000..42c5555 --- /dev/null +++ b/plugs/think-plugs-staff/src/view/dept/index_search.html @@ -0,0 +1,27 @@ +
+ {:lang('条件搜索')} + +
\ No newline at end of file