CopySupplier.php 7.5 KB

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