where(['is_deleted' => 1]); } public function scopeNotDeleted(Query $query): void { $query->where(['is_deleted' => 0]); } public static function items() { return self::mk()->where(['status' => 1])->select(); } public function staffs(): HasMany { return $this->hasMany(StaffUser::class, 'dept_id', 'id')->where([ 'status' => 1, 'is_deleted' => 0, ]); } public function headman(): HasOne { return $this->hasOne(StaffUser::class, 'id', 'headman_id')->where([ 'status' => 1, 'is_deleted' => 0, ]); } public function children(): HasMany { return $this->hasMany(StaffDept::class, 'pid', 'id'); } public function parent(): HasOne { return $this->hasOne(StaffDept::class, 'id', 'pid'); } public static function tree() { return static::mk()->where(['is_deleted' => 0, 'pid' => 0])->with('children.children')->select(); } }