wugg 8 mēneši atpakaļ
vecāks
revīzija
3c1469f75b
1 mainītis faili ar 164 papildinājumiem un 0 dzēšanām
  1. 164 0
      app/listener/CopyCompany.php

+ 164 - 0
app/listener/CopyCompany.php

@@ -0,0 +1,164 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\listener;
+
+use app\cxinv\model\CompanyInfo;
+use app\cxinv\model\SupplierInfo;
+use app\user\model\Business;
+use app\user\model\CustomerInfo;
+use app\user\model\Supplier;
+class CopyCompany
+{
+    private $_delaway=['供应商发货','公司自提'];
+	private $_applyway=['正式供应商','临时供应商'];
+	private $_source=['客户提供','供应商','公司开发'];
+	private $_cat=['生产厂家','代理商','经销商','分销商','电商平台'];
+	private $_level=['生产厂家','一级代理','二级代理'];
+	private $_payway=['现结','月清','双月请'];
+	private $_catpay=['个人独私企业','合伙企业','有限责任公司','供应商','股份有限责任公司','有限责任公司(自然人独资)','有限责任公司(自然人独资或控股)','村级集体经济组织','股份有限公司'];
+
+    /**
+     * 事件监听处理
+     *
+     * @return mixed
+     */
+    public function handle($event)
+    {
+        if($event['type']==1){
+            $company = Business::where(['companyNo'=>$event['code'],"is_del"=>0])->findOrEmpty();
+            if(!$company->isEmpty())$this->checkcompany($company);
+        }else if($event['type']==2){
+            $result=CustomerInfo::where(['companyNo'=>$event['code'],"is_del"=>0])->findOrEmpty();
+            if(!$result->isEmpty())$this->checkcustomer($result);
+        }else if($event['type']==3){
+            $result=Supplier::where(['code'=>$event['code'],'is_del'=>0])->findOrEmpty();
+            if(!$result->isEmpty())$this->checkSupplier($result);
+        }
+    }
+
+   private function checkcompany($supplier){
+		$comp= CompanyInfo::where(['companyNo'=>$supplier['companyNo'],'is_del'=>0])->findOrEmpty();
+		if($comp->isEmpty()){
+			$data = [
+	           'companyNo'=>$supplier['companyNo'],
+	           'company_name'=>$supplier['company'],
+	           'company_address'=>$supplier['inv_addr'],
+	           'company_license'=>$supplier['inv_code'],
+	           'bank_name'=>$supplier['inv_bank'],
+	           'bankNo'=>$supplier['inv_bankNo'],
+	           'contector'=>$supplier['contactor'],
+	           'mobile'=>$supplier['mobile']??$supplier['invoice_mobile'],
+	           'company_img'=>$supplier['license_img'],
+	           'input_ticket'=>0,
+	           'out_ticket'=>0,
+	           'voider'=>'',
+	           'payee'=>'',
+	           'drawer'=>'',
+	           'reviewer'=>'',
+	           'ownerPlace'=>'',
+	           'denomination'=>'',
+	           'invoiceType'=>'',
+	           'invoice_title'=>$supplier['invoice_title'],
+	           'status'=>0,
+        ];
+		}else{
+			$data = [
+	           'company_name'=>$supplier['company']??$comp['company_name'],
+	           'company_address'=>$supplier['inv_addr'],
+	           'company_license'=>$supplier['inv_code']??$comp['company_license'],
+	           'bank_name'=>$supplier['inv_bank'],
+	           'bankNo'=>$supplier['inv_bankNo'],
+	           'contector'=>$supplier['contactor']??$comp['contector'],
+	           'mobile'=>$supplier['invoice_mobile'],
+	           'company_img'=>$supplier['license_img']??$comp['company_img'],
+	           'invoice_title'=>$supplier['invoice_title'],
+             ];
+		}
+		$comp->save($data);
+    }
+
+     private function checkcustomer($supplier){
+		$comp= \app\cxinv\model\CustomerInfo::where(['companyNo'=>$supplier['companyNo'],'is_del'=>0])->findOrEmpty();
+		if($comp->isEmpty()){
+			$data = [
+	           'companyNo'=>$supplier['companyNo'],
+	           'companyName'=>$supplier['companyName'],
+	           'creater'=>$supplier['creater'],
+	           'area'=>$supplier['area'],
+	           'status'=>1,
+	           'addtime'=>date('Y-m-d H:i:s'),
+	           'updatetime'=>date('Y-m-d H:i:s')
+       ];
+		}else{
+			$data = [
+	           'companyNo'=>$supplier['companyNo'],
+	           'companyName'=>$supplier['companyName'],
+	           'is_del'=>$supplier['is_del']
+             ];
+		}
+		$comp->save($data);
+    }
+
+     private function checkSupplier($supplier){
+		$comp= SupplierInfo::where(['code'=>$supplier['code']])->findOrEmpty();
+
+		if($comp->isEmpty()){
+			$data= [
+				            'name' => $supplier['name'],
+                            'code' => $supplier['code'],
+                            'source' => $this->_source[$supplier['source']]??$this->_source[0],
+                            'contector' => $supplier['contactor']??'',
+                            'post' => $supplier['position']??'',
+                            'type' => 1,
+                            'nature' =>  $supplier['nature']??'',
+                            'corporation' => $supplier['legaler']??'',
+                            'registertime' => $supplier['registertime']??'',
+                            'capital' => $supplier['capital']??'',
+                            'supplier_type' => $this->_cat[$supplier['supplier_type']]??'',
+                            'pay_method' => $this->_payway[$supplier['pay_type']],
+                            'paydays' => $supplier['pay_day'],
+                            'mobile' => $supplier['mobile']??'',
+                            'address' => $supplier['addr']??'',
+                            'return_ticket' => $supplier['ticket_type'],
+                            'delivery' => $this->_delaway[$supplier['delivery_way']]??'',
+                            'status' => 1,
+                            'addtime' => $supplier['addtime']??date('Y-m-d H:i:s'),
+                            'updatetime' => $supplier['updatetime']??date('Y-m-d H:i:s'),
+                            'registercode' => $supplier['registercode']??'',
+                            'level' => $this->_level[$supplier['level']]??'',
+                            'product_category' => $supplier['product_category'],
+                            'license_img' => $supplier['license_img']
+
+			];
+		}else{
+			$data = [
+	                        'name' => $supplier['name'],
+                            'source' => $supplier['source'],
+                            'contector' => $supplier['contactor']??'',
+                            'post' => $supplier['position']??'',
+                            'type' => 1,
+                            'nature' =>  $supplier['nature'],
+                            'corporation' => $supplier['legaler'],
+                            'registertime' => $supplier['registertime'],
+                            'capital' => $supplier['capital']??'',
+							'supplier_type' => $this->_cat[$supplier['supplier_type']]??'',
+							'pay_method' => $supplier['pay_type'],
+                            'paydays' => $supplier['pay_day']??'0',
+                            'mobile' => $supplier['mobile']??'',
+                            'address' => $supplier['addr'],
+                            'return_ticket' => $supplier['ticket_type'],
+							'delivery' => $this->_delaway[$supplier['delivery_way']]??'',
+                            'status' => 1,
+                            'addtime' => $supplier['addtime'],
+                            'updatetime' => $supplier['updatetime'],
+                            'registercode' => $supplier['registercode'],
+							'level' => $this->_level[$supplier['level']]??'',
+                            'product_category' => $supplier['product_category'],
+
+             ];
+
+		}
+		$comp->save($data);
+    }
+}