| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 | <?phpnamespace App\Service;use App\Model\ConstructionInfo;use App\Model\CustomerInfo;use App\Model\ProductRange;use App\Model\ReturnExchangeOrderRange;use App\Model\SalesOrderInfo;use App\Model\SalesOrderRange;use App\Model\SportsBagRange;use App\Model\SupplierInfo;use Illuminate\Support\Facades\DB;class RangeService extends Service{    //获取客户可见数据    public static function customerRange($user,$search){        $user_id = $user['id'];        $depart_id = $user['depart_range'];        $type = implode(',',CustomerInfo::$see_man);        $type2 = CustomerInfo::type_eight;        $depart_str = implode(',',$depart_id);        $str = "(data_id = $user_id AND type IN({$type})) OR (data_id IN({$depart_str}) AND type = {$type2})";        // 销售人员/负责人 3协同人  可见部门 可见人 可以看见        $customer_id = CustomerInfo::where('del_time',0)            ->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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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']) && ! empty($user['is_all_depart'])){            $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;    }}
 |