wugg 2 سال پیش
والد
کامیت
0fad9aebd8
2فایلهای تغییر یافته به همراه33 افزوده شده و 20 حذف شده
  1. 21 11
      app/admin/command/QueryInvalidInvoice.php
  2. 12 9
      app/admin/controller/OrderInv.php

+ 21 - 11
app/admin/command/QueryInvalidInvoice.php

@@ -28,29 +28,39 @@ class QueryInvalidInvoice extends Command
     	Db::startTrans();
     	try{
     	$data =Db::name("invoice_return")->where(["status"=>1,"discard"=>2])->where("updatetime","<=",date("Y-m-d H:i:s"))->lock(true)->findOrEmpty();
-    	if(empty($data))return;
+    	if(empty($data)){
+    		Db::rollback();
+    		return ;
+	    };
     	$invoiceInfo = Db::name("invoice_ticket")->where(["invNo"=>$data['invNo'],"is_del"=>0,"status"=>1])->findOrEmpty();
-    	if(empty($invoiceInfo))throw new \Exception("未找到开票数据");
+    	if(empty($invoiceInfo))throw new \Exception($data['invNo']."未找到开票数据");
 		$check=$this->ChickInvoice($invoiceInfo['seller_id'],$invoiceInfo['inv_code'],$invoiceInfo['inv_number']);
 		if(isset($check['ZTDM']) && $check['ZTDM']=='001000') {
 			$reups=Db::name("invoice_return")->where($data)->update(["discard"=>2,"remark"=>$data['remark']."({$check['ZTXX']})","updatetime"=>date("Y-m-d H:i:s",time()+120)]);
 			if($reups==false)throw new \Exception("退票数据更新失败");
-			throw new \Exception("发票作废中");
+			Db::commit();
+			$output->writeln("[$date] {$data['invNo']} {$check['ZTXX']}");
+			return ;
+
 		}
 		if(isset($check['ZTDM']) && $check['ZTDM']=='000000'){
 			$reup=Db::name("invoice_return")->where($data)->update(["status"=>2,"discard"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-			if($reup==false)throw new \Exception("退票数据更新失败");
+			if($reup==false)throw new \Exception($data['invNo']."退票数据更新失败");
+			$poolup=Db::name("invoice_pool")->where(["invNo"=>$data['invNo'],"is_del"=>0,"status"=>4])->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
+			if($poolup==false)throw new \Exception($data['invNo']."开票票数据更新失败");
 			$ticket =  Db::name("invoice_ticket")->where(["invNo"=>$data['invNo'],"is_del"=>0,"status"=>1])->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
-			if($ticket==false)throw new \Exception("退票数据更新失败");
+			if($ticket==false)throw new \Exception($data['invNo']."发票详情数据更新失败");
+			$infoup =Db::name("invoice_good")->where(["invNo"=>$data['invNo'],"is_del"=>0])->update(["goodNum"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
+            if($infoup==false)throw  new \Exception($data['invNo']."发票商品信息修改失败");
 			  $qrdArr=Db::name("assoc")->where(["viceCode"=>$data['invNo'],"is_del"=>0,"status"=>2])->column("id,orderCode,cancel_fee");
                      if(!empty($qrdArr)){
                           foreach ($qrdArr as $value){
                               $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
                               if($qrdinfo==false){
-                                throw  new \Exception("确认单信息未找到");
+                                throw  new \Exception($value['orderCode']."确认单信息未找到");
                               }
                               if($qrdinfo['ainv_fee']<$value['cancel_fee']){
-                                   throw  new \Exception("确认单信息开票金额不足");
+                                   throw  new \Exception($value['orderCode']."确认单信息开票金额不足");
                               }
                               $update =[
                                   "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
@@ -61,20 +71,20 @@ class QueryInvalidInvoice extends Command
                               ];
                               $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
                               if($qrdup==false){
-                                  throw  new \Exception("确认单信息更新失败");
+                                  throw  new \Exception($value['orderCode']."确认单信息更新失败");
                               }
                               $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
                               $assocup =Db::name("assoc")->where($value)->update($assoc);
                               if($assocup==false){
-                                  throw  new \Exception("确认单关联信息更新失败");
+                                  throw  new \Exception($value['orderCode']."确认单关联信息更新失败");
                               }
                           }
                      }else{
-                     	throw  new \Exception("未找到关联订单数据信息");
+                     	throw  new \Exception($data['invNo']."未找到关联订单数据信息");
                      }
 		}else{
 			$reup=Db::name("invoice_return")->where($data)->update(["status"=>4,"remark"=>$data['remark']."({$check['ZTXX']})","updatetime"=>date("Y-m-d H:i:s")]);
-			if($reup==false)throw new \Exception("退票数据更新失败");
+			if($reup==false)throw new \Exception($data['invNo']."退票数据更新失败");
 		}
 		Cache::store("redis")->set("queryinvalidinvoice",0);
 		Db::commit();

+ 12 - 9
app/admin/controller/OrderInv.php

@@ -483,7 +483,7 @@ class OrderInv extends BaseController{
                               "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
                               "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
                               "inv_status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 1 : 2,
-                              "status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ?0 : 1,
+                              "status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0&&$qrdinfo['pay_status']==1 ?0 : 1,
                               "updatetime"=>date("Y-m-d H:i:s"),
                           ];
                           $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
@@ -506,9 +506,7 @@ class OrderInv extends BaseController{
                                   'is_del' => 0,
                                   'invNo' => $invNo,
                                   'orderCode' => $value['orderCode']
-                              ])
-                              ->dec('goodNum', $qrdinfo['goodNum'])
-                              ->update();
+                              ])->update(["goodNum"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
                       }
                  }
             }
@@ -867,6 +865,10 @@ class OrderInv extends BaseController{
 		                }
             		}
                 if($status==2){
+                	    $infoup =Db::name("invoice_good")->where(["invNo"=>$return['invNo'],"is_del"=>0])->update(["goodNum"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
+                	    if($infoup==false)throw  new \Exception("退票商品信息修改失败");
+                	    $poolup=Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0,"status"=>4])->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
+						if($poolup==false)throw new \Exception($return['invNo']."开票票数据更新失败");
                       $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0,"status"=>2])->column("id,orderCode,cancel_fee");
                      if(!empty($qrdArr)){
                           foreach ($qrdArr as $value){
@@ -881,7 +883,7 @@ class OrderInv extends BaseController{
                               }
                               $update =[
                                   "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
-                                    "ainv_fee"=>$qrdinfo['ainv_fee']-$value['cancel_fee'],
+                                  "ainv_fee"=>$qrdinfo['ainv_fee']-$value['cancel_fee'],
                                   "inv_status"=>$qrdinfo['inv_fee']==0 &&$qrdinfo['ainv_fee']-$value['cancel_fee']==0 ? 1 : 2,
                                   "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']-$value['cancel_fee']==0&&$qrdinfo['pay_status']==1 ?0 : 1,
                                   "updatetime"=>date("Y-m-d H:i:s"),
@@ -1246,15 +1248,16 @@ class OrderInv extends BaseController{
                               Db::rollback();
                               return error_show(1003,"确认单信息未找到");
                           }
-                          if($qrdinfo['inv_fee']<$value['cancel_fee']){
+                          if($qrdinfo['ainv_fee']<$value['cancel_fee']){
                                Db::rollback();
                               return error_show(1003,"确认单信息开票金额不足");
                           }
                           $update =[
                               "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
-                              "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
-                              "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']-$value['cancel_fee']==0 ? 1 : 2,
-                              "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']-$value['cancel_fee']==0 && $qrdinfo['pay_status'] ?0 : 1,
+                              "ainv_fee"=>$qrdinfo['ainv_fee']-$value['cancel_fee'],
+                              "inv_status"=>$qrdinfo['inv_fee']==0 &&$qrdinfo['ainv_fee']-$value['cancel_fee']==0 ?
+                              1 : 2,
+                              "status"=>$qrdinfo['inv_fee']==0 &&$qrdinfo['ainv_fee']-$value['cancel_fee']==0 && $qrdinfo['pay_status']==1 ?0 : 1,
                               "updatetime"=>date("Y-m-d H:i:s"),
                           ];
                           $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);