|
@@ -760,9 +760,7 @@ class OrderInv extends BaseController{
|
|
|
if ($status==""){
|
|
|
return error_show(1005,"参数 status 不能为空");
|
|
|
}
|
|
|
-
|
|
|
$remark =isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
|
|
|
-
|
|
|
$return_reason =isset($this->post['return_reason'])&&$this->post['return_reason']!="" ? trim($this->post['return_reason']):"";
|
|
|
$return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
|
|
|
if($return==false){
|
|
@@ -826,18 +824,32 @@ class OrderInv extends BaseController{
|
|
|
if($up){
|
|
|
if($status==1){
|
|
|
if($return_type==1){
|
|
|
+ $discard=0;
|
|
|
if(date("Y-m",strtotime($ticket["open_date"]))==date("Y-m")){
|
|
|
//当月纸质普通发票+纸质专用发票 作废
|
|
|
- if(in_array($ticket['inv_type'],['004','007']))$this->addDiscard($ticket,$returnCode);
|
|
|
+ if(in_array($ticket['inv_type'],['004','007'])){
|
|
|
+ $discard=1;
|
|
|
+ $result= $this->addDiscard($ticket,$returnCode);
|
|
|
+ }
|
|
|
+
|
|
|
//当月电子普票红冲
|
|
|
- if($ticket['inv_type']=='026') $this->addRedOpen($ticket,$return_reason,$invinfo['company_type'], $returnCode);
|
|
|
+ if($ticket['inv_type']=='026')$result= $this->addRedOpen($ticket,$return_reason,$invinfo['company_type'], $returnCode);
|
|
|
//当月电子专票红冲
|
|
|
- if($ticket['inv_type']=='028') $this->addApplyRed($ticket,$returnCode);
|
|
|
+ if($ticket['inv_type']=='028')$result= $this->addApplyRed($ticket,$returnCode);
|
|
|
}else{
|
|
|
//跨月票都走红冲
|
|
|
- if(in_array($ticket['inv_type'],['007','026'])) $this->addRedOpen($ticket,$return_reason,$invinfo['company_type'], $returnCode);
|
|
|
- if(in_array($ticket['inv_type'],['004','028'])) $this->addApplyRed($ticket,$returnCode);
|
|
|
+ if(in_array($ticket['inv_type'],['007','026'])) $result= $this->addRedOpen($ticket,$return_reason,$invinfo['company_type'], $returnCode);
|
|
|
+ if(in_array($ticket['inv_type'],['004','028'])) $result= $this->addApplyRed($ticket,$returnCode);
|
|
|
}
|
|
|
+ if($result['code']==0){
|
|
|
+ if($discard==1){
|
|
|
+ $status=2;
|
|
|
+ }
|
|
|
+ if(isset($result['data']) &&$result['data']['invRed']!='' ){
|
|
|
+ Db::name("invoice_return")->where(["returnCode"=>$returnCode])->update(['red_inv'=>$result['data']['invRed']]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}else{
|
|
|
$invpool=[
|
|
|
"invNo"=>$invinfo['invNo'],
|
|
@@ -1967,14 +1979,14 @@ class OrderInv extends BaseController{
|
|
|
if($upred==false){
|
|
|
throw new Exception("红冲提交失败",1006);
|
|
|
}
|
|
|
- return app_show(0,"红冲已提交");
|
|
|
+ return app_show(0,"红冲已提交",["invRed"=>$invRed]);
|
|
|
}
|
|
|
|
|
|
private function addDiscard($ticket=[],$returnCode){
|
|
|
$invoice=Config::get("invoice");
|
|
|
$tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
|
|
|
$result=$tax->DeprecateInvoices($ticket['seller_id'],$ticket['inv_type'],$ticket['inv_code'],$ticket['inv_number'],1);
|
|
|
- if(isset($result['ZTDM']) && $result['ZTDM']=='050000'){
|
|
|
+ if(isset($result['ZTDM']) && ($result['ZTDM']=='050000' || $result['ZTDM']=='053000')){
|
|
|
Db::name("invoice_return")->where(['returnCode'=>$returnCode])->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
$up =Db::name("invoice_pool")->where(['invNo'=>$ticket['invNo']])->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
if($up){
|