123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987 |
- <?php
- namespace App\Service;
- use App\Model\BasicType;
- use App\Model\Construction;
- use App\Model\ConstructionInfo;
- use App\Model\Customer;
- use App\Model\CustomerInfo;
- use App\Model\Depart;
- use App\Model\Employee;
- use App\Model\InvoiceOrder;
- use App\Model\OaOrder;
- use App\Model\OaOrderSub;
- use App\Model\OaOrderSubEmployee;
- use App\Model\PaymentReceipt;
- use App\Model\PaymentReceiptInfo;
- use App\Model\Product;
- use App\Model\PurchaseOrder;
- use App\Model\ReturnExchangeOrder;
- use App\Model\SalesOrder;
- use App\Model\SalesOrderInfo;
- use App\Model\SeeRange;
- use App\Model\SportsBag;
- use Illuminate\Support\Facades\DB;
- class RangeService extends Service
- {
- //设置可见范围 除了合同
- public function seeRange($data,$user){
- if(empty($data['data_type'])) return [false, "可见范围数据类型不能为空"];
- if(! in_array($data['data_type'], SeeRange::$type)) return [false, "可见范围数据类型错误"];
- if(empty($data['data_id'])) return [false,'可见范围数据ID不能为空'];
- $time = time();
- SeeRange::where('del_time',0)
- ->where('data_type',$data['data_type'])
- ->where('data_id',$data['data_id'])
- ->whereIn('type',[SeeRange::data_one, SeeRange::data_two])
- ->update(['del_time' => $time]);
- if(! empty($data['depart'])){
- $insert = [];
- foreach ($data['depart'] as $value){
- $insert[] = [
- 'data_id' => $data['data_id'],
- 'data_type' => $data['data_type'],
- 'param_id' => $value,
- 'type' => SeeRange::data_one,
- 'crt_time' => $time,
- ];
- }
- SeeRange::insert($insert);
- }
- if(! empty($data['employee'])){
- $insert = [];
- foreach ($data['employee'] as $value){
- $insert[] = [
- 'data_id' => $data['data_id'],
- 'data_type' => $data['data_type'],
- 'param_id' => $value,
- 'type' => SeeRange::data_two,
- 'crt_time' => $time,
- ];
- }
- SeeRange::insert($insert);
- }
- return [true,''];
- }
- //可见范围删除
- public function RangeDelete($data_id = 0, $data_type = 0){
- if(empty($data_id) || empty($data_type)) return;
- SeeRange::where('del_time',0)
- ->where('data_id',$data_id)
- ->where('data_type',$data_type)
- ->update(['del_time'=> time()]);
- }
- //获取可见范围详情
- public function RangeDetail($data_id = 0, $data_type = 0){
- if(empty($data_id) || empty($data_type)) return [];
- $see = SeeRange::where('del_time',0)
- ->where('data_id',$data_id)
- ->where('data_type',$data_type)
- ->get()->toArray();
- $depart_map = Depart::where('del_time',0)->pluck('title','id')->toArray();
- $emp_map = Employee::where('del_time',0)->pluck('emp_name','id')->toArray();
- $depart = $employee = $depart2 = [];
- foreach ($see as $value){
- if ($value['type'] == SeeRange::data_one){
- $name = $depart_map[$value['param_id']] ?? "";
- if(! empty($name)){
- $tmp = [
- 'id' => $value['param_id'],
- 'name' => $depart_map[$value['param_id']] ?? "",
- ];
- $depart[] = $tmp;
- }
- }elseif ($value['type'] == SeeRange::data_two){
- $name = $emp_map[$value['param_id']] ?? '';
- if(! empty($name)){
- $tmp = [
- 'id' => $value['param_id'],
- 'name' => $emp_map[$value['param_id']] ?? '',
- ];
- $employee[] = $tmp;
- }
- }elseif ($value['type'] == SeeRange::data_three){
- $name = $depart_map[$value['param_id']] ?? '';
- if(! empty($name)) {
- $tmp = [
- 'id' => $value['param_id'],
- 'name' => $depart_map[$value['param_id']] ?? '',
- ];
- $depart2[] = $tmp;
- }
- }
- }
- return [$depart, $employee, $depart2];
- }
- //获取可见范围数据id
- public static function getRangeDataId($user,$data_type){
- $user_id = $user['id'];
- $depart_id = $user['depart_range'];
- $type = SeeRange::data_two;
- $type2 = [SeeRange::data_one,SeeRange::data_three];
- $type2 = implode(',',$type2);
- $depart_str = implode(',',$depart_id);
- if(empty($depart_str)) {
- $string = "param_id = 0";
- }else{
- $string = "param_id IN({$depart_str})";
- }
- // 人为当前用户时, 或部门在当前用户范围内
- $str = "(param_id = $user_id AND type = $type) OR ($string AND type IN ({$type2}))";
- // 可见部门 可见人 可以看见
- $data_id = SeeRange::where('del_time',0)
- ->where('data_type', $data_type)
- ->where(function ($query) use($str) {
- $query->whereRaw($str);
- })->select('data_id')->get()->toArray();
- return array_unique(array_column($data_id,'data_id'));
- }
- //获取客户可见数据
- public static function customerRange($user,$search){
- // 销售人员/负责人 3协同人 可以看见
- $customer_id = CustomerInfo::where('del_time',0)
- ->where('data_id',$user['id'])
- ->whereIn('type',CustomerInfo::$see_man)
- ->select('customer_id')->get()->toArray();
- $return_id = array_unique(array_column($customer_id,'customer_id'));
- //可见范围id
- $rang_id = Self::getRangeDataId($user,SeeRange::type_one);
- //并和
- $return_id = array_unique(array_merge_recursive($return_id,$rang_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 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'));
- //可见范围id
- $return = Self::getRangeDataId($user,SeeRange::type_two);
- $return_id = array_unique(array_merge_recursive($return_id,$return));
- 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]);
- }
- }
- if(isset($search['is_check'])){
- $args = self::constructionCheck($user,$search);
- $result = Construction::whereIn('id',$return_id)
- ->when(! empty($args), function ($query) use ($args) {
- return $query->whereRaw($args);
- })
- ->select('id')
- ->get()->toArray();
- $return_id = array_column($result,'id');
- }
- return $return_id;
- }
- //获取发货单可见数据
- public static function invoiceRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_three);
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
- $id = DB::table('invoice_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]);
- }
- }
- if(isset($search['is_check'])){
- $args = self::invoiceCheck($user,$search);
- $result = InvoiceOrder::whereIn('id',$return_id)
- ->when(! empty($args), function ($query) use ($args) {
- return $query->whereRaw($args);
- })
- ->select('id')
- ->get()->toArray();
- $return_id = array_column($result,'id');
- }
- return $return_id;
- }
- //获取产品可见数据
- public static function productRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_four);
- 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 productRangeNot($user,$search){
- //不可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_four);
- //分社管理员
- if(empty($user['is_all_depart']) && ! empty($user['is_manager'])) {
- $depart = array_shift($user['rule_depart']);
- $depart_id = $depart['depart_id'] ?? 0;
- $id = DB::table('product')
- ->where('del_time',0)
- ->where('top_depart_id',$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 purchaseRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_five);
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
- $id = DB::table('purchase_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]);
- }
- }
- if(isset($search['is_check'])){
- $args = self::purchaseCheck($user,$search);
- $result = PurchaseOrder::whereIn('id',$return_id)
- ->when(! empty($args), function ($query) use ($args) {
- return $query->whereRaw($args);
- })
- ->select('id')
- ->get()->toArray();
- $return_id = array_column($result,'id');
- }
- return $return_id;
- }
- //获取退换货单可见数据
- public static function returnExchangeOrderRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_six);
- 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]);
- }
- }
- if(isset($search['is_check'])){
- $args = self::returnExchangeOrderCheck($user,$search);
- $result = ReturnExchangeOrder::whereIn('id',$return_id)
- ->when(! empty($args), function ($query) use ($args) {
- return $query->whereRaw($args);
- })
- ->select('id')
- ->get()->toArray();
- $return_id = array_column($result,'id');
- }
- 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'));
- //指派后 可见范围id
- $return = Self::getRangeDataId($user,SeeRange::type_seven);
- $return_id = array_unique(array_merge_recursive($sales_order_id,$return));
- 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]);
- }
- }
- if(isset($search['is_check'])){
- $args = self::salesOrderCheck($user,$search);
- $result = SalesOrder::whereIn('id',$return_id)
- ->when(! empty($args), function ($query) use ($args) {
- return $query->whereRaw($args);
- })
- ->select('id')
- ->get()->toArray();
- $return_id = array_column($result,'id');
- }
- return $return_id;
- }
- //获取特殊采购单可见数据
- public static function purchaseSpecialRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_ten);
- // if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
- // $id = DB::table('purchase_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 supplierRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_nine);
- 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 sportsBagRange($user,$search){
- //可见范围id
- $return_id = Self::getRangeDataId($user,SeeRange::type_eight);
- 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;
- }
- //产品不可见部门
- public static function productNotSeeRange($product_id){
- $return = [];
- $result = SeeRange::where('del_time',0)
- ->where('data_type', SeeRange::type_four)
- ->whereIn('data_id',$product_id)
- ->where('type',SeeRange::data_one)
- ->select('param_id as depart_id','data_id as product_id')
- ->get()->toArray();
- foreach ($result as $value){
- $return[$value['product_id']][] = $value['depart_id'];
- }
- return $return;
- }
- //产品签订人负责人
- public function salesOrderSearch($data){
- $return1 = $return2 = [];
- if(! empty($data['qd'])){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['qd'].'%')
- ->select('id')->get()->toArray();
- $emp_id = array_column($emp_id,'id');
- //单据中选择的签订人
- $sales_order_id = SalesOrderInfo::where('del_time',0)
- ->where('type',SalesOrderInfo::type_one)
- ->whereIn('data_id',$emp_id)
- ->select('sales_order_id')
- ->get()->toArray();
- $return1 = array_unique(array_column($sales_order_id,'sales_order_id'));
- }
- if(! empty($data['fz'])){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['fz'].'%')
- ->select('id')->get()->toArray();
- $emp_id = array_column($emp_id,'id');
- //单据中选择的负责人
- $sales_order_id = SalesOrderInfo::where('del_time',0)
- ->where('type',SalesOrderInfo::type_two)
- ->whereIn('data_id',$emp_id)
- ->select('sales_order_id')
- ->get()->toArray();
- $return2 = array_unique(array_column($sales_order_id,'sales_order_id'));
- }
- if(! empty($data['qd']) && ! empty($data['fz'])){
- $return = array_intersect($return1, $return2);
- }elseif(!empty($data['qd'])){
- $return = $return1;
- }else{
- $return = $return2;
- }
- return $return;
- }
- //指派门店
- public function salesOrderZpSearch($data){
- $return = SeeRange::where('del_time',0)
- ->where('param_id',$data['zp'])
- ->where('data_type',SeeRange::type_seven)
- ->where('type',SeeRange::data_three)
- ->select('data_id')
- ->get()->toArray();
- return array_column($return,'data_id');
- }
- //客户联系方式
- public function salesOrderCustomerMessageSearch($data){
- $return = CustomerInfo::where('del_time',0)
- ->where("type",CustomerInfo::type_one)
- ->where('contact_info','LIKE', '%'.$data['contact_info'].'%')
- ->select('customer_id')
- ->get()->toArray();
- return array_column($return,'customer_id');
- }
- //客户创建人
- public function salesOrderCustomerCrtSearch($user,$data){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['customer_crt_name'].'%')
- ->select('id')->get()->toArray();
- $emp_id = array_column($emp_id,'id');
- $model2 = Customer::Clear($user,$data);
- $customer = $model2->where('del_time',0)
- ->whereIn('crt_id', $emp_id)
- ->select('id')
- ->get()->toArray();
- return array_column($customer,'id');
- }
- //收付款人搜索
- public function paymentReceiptSearch($data){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['belong'].'%')
- ->select('id')->get()->toArray();
- $emp_id = array_column($emp_id,'id');
- //单据中选择的签订人
- $id = PaymentReceiptInfo::where('del_time',0)
- ->where('type',PaymentReceiptInfo::type_two)
- ->whereIn('data_id',$emp_id)
- ->select('payment_receipt_id')
- ->get()->toArray();
- return array_unique(array_column($id,'payment_receipt_id'));
- }
- //创建人
- public function crtNameSearch($data){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['crt_name'].'%')
- ->select('id')->get()->toArray();
- return array_column($emp_id,'id');
- }
- public function crtContactSearch($data){
- $id = CustomerInfo::where('del_time',0)
- ->where('type',CustomerInfo::type_one)
- ->where('contact_info','LIKE', '%'.$data['title_t'].'%')
- ->select('customer_id')->get()->toArray();
- return array_column($id,'customer_id');
- }
- //负责人
- public function customerSearch($data){
- $emp_id = Employee::where('del_time',0)
- ->where('emp_name','LIKE', '%'.$data['fz'].'%')
- ->select('id')->get()->toArray();
- $emp_id = array_column($emp_id,'id');
- //单据中选择的负责人
- $customer_id = CustomerInfo::where('del_time',0)
- ->where('type',CustomerInfo::type_two)
- ->whereIn('data_id',$emp_id)
- ->select('customer_id')
- ->get()->toArray();
- return array_unique(array_column($customer_id,'customer_id'));;
- }
- //获取可见人施工单
- public function RangeConstructionEmpDetail($data_id = 0){
- if(empty($data_id)) return [];
- $see = ConstructionInfo::where('del_time',0)
- ->whereIn('construction_id',$data_id)
- ->where('type',ConstructionInfo::type_three)
- ->get()->toArray();
- $emp_map = Employee::where('del_time',0)
- ->whereIn('id',array_column($see,'employee_id'))
- ->pluck('emp_name','id')->toArray();
- $employee = [];
- foreach ($see as $value){
- $name = $emp_map[$value['employee_id']] ?? '';
- if(! empty($name)){
- $tmp = [
- 'id' => $value['employee_id'],
- 'emp_name' => $emp_map[$value['employee_id']] ?? '',
- ];
- $employee[$value['construction_id']][] = $tmp;
- }
- }
- return $employee;
- }
- //客户类型
- public function customerBasicTypeSearch($customer_type, $type){
- $result = BasicType::where('del_time',0)
- ->whereIn('type',$type)
- ->where('title', $customer_type)
- ->select('id')->get()->toArray();
- return array_column($result,'id');
- }
- //全部 待审 已审核 -----------------------------------------------
- public static function sportsBagCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForSportsCheck($user,$search);
- //待审核
- $check = implode(",", SportsBag::$wait_check);
- $args = "(state IN (" . implode(",", SportsBag::$wait_check) ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(SportsBag::$wait_check, [SportsBag::STATE_ONE]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state = ". SportsBag::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForSportsCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核
- $args = "(state = " . SportsBag::STATE_ONE . ")";
- $data = SportsBag::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function paymentReceiptCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForPaymentCheck($user,$search);
- //待审核
- $check = implode(",", SportsBag::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $id = implode(",", $id);
- $check_2 = implode(',', array_diff(SportsBag::$wait_check, [PaymentReceipt::STATE_ONE]));
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state = ". PaymentReceipt::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForPaymentCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核
- $args = "(state = " . PaymentReceipt::STATE_ONE . ")";
- $data = PaymentReceipt::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function salesOrderCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForSalesCheck($user,$search);
- //待审核
- $check = implode(",", SalesOrder::$wait_check);
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(SalesOrder::$wait_check, [SalesOrder::State_one]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审 线上订单的已审核是2 其它是 3
- $args = SalesOrder::search;
- }
- return $args;
- }
- private static function getWaitForSalesCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核合同
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state = " . SalesOrder::State_one . ")";
- $data = SalesOrder::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function invoiceCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForInvoiceCheck($user,$search);
- //待审核
- $check = implode(",", InvoiceOrder::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(InvoiceOrder::$wait_check, [InvoiceOrder::STATE_ONE]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state = ". InvoiceOrder::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForInvoiceCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . InvoiceOrder::STATE_ONE . ")";
- $data = InvoiceOrder::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function returnExchangeOrderCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForReturnExchangeCheck($user,$search);
- //待审核
- $check = implode(",", ReturnExchangeOrder::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(ReturnExchangeOrder::$wait_check, [ReturnExchangeOrder::State_one]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state = ". ReturnExchangeOrder::State_two . ")";
- }
- return $args;
- }
- private static function getWaitForReturnExchangeCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . ReturnExchangeOrder::State_one . ")";
- $data = ReturnExchangeOrder::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function constructionCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForConstructionCheck($user,$search);
- //待审核
- $check = implode(",", Construction::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(Construction::$wait_check, [Construction::STATE_ONE]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state >= ". Construction::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForConstructionCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . Construction::STATE_ONE . ")";
- $data = Construction::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- public static function purchaseCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForPurchaseCheck($user,$search);
- //待审核
- $check = implode(",", PurchaseOrder::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(PurchaseOrder::$wait_check, [PurchaseOrder::STATE_ONE]));
- $id = implode(",", $id);
- if($wait_for_me){
- if(empty($id)) {
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }else{
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
- }
- }
- }
- }elseif($search['is_check'] == 2){
- //已审
- $args = "(state >= ". PurchaseOrder::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForPurchaseCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . PurchaseOrder::STATE_ONE . ")";
- $data = PurchaseOrder::where('del_time',0)
- ->whereRaw($args)
- ->select('order_number','id')
- ->get()->toArray();
- if(empty($data)) return [true, []];
- list($status,$msg) = self::getWaitCommon($data,$user);
- return [$status, $msg];
- }
- private static function getWaitCommon($data,$user){
- $data_map = array_column($data,'id','order_number');
- //查找对应审批流数据
- $orderNoGroups = OaOrder::whereIn('order_no', array_column($data,'order_number'))
- ->get()
- ->groupBy('order_no');
- $maxIds = $orderNoGroups->map(function ($group) {
- return $group->max('id');
- });
- $map = $maxIds->toArray();
- if(empty($map)) return [true, []];
- $oa_order_id = array_values($map);
- $map2 = array_flip($map);
- unset($map);
- //获取审批流下的人
- $list = OaOrderSub::whereIn('oa_order_id', $oa_order_id)
- ->whereIn('state',[0,1])
- ->select('id','state','oa_order_id')
- ->orderBy('id', 'desc')
- ->get()->toArray();
- $subEmployeeList = OaOrderSubEmployee::whereIn('oa_order_id', $oa_order_id)
- ->where('employee_id',$user['id'])
- ->get()->toArray();
- if(empty($subEmployeeList)) return [true, []];
- //每条数据对应的人
- $emp_id_key_list = [];
- foreach ($subEmployeeList as $v) {
- $emp_id_key_list[$v['oa_order_sub_id']][] = $v['employee_id'];
- }
- unset($subEmployeeList);
- $flag = $id = [];
- foreach ($list as $v) {
- //不存在单号或者已存在单号返回数据
- if(empty($v['oa_order_id']) || isset($flag[$v['oa_order_id']])) continue;
- $emp_tmp = $emp_id_key_list[$v['id']] ?? [];
- $flag[$v['oa_order_id']] = $emp_tmp;
- $order_number = $map2[$v['oa_order_id']] ?? "";
- $sales_id = $data_map[$order_number] ?? 0;
- if(in_array($user['id'], $emp_tmp)) $id[] = $sales_id;
- }
- unset($flag);
- return [true, $id];
- }
- //全部 待审 已审核 -----------------------------------------------
- }
|