Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

semour / semour_web

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • semour_web
  • app
  • Models
  • Cms
  • CmsDepartmentModel.php
CmsDepartmentModel.php 1.58 KB
Edit
杨树贤's avatar
用户对接自动分发
0d8576fa
 
杨树贤 committed 2 years ago
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
<?php
namespace App\Models\Cms;

use Illuminate\Database\Eloquent\Model;

class CmsDepartmentModel extends Model
{
    protected $table = 'department';
    public $timestamps = false;
    protected $primaryKey = 'departmentId';

    //采购部门的总ID
    const PURCHASE_DEPARTMENT_ID = 8;

    //销售部门的总ID
    const SALES_DEPARTMENT_ID = 7;

    // 获取部门人员
    public static function getUsersByDepartmentId($departmentId, $status = '', $filter = '')
    {
        $departmentIds = [];

        self::getSubDepartmentId($departmentId, $departmentIds);

        return CmsUserInfoModel::whereIn('department_id', $departmentIds)
            ->where(function ($query) use ($status) {
                if ($status !== '') {
                    $query->where('status', '=', $status);
                }
            })
            ->where(function ($query) use ($filter) {
                if ($filter) {
                    $query->whereRaw($filter);
                }
            })
            ->get()->toArray();
    }

    // 获取下级部门ID
    public static function getSubDepartmentId($departmentId, &$departmentIds)
    {
        // 获取下级部门
        $sub_department = CmsUserDepartmentModel::where('parent_id', $departmentId)->select([
            'department_id',
            'department_name'
        ])->get();
        if ($sub_department) {
            foreach ($sub_department as $v) {
                self::getSubDepartmentId($v['department_id'], $departmentIds);
            }
        }

        $departmentIds[] = $departmentId;

        return $departmentIds;
    }
}