12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- <?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\Inventory;
- 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\ProductAdjustment;
- 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];
- }
- public static function inventoryCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getWaitForinventoryCheck($user,$search);
- //待审核
- $check = implode(",", Inventory::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(Inventory::$wait_check, [Inventory::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 >= ". Inventory::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getWaitForinventoryCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . Inventory::STATE_ONE . ")";
- $data = Inventory::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 productAdjustmentCheck($user,$search){
- $args = "";
- if($search['is_check'] == 1) {
- list($status, $id) = self::getProductAdjustmentCheck($user,$search);
- //待审核
- $check = implode(",", ProductAdjustment::$wait_check);
- $args = "(state IN (" . $check ."))";
- if($status) {
- $wait_for_me = $search['wait_for_me'] ?? 0;
- $check_2 = implode(',', array_diff(ProductAdjustment::$wait_check, [ProductAdjustment::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 >= ". ProductAdjustment::STATE_TWO . ")";
- }
- return $args;
- }
- private static function getProductAdjustmentCheck($user, $search){
- if(! isset($search['wait_for_me'])) return [false, []];
- //获取待审核数据
- $args = "(state = " . ProductAdjustment::STATE_ONE . ")";
- $data = ProductAdjustment::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];
- }
- //全部 待审 已审核 -----------------------------------------------
- }
|