downredinvres.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\facade\Config;
  7. use think\console\input\Argument;
  8. use think\console\input\Option;
  9. use think\console\Output;
  10. use think\facade\Cache;
  11. use think\facade\Db;
  12. class downredinvres extends Command
  13. {
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('downredinvres')
  18. ->setDescription('the downredinvres command');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. $GetOrderInfoAndInvoiceInfo= Cache::store("redis")->get("downredinvres");
  23. if($GetOrderInfoAndInvoiceInfo==0) Cache::store("redis")->set("downredinvres",1,180);
  24. Db::startTrans();
  25. $date= date("Y-m-d H:i:s");
  26. $row =Db::name("invoice_red")->where(["status"=>1,"is_del"=>0])->where("updatetime","<=",date("Y-m-d H:i:s"))
  27. ->lock(true)->findOrEmpty();
  28. try{
  29. $data=["updatetime"=>date("Y-m-d H:i:s",time()+600)];
  30. $opendatetime =date("Ymd",strtotime($row['addtime']));
  31. $invoice=Config::get("invoice");
  32. $Tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
  33. $result=$Tax->DownloadRedInvoiceApplicationResult($row['SQBSCQQPCH'],$row['XHFSBH'],$row['FPLXDM'],$opendatetime);
  34. $data['status']=5;
  35. $data['remark']='红冲申请提交失败';
  36. if(isset($result['ZTDM']) && $result['ZTDM']=='060000'){
  37. $resultChild=$result['HZSQDXZZXX'][0]['HZSQDXZTXX'];
  38. if($resultChild['ZTDM']=='060000'){
  39. $data['status']=2;
  40. $data['XXBBH']=$resultChild['XXBBH'];
  41. $data['remark']='申请表审核结果下载下载成功!';
  42. }
  43. if($resultChild['ZTDM']=='060111'){
  44. $data['status']=1;
  45. $data['XXBBH']=$resultChild['XXBBH'];
  46. $data['remark']='申请表审核结果下载正在下载中!';
  47. }
  48. }
  49. if($data['status']==5){
  50. throw new \Exception($result['ZTXX'], 10006);
  51. }
  52. Db::name("invoice_red")->where($row)->update($data);
  53. Db::commit();
  54. $output->writeln("[$date] ".$row['invRed'].'发票申请表获取成功');
  55. }catch (\Exception $e){
  56. Db::rollback();
  57. $output->writeln("[$date] ".$row['invRed'].$e->getMessage());
  58. }
  59. }
  60. }