Blame view

addons/antis/model/StaffDepartment.php 1.67 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  <?php

  

  namespace addons\antis\model;

  

  use think\Model;

  use traits\model\SoftDelete;

  

  /**

   *员工部门表

   */

  class StaffDepartment Extends Model {

  	use SoftDelete;

      // 表名,不含前缀

      protected $name = 'qingdong_staff_department';

  	// 开启自动写入时间戳字段

  	protected $autoWriteTimestamp = 'int';

  	// 定义时间戳字段名

  	protected $createTime = 'createtime';

  	protected $updateTime = 'updatetime';

  	protected $deleteTime = 'deletetime';

  

  

  	//员工业绩

  	public function achievement() {

  		return $this->belongsTo(Achievement::class, 'id', 'obj_id')->where(['type' => 2]);

  	}

  

  

  	//获取部门列表

  	public static function getDepartmentList() {

  		$department = self::where([])->field('id,name,pid')->select();

  

  		$data = [];

  		foreach ($department as $v) {

  			$data[$v['pid']][] = $v;

  		}

  

  		return self::getChilds($data, 0);

  	}

  

  	//获取部门及所有下级部门

  	public static function getDepartmentLowerId($l_ids,$top=true){

  		$ids=self::where(['pid' =>['in',$l_ids]])->column('id');

  		if ($ids) {

  			$w_ids = self::getDepartmentLowerId($ids,false);

  			$ids   = array_merge($ids, $w_ids);

  		}else{

  			$ids=[];

  		}

  		if($top){

  			$ids=array_merge($ids,$l_ids);

  		}

  		return $ids;

  	}

  

  

  	//生成树状结构

  	private static function getChilds($data, $pid) {

  		$list = [];

  		if (isset($data[$pid])) {

  			$list = $data[$pid];

  			foreach ($list as $k => $v) {

  				$v['children'] = self::getChilds($data, $v['id']);

  				$list[$k]    = $v;

  			}

  		}

  

  		return $list;

  	}

      //获取部门列表

      public static function getList()

      {

          return self::where([])->field('id,name')->select();

      }

  }