GetOrderInfoAndInvoiceInfo.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\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\Config;use think\facade\Db;
  10. class GetOrderInfoAndInvoiceInfo extends Command
  11. {
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('getorderinfoandinvoiceinfo')
  16. ->setDescription('the getorderinfoandinvoiceinfo command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. // 指令输出
  21. $data = $this->GetData();
  22. foreach ($data as $value){
  23. if($value['status']==1){
  24. $this->GetOrderInfo($value);
  25. }
  26. if($value['status']==2){
  27. Db::name("invoice_pool")->where(["invNo"=>$value['invNo'],"is_del"=>0])->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  28. $this->insertTicket($value['result'],$value['invNo']);
  29. Db::name("invoice_interface")->where($value)->update(["is_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  30. }
  31. if($value['status']==3 || $value['status']==4){
  32. Db::name("invoice_pool")->where(["invNo"=>$value['invNo'],"is_del"=>0])->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
  33. Db::name("invoice_interface")->where($value)->update(["is_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  34. }
  35. }
  36. $output->writeln('getorderinfoandinvoiceinfo');
  37. }
  38. protected function GetData(){
  39. $list=Db::name("invoice_interface")->where([["status",">=",1],["is_check","=",0],["updatetime","<=",date("Y-m-d
  40. H:i:s")]])->cursor();
  41. foreach ($list as $value){
  42. yield $value;
  43. }
  44. }
  45. protected function GetOrderInfo($order){
  46. $invoice=Config::get("invoice");
  47. $tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],'911101050628285328');
  48. $result=$tax->GetOrderInfoAndInvoiceInfo($order['XHFSBH'],$order['DDQQLSH']);
  49. if($result['ZTDM'] && $result['ZTDM']=='000000'){
  50. foreach ($result['DDFPZXX'] as $value){
  51. $zt=$value['DDFPXX']['DDZT'];
  52. $ztxx=$value['DDFPXX']['DDZTXX'];
  53. if($zt=='030000'){
  54. $data= $value['DDFPXX'];
  55. $data['itemlist'] = $value['DDMXXX'];
  56. $exit= json_encode($data,JSON_UNESCAPED_UNICODE);
  57. Db::name("invoice_interface")->where(["DDQQLSH"=>$value['DDFPXX']['DDQQLSH']])->update(["status"=>2,"result"=>$exit,"remark"=>$ztxx,"updatetime"=>date("Y-m-d H:i:s")]);
  58. }
  59. if($zt=='031999' ||$zt=='032997'||$zt=='032999'||$zt=='032998' ){
  60. Db::name("invoice_interface")->where(["DDQQLSH"=>$value['DDFPXX']['DDQQLSH']])->update
  61. (["status"=>4,"is_check"=>1,"remark"=>$ztxx,"updatetime"=>date("Y-m-d H:i:s")]);
  62. }
  63. }
  64. }
  65. }
  66. protected function insertTicket($data,$invNo=''){
  67. $invinfo =Db::name("invoice_ticket")->where(["invNo"=>$invNo,'is_del'=>0])->findOrEmpty();
  68. $json= json_decode($data,true);
  69. if(is_array($json)&&!empty($json)){
  70. if(empty($invinfo)){
  71. $invinfo["invNo"]=$invNo;
  72. $invinfo["status"]=1;
  73. $invinfo["addtime"]=date("Y-m-d H:i:s");
  74. }
  75. $invinfo["inv_type"]=$json['FPLXDM'];
  76. $invinfo["type"]=$json['KPLX'];
  77. $invinfo["inv_code"]=$json['FPDM'];
  78. $invinfo["inv_number"]=$json['FPHM'];
  79. $invinfo["inv_total"]=$json['JSHJ'];
  80. $invinfo["inv_subtotal"]=$json['HJJE'];
  81. $invinfo["open_date"]=$json['KPRQ'];
  82. $invinfo["seller_id"]=$json['XHFSBH'];
  83. $invinfo["seller_title"]=$json['XHFMC'];
  84. $invinfo["seller_addr"]=$json['XHFDZ'];
  85. $invinfo["seller_mobile"]=$json['XHFDH'];
  86. $invinfo["seller_bank"]=$json['XHFYH'];
  87. $invinfo["seller_bankNo"]=$json['XHFZH'];
  88. $invinfo["buyer_id"]=$json['GMFSBH'];
  89. $invinfo["buyer_title"]=$json['GMFMC'];
  90. $invinfo["buyer_addr"]=$json['GMFDZ'];
  91. $invinfo["buyer_mobile"]=$json['GMFDH'];
  92. $invinfo["buyer_bank"]=$json['GMFYH'];
  93. $invinfo["buyer_bankNo"]=$json['GMFZH'];
  94. $invinfo["tax_fee"]=$json['HJSE'];
  95. $invinfo["remark"]=$json['BZ']??$json['CHBZ'];
  96. $invinfo["issuer"]=$json['KPR'];
  97. $invinfo["reciver"]=$json['SKR'];
  98. $invinfo["reviewer"]=$json['FHR'];
  99. $invinfo["check_code"]=$json['JYM'];
  100. $invinfo["item"]=json_encode($json['itemlist'],JSON_UNESCAPED_UNICODE);
  101. Db::name("invoice_ticket")->save($invinfo);
  102. }
  103. }
  104. }