64 lines
1.5 KiB
PHP
Raw Normal View History

2020-04-29 17:37:45 +08:00
<?php
namespace catchAdmin\permissions\model;
use catchAdmin\permissions\model\search\DepartmentSearch;
use catcher\base\CatchModel;
2020-10-21 08:12:07 +08:00
use think\db\exception\DbException;
2020-04-29 17:37:45 +08:00
class Department extends CatchModel
{
use DepartmentSearch;
protected $name = 'departments';
protected $field = [
'id', //
'department_name', // 部门名称
'parent_id', // 父级ID
'principal', // 负责人
'mobile', // 联系电话
'email', // 联系又想
'creator_id', // 创建人ID
'status', // 1 正常 2 停用
'sort', // 排序字段
'created_at', // 创建时间
'updated_at', // 更新时间
'deleted_at', // 删除状态null 未删除 timestamp 已删除
];
2021-04-26 10:37:18 +08:00
protected $updateChildrenFields = 'status';
/**
2020-04-29 17:37:45 +08:00
* 列表数据
*
* @time 2020年01月09日
* @return array
2020-10-21 08:12:07 +08:00
* @throws DbException
2020-04-29 17:37:45 +08:00
*/
public function getList(): array
{
2020-09-01 07:58:36 +08:00
return $this->catchSearch()
2020-06-17 13:24:02 +08:00
->catchOrder()
2020-10-21 08:12:07 +08:00
->select()->toTree();
2020-04-29 17:37:45 +08:00
}
2020-11-04 08:20:15 +08:00
/**
* 获取子部门IDS
2020-11-04 08:20:15 +08:00
*
* @time 2020年11月04日
* @param $id
2020-11-04 08:20:15 +08:00
* @throws DbException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @return mixed
2020-11-04 08:20:15 +08:00
*/
public static function getChildrenDepartmentIds($id)
2020-11-04 08:20:15 +08:00
{
$departmentIds = Department::field(['id', 'parent_id'])->select()->getAllChildrenIds([$id]);
2020-11-04 08:20:15 +08:00
$departmentIds[] = $id;
2020-11-04 08:20:15 +08:00
return $departmentIds;
2020-11-04 08:20:15 +08:00
}
2020-04-29 17:37:45 +08:00
}