CopyCompany.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\listener;
  4. use app\cxinv\model\CompanyInfo;
  5. use app\cxinv\model\SupplierInfo;
  6. use app\user\model\Business;
  7. use app\user\model\CustomerInfo;
  8. use app\user\model\Supplier;
  9. class CopyCompany
  10. {
  11. private $_delaway=['供应商发货','公司自提'];
  12. private $_applyway=['正式供应商','临时供应商'];
  13. private $_source=['客户提供','供应商','公司开发'];
  14. private $_cat=['生产厂家','代理商','经销商','分销商','电商平台'];
  15. private $_level=['生产厂家','一级代理','二级代理'];
  16. private $_payway=['现结','月清','双月请'];
  17. private $_catpay=['个人独私企业','合伙企业','有限责任公司','供应商','股份有限责任公司','有限责任公司(自然人独资)','有限责任公司(自然人独资或控股)','村级集体经济组织','股份有限公司'];
  18. /**
  19. * 事件监听处理
  20. *
  21. * @return mixed
  22. */
  23. public function handle($event)
  24. {
  25. if($event['type']==1){
  26. $company = Business::where(['companyNo'=>$event['code'],"is_del"=>0])->findOrEmpty();
  27. if(!$company->isEmpty())$this->checkcompany($company);
  28. }else if($event['type']==2){
  29. $result=CustomerInfo::where(['companyNo'=>$event['code'],"is_del"=>0])->findOrEmpty();
  30. if(!$result->isEmpty())$this->checkcustomer($result);
  31. }else if($event['type']==3){
  32. $result=Supplier::where(['code'=>$event['code'],'is_del'=>0])->findOrEmpty();
  33. if(!$result->isEmpty())$this->checkSupplier($result);
  34. }
  35. }
  36. private function checkcompany($supplier){
  37. $comp= CompanyInfo::where(['companyNo'=>$supplier['companyNo'],'is_del'=>0])->findOrEmpty();
  38. if($comp->isEmpty()){
  39. $data = [
  40. 'companyNo'=>$supplier['companyNo'],
  41. 'company_name'=>$supplier['company'],
  42. 'company_address'=>$supplier['inv_addr'],
  43. 'company_license'=>$supplier['inv_code'],
  44. 'bank_name'=>$supplier['inv_bank'],
  45. 'bankNo'=>$supplier['inv_bankNo'],
  46. 'contector'=>$supplier['contactor'],
  47. 'mobile'=>$supplier['mobile']??$supplier['invoice_mobile'],
  48. 'company_img'=>$supplier['license_img'],
  49. 'input_ticket'=>0,
  50. 'out_ticket'=>0,
  51. 'voider'=>'',
  52. 'payee'=>'',
  53. 'drawer'=>'',
  54. 'reviewer'=>'',
  55. 'ownerPlace'=>'',
  56. 'denomination'=>'',
  57. 'invoiceType'=>'',
  58. 'invoice_title'=>$supplier['invoice_title'],
  59. 'status'=>0,
  60. ];
  61. }else{
  62. $data = [
  63. 'company_name'=>$supplier['company']??$comp['company_name'],
  64. 'company_address'=>$supplier['inv_addr'],
  65. 'company_license'=>$supplier['inv_code']??$comp['company_license'],
  66. 'bank_name'=>$supplier['inv_bank'],
  67. 'bankNo'=>$supplier['inv_bankNo'],
  68. 'contector'=>$supplier['contactor']??$comp['contector'],
  69. 'mobile'=>$supplier['invoice_mobile'],
  70. 'company_img'=>$supplier['license_img']??$comp['company_img'],
  71. 'invoice_title'=>$supplier['invoice_title'],
  72. ];
  73. }
  74. $comp->save($data);
  75. }
  76. private function checkcustomer($supplier){
  77. $comp= \app\cxinv\model\CustomerInfo::where(['companyNo'=>$supplier['companyNo'],'is_del'=>0])->findOrEmpty();
  78. if($comp->isEmpty()){
  79. $data = [
  80. 'companyNo'=>$supplier['companyNo'],
  81. 'companyName'=>$supplier['companyName'],
  82. 'creater'=>$supplier['creater'],
  83. 'area'=>$supplier['area'],
  84. 'status'=>1,
  85. 'addtime'=>date('Y-m-d H:i:s'),
  86. 'updatetime'=>date('Y-m-d H:i:s')
  87. ];
  88. }else{
  89. $data = [
  90. 'companyNo'=>$supplier['companyNo'],
  91. 'companyName'=>$supplier['companyName'],
  92. 'is_del'=>$supplier['is_del']
  93. ];
  94. }
  95. $comp->save($data);
  96. }
  97. private function checkSupplier($supplier){
  98. $comp= SupplierInfo::where(['code'=>$supplier['code']])->findOrEmpty();
  99. if($comp->isEmpty()){
  100. $data= [
  101. 'name' => $supplier['name'],
  102. 'code' => $supplier['code'],
  103. 'source' => $this->_source[$supplier['source']]??$this->_source[0],
  104. 'contector' => $supplier['contactor']??'',
  105. 'post' => $supplier['position']??'',
  106. 'type' => 1,
  107. 'nature' => $supplier['nature']??'',
  108. 'corporation' => $supplier['legaler']??'',
  109. 'registertime' => $supplier['registertime']??'',
  110. 'capital' => $supplier['capital']??'',
  111. 'supplier_type' => $this->_cat[$supplier['supplier_type']]??'',
  112. 'pay_method' => $this->_payway[$supplier['pay_type']],
  113. 'paydays' => $supplier['pay_day'],
  114. 'mobile' => $supplier['mobile']??'',
  115. 'address' => $supplier['addr']??'',
  116. 'return_ticket' => $supplier['ticket_type'],
  117. 'delivery' => $this->_delaway[$supplier['delivery_way']]??'',
  118. 'status' => 1,
  119. 'addtime' => $supplier['addtime']??date('Y-m-d H:i:s'),
  120. 'updatetime' => $supplier['updatetime']??date('Y-m-d H:i:s'),
  121. 'registercode' => $supplier['registercode']??'',
  122. 'level' => $this->_level[$supplier['level']]??'',
  123. 'product_category' => $supplier['product_category'],
  124. 'license_img' => $supplier['license_img']
  125. ];
  126. }else{
  127. $data = [
  128. 'name' => $supplier['name'],
  129. 'source' => $supplier['source'],
  130. 'contector' => $supplier['contactor']??'',
  131. 'post' => $supplier['position']??'',
  132. 'type' => 1,
  133. 'nature' => $supplier['nature'],
  134. 'corporation' => $supplier['legaler'],
  135. 'registertime' => $supplier['registertime'],
  136. 'capital' => $supplier['capital']??'',
  137. 'supplier_type' => $this->_cat[$supplier['supplier_type']]??'',
  138. 'pay_method' => $supplier['pay_type'],
  139. 'paydays' => $supplier['pay_day']??'0',
  140. 'mobile' => $supplier['mobile']??'',
  141. 'address' => $supplier['addr'],
  142. 'return_ticket' => $supplier['ticket_type'],
  143. 'delivery' => $this->_delaway[$supplier['delivery_way']]??'',
  144. 'status' => 1,
  145. 'addtime' => $supplier['addtime'],
  146. 'updatetime' => $supplier['updatetime'],
  147. 'registercode' => $supplier['registercode'],
  148. 'level' => $this->_level[$supplier['level']]??'',
  149. 'product_category' => $supplier['product_category'],
  150. ];
  151. }
  152. $comp->save($data);
  153. }
  154. }