where(function ($query) use($str) { $query->whereRaw($str); })->select('customer_id')->get()->toArray(); $return_id = array_unique(array_column($customer_id,'customer_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('customer') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取供应商可见数据 public static function supplierRange($user,$search){ $user_id = $user['id']; $depart_id = $user['depart_range']; $type = SupplierInfo::type_two; $type2 = SupplierInfo::type_one; $depart_str = implode(',',$depart_id); $str = "(data_id = $user_id AND type IN({$type})) OR (data_id IN({$depart_str}) AND type = {$type2})"; // 可见部门 可见人 可以看见 $supplier_id = SupplierInfo::where('del_time',0) ->where(function ($query) use($str) { $query->whereRaw($str); })->select('supplier_id')->get()->toArray(); $return_id = array_unique(array_column($supplier_id,'supplier_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('supplier') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取产品可见数据 public static function productRange($user,$search){ $user_id = $user['id']; $depart_id = $user['depart_range']; $product_id = ProductRange::where('del_time',0) ->where(function ($query) use($user_id, $depart_id) { $query->where('employee_id',$user_id) ->orWhereIn('depart_id', $depart_id); })->select('product_id')->get() ->toArray(); $return_id = array_unique(array_column($product_id,'product_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('product') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取合同可见数据 public static function salesOrderRange($user,$search){ //单据中选择的签订负责协同人 $sales_order_id = SalesOrderInfo::where('del_time',0) ->whereIn('type',SalesOrderInfo::$man) ->where('data_id',$user['id']) ->select('sales_order_id') ->get()->toArray(); $sales_order_id = array_unique(array_column($sales_order_id,'sales_order_id')); //指派后 $user_id = $user['id']; $depart_id = $user['depart_range']; $sales_order_id2 = SalesOrderRange::where('del_time',0) ->where(function ($query) use($user_id, $depart_id) { $query->where('employee_id',$user_id) ->orWhereIn('depart_id', $depart_id); })->select('sales_order_id')->get() ->toArray(); $return_id = array_unique(array_merge_recursive($sales_order_id,array_column($sales_order_id2,'sales_order_id'))); if(! empty($search['top_depart_id'])){ $id = DB::table('sales_order') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取施工单可见数据 public static function constructionRange($user,$search){ //单据中选择的签订负责协同人 $construction_id = ConstructionInfo::where('del_time',0) ->where('employee_id',$user['id']) ->select('construction_id') ->get()->toArray(); $return_id = array_unique(array_column($construction_id,'construction_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('construction') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取退换货单可见数据 public static function returnExchangeOrderRange($user,$search){ $user_id = $user['id']; $depart_id = $user['depart_range']; $return_exchange_id = ReturnExchangeOrderRange::where('del_time',0) ->where(function ($query) use($user_id, $depart_id) { $query->where('employee_id',$user_id) ->orWhereIn('depart_id', $depart_id); })->select('return_exchange_id')->get() ->toArray(); $return_id = array_unique(array_column($return_exchange_id,'return_exchange_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('return_exchange_order') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } //获取活动包可见数据 public static function sportsBagRange($user,$search){ $user_id = $user['id']; $depart_id = $user['depart_range']; $return_exchange_id = SportsBagRange::where('del_time',0) ->where(function ($query) use($user_id, $depart_id) { $query->where('employee_id',$user_id) ->orWhereIn('depart_id', $depart_id); })->select('sports_bag_id')->get() ->toArray(); $return_id = array_unique(array_column($return_exchange_id,'sports_bag_id')); if(! empty($search['top_depart_id'])){ $id = DB::table('sports_bag') ->where('del_time',0) ->where('top_depart_id',$search['top_depart_id']) ->select('id')->get()->toArray(); $id = array_column($id,'id'); foreach ($return_id as $key => $value){ if(! in_array($value,$id)) unset($return_id[$key]); } } return $return_id; } }