|
@@ -49,6 +49,13 @@ class UseScopeBaseModel extends Model
|
|
|
$query->where('top_depart_id', $top_depart_id);
|
|
|
}
|
|
|
|
|
|
+ //获取当前门店下
|
|
|
+ if(! empty($search['get_my_top_depart_data'])){
|
|
|
+ $depart = ! empty($user['depart_top'][0]) ? $user['depart_top'][0]: [];
|
|
|
+ $depart_id = $depart['depart_id'] ?? 0;
|
|
|
+ $query->where('top_depart_id', $depart_id);
|
|
|
+ }
|
|
|
+
|
|
|
return $query;
|
|
|
}
|
|
|
|
|
@@ -159,6 +166,113 @@ class UseScopeBaseModel extends Model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //部门和顶级部门(公司)过滤 取别名a
|
|
|
+ public function scopeAClear($query, $user, $search)
|
|
|
+ {
|
|
|
+ //是否所有部门
|
|
|
+ $is_all_depart = $user['is_all_depart'] ?? 0;
|
|
|
+ //权限范围内的部门
|
|
|
+ $depart_range = $user['depart_range'] ?? [];
|
|
|
+ //我可见的
|
|
|
+ $is_see = $search['is_see'] ?? 0;
|
|
|
+
|
|
|
+ //可见范围方法
|
|
|
+ $model = $query->getModel(); // 获取模型的实例
|
|
|
+ $range_function = $model::range_function ?? ""; // 访问静态属性
|
|
|
+ $is_function_range = $this->hasMethod(new RangeService(),$range_function);
|
|
|
+
|
|
|
+ //顶级部门
|
|
|
+ $search_depart_id = $search['top_depart_id'] ?? 0; //顶级公司
|
|
|
+ if(empty($search_depart_id)){
|
|
|
+ //默认进来 自身顶级公司
|
|
|
+ $top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
+ $top_depart_id = $top_depart_id['depart_id'] ?? 0;
|
|
|
+ }else{
|
|
|
+ //查询 顶级公司
|
|
|
+ $top_depart_id = $search_depart_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = [];
|
|
|
+ //可见范围 以及单据里面填写人员
|
|
|
+ if($is_function_range) $id = RangeService::$range_function($user,$search);
|
|
|
+
|
|
|
+ //个人部门所有
|
|
|
+ $auth_type = $this->getQx($search,$user);
|
|
|
+
|
|
|
+ if($is_all_depart){
|
|
|
+ //所有权限
|
|
|
+ if(empty($search_depart_id)){
|
|
|
+ if(! $is_see){
|
|
|
+ if(! $auth_type){
|
|
|
+ //全部
|
|
|
+ $query->whereIn('a.depart_id', $depart_range);
|
|
|
+ }else{
|
|
|
+ if($auth_type == 1) { //我创建的 且加上可见
|
|
|
+ $query->where('a.crt_id',$user['id'])
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }elseif ($auth_type == 2 || $auth_type == 3){
|
|
|
+ //自己权限范围内的部门 或 所有
|
|
|
+ $query->whereIn('a.depart_id', $depart_range);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //可见
|
|
|
+ $query->whereIn('a.id', $id);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(! $is_see){
|
|
|
+ if(! $auth_type){
|
|
|
+ //查看指定公司
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id);
|
|
|
+ }else{
|
|
|
+ if($auth_type == 1) { //指定公司下 且 我创建的 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->where('a.crt_id',$user['id'])
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }elseif ($auth_type == 2 || $auth_type == 3){
|
|
|
+ // (指定公司下的 且 自己权限范围内的部门 或 所有) 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->whereIn('a.depart_id', $depart_range)
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //查看指定公司 且 我可见
|
|
|
+ $query->whereIn('a.id', $id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //非所有权限
|
|
|
+ if(! $is_see){
|
|
|
+ if(! $auth_type){
|
|
|
+ //指定公司下全部 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->whereIn('a.depart_id', $depart_range)
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }else{
|
|
|
+ if($auth_type == 1) {
|
|
|
+ //指定公司下 且 我创建的 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->where('a.crt_id',$user['id'])
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }elseif ($auth_type == 2) {
|
|
|
+ //指定公司下 且 自己权限范围内的部门 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->whereIn('a.depart_id', $depart_range)
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }elseif ($auth_type == 3) {
|
|
|
+ // 指定公司下所有 且加上可见
|
|
|
+ $query->where('a.top_depart_id', $top_depart_id)
|
|
|
+ ->orWhereIn('a.id', $id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //某个分社可见
|
|
|
+ $query->whereIn('a.id', $id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//部门和顶级部门(公司)过滤 Old
|
|
|
public function scopeClear1($query, $user, $search)
|
|
|
{
|