wugg 10 months ago
parent
commit
5a5f802bdb

+ 9 - 7
app/admin/command/GetOrderInfoAndInvoiceInfo.php

@@ -40,6 +40,7 @@ class GetOrderInfoAndInvoiceInfo extends Command
 					$this->GetOrderInfo($value);
 				}
 				if($value['status']==2){
+					
 					if($value['KPLX']==1){
 							$red=Db::name("invoice_red")->where(["invRed"=>$value['invNo'],"is_del"=>0])->find();
 							if($red){
@@ -51,12 +52,16 @@ class GetOrderInfoAndInvoiceInfo extends Command
 							$this->insertTicket($value['result'],$invNo);
 					}else{
 							$invNo = $value['invNo'];
-							$invoicePoo= Db::name('invoice_pool')->where(['invNo'=>$value['invNo'],'is_del'=>0])
-							->findOrEmpty();
 							Db::name("invoice_pool")->where(["invNo"=>$value['invNo'],"is_del"=>0])->update(["status"=>4,"seller_check"=>1,"buyer_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
 							$this->insertTicket($value['result'],$invNo);
-							if($invoicePoo['is_comon']==1)event("comonOrder",["invNo"=>$invNo,"type"=>"inv"]);
-							
+					}
+					if(isset($invNo)&&$invNo!=''){
+						$is_comon= Db::name('invoice_pool')->where(['invNo'=>$invNo,'is_del'=>0])
+																					->value('is_comon');
+						if ($is_comon == 1) {
+							event('comonOrder' ,['invNo'=>$invNo ,'type' =>$value['KPLX']==0?'inv':'rinv']);
+							$output->writeln( "【 $date 】通用订单验票完成".$invNo.$value['KPLX']==0?'开票':'退票');
+						}
 					}
 					Db::name("invoice_interface")->where($value)->update(["is_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
 					
@@ -93,7 +98,6 @@ class GetOrderInfoAndInvoiceInfo extends Command
     }
 
     protected function GetOrderInfo($order){
-//    	$invoice=Config::get("invoice");
     	$invoiceConf=Config::get('invoice');
     	if(!isset($invoiceConf[$order['XHFSBH']])){
     		Db::name('invoice_interface')->where($order)->update(['status'=>4,'remark'=>"金税配置不存在",'updatetime'=>date('Y-m-d H:i:s')]);
@@ -132,7 +136,6 @@ class GetOrderInfoAndInvoiceInfo extends Command
 
     protected function insertTicket($data,$invNo=''){
 	    $json= json_decode($data,true);
-
 		if(is_array($json)&&!empty($json)){
 			$invinfo =Db::name("invoice_ticket")->where(["invNo"=>$invNo,'type'=>$json['KPLX'],'is_del'=>0])->findOrEmpty();
 			if(empty($invinfo)){
@@ -193,7 +196,6 @@ class GetOrderInfoAndInvoiceInfo extends Command
 									0 HSBZ,
 									tax as SL,
 									-taxPrice as SE")->select()->toArray();
-//					$data = $invinfo['DDMXXX']?json_decode($invinfo['DDMXXX'],true):[];
 				}
 			}
 			foreach ($data as $value){

+ 1 - 1
app/admin/command/QueryInvalidInvoice.php

@@ -53,7 +53,7 @@ class QueryInvalidInvoice extends Command
 			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");
+			$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();

+ 2 - 3
app/admin/controller/ComonOrder.php

@@ -40,7 +40,7 @@ class ComonOrder extends Base
     public function list(){
         $post = $this->request->only(["start"=>"","end"=>"","cxCode"=>"","orderCode"=>[],"customerNo"=>"",
         'cgd_status'=>'',"companyNo"=>"",'status'=>[],'relaComNo'=>'','platform_type'=>'','inv_status'=>'','pay_status'=>'', 'page'=>1,'size'=>15],"post","trim");
-        $where=[["qrd.is_del","=",0],['cgd.is_del','=',0]];
+        $where=[["qrd.is_del","=",0],['cgd.is_del','=',0],['qrd.totalPrice','<>',0],['cgd.totalPrice','<>',0]];
         $post['start']==''?:$where[]=["comon_order.addtime",">=",date("Y-m-d 00:00:00",strtotime($post['start']))];
         $post['end']==''?:$where[]=["comon_order.addtime","<=",date("Y-m-d 23:59:59",strtotime($post['end']))];
         $post['cxCode']==''?:$where[]=["comon_order.cxCode","like","%{$post['cxCode']}%"];
@@ -52,8 +52,7 @@ class ComonOrder extends Base
         $post['platform_type']==''?:$where[]=["comon_order.platform_type","=",$post['platform_type']];
         $post['cgd_status']===''?:$where[]=['cgd.cgd_status','=',$post['cgd_status']];
         $post['companyNo']==''?:$where[]=["comon_order.companyNo|comon_order.supplierNo","=",$post['companyNo']];
-        $post['relaComNo']==''?:$where[]=["comon_order.companyNo|comon_order.supplierNo|comon_order.customerNo","=",
-        $post['relaComNo']];
+        $post['relaComNo']==''?:$where[]=["comon_order.companyNo|comon_order.supplierNo|comon_order.customerNo","=", $post['relaComNo']];
         $list=$this->model->withJoin(["qrd","cgd"],"left")->where($where)
         ->order("id desc")->paginate (["page"=>$post['page'],"list_rows"=>$post['size']]);
         $this->success("0",["list"=>$list->items(),"count"=>$list->total()]);

+ 14 - 1
app/admin/controller/Good.php

@@ -3,7 +3,7 @@ declare (strict_types = 1);
 
 namespace app\admin\controller;
 
-use app\admin\model\GoodChange;use think\App;use think\facade\Validate;
+use app\admin\model\GoodChange;use app\admin\model\GoodCombind;use think\App;use think\facade\Validate;
 class Good extends Base
 {
 	protected $model=null;
@@ -38,6 +38,14 @@ class Good extends Base
     	->where($where)
     	->order("id desc")
     	->paginate(["page"=>$param['page'],"list_rows"=>$param["size"]]);
+    	foreach ($list->items() as &$item){
+    		$item->combind=[];
+    		if($item->isCombind==1){
+    			$good = GoodCombind::with(['child'])->where(["spuCode"=>$item->spuCode,"is_del"=>0])->select();
+    		    $item->combind = $good->isEmpty()?[]:$good->toArray();
+    		}
+    	}
+    	
     	$this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
     }
     //批量更新数据状态审核
@@ -113,6 +121,11 @@ class Good extends Base
         if($valid->check($param)==false)$this->error($valid->getError());
         $info = $this->model->where(["spuCode"=>$param['spuCode']])->findOrEmpty();
         if($info->isEmpty())$this->error("商品信息不存在");
+            $info->combind=[];
+    		if($info->isCombind==1){
+    			$good = GoodCombind::with(['child'])->where(['spuCode'=>$info->spuCode,'is_del'=>0])->select();
+    		    $info->combind = $good->isEmpty()?[]:$good->toArray();
+    		}
         $this->success("获取成功",$info);
     }
     //导出列表

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

@@ -911,21 +911,29 @@ class OrderInv extends Base{
 	            $invNum =isset($this->post['invNum'])&&$this->post['invNum']!=''?trim($this->post['invNum']):"";
 	            $open_date =isset($this->post['open_date'])&&$this->post['open_date']!=''?trim($this->post['open_date']):"";
 	            $checkCode =isset($this->post['checkCode'])&&$this->post['checkCode']!=''?trim($this->post['checkCode']):"";
-	            $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floatval($this->post['subtotal_fee']):"";
-	            if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
+	            $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floatval($this->post['subtotal_fee']):0;
+	            $total_fee =isset($this->post['total_fee'])&&$this->post['total_fee']!=''?floatval($this->post['total_fee']):0;
 	            if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
 	            if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
 	            if(in_array($invinfo['inv_type'],['normal','roll',"toll",'electronic'])){
                	    if($checkCode==='') return error_show(1004,"参数 checkCode 不能为空");
                }
-	            if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
+	           //全电子发票
+	           if(in_array($invinfo['inv_type'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
+	           	    //全电发票传含税金额
+	              if($total_fee=='') return error_show(1004,'参数 total_fee 不能为空');
+	           }else{
+	           	//全电发票无invCode
+	           	 if($invCode==='') return error_show(1004,'参数 invCode 不能为空');
+	           	 if($subtotal_fee=='') return error_show(1004,'参数 subtotal_fee 不能为空');
+	           }
             }
         }
-//电子普票 只能红冲 不能作废
-//电子专票 只能红冲 不能作废
-//纸质专票 当月可以作废 次月红冲
-//纸质普票  当月作废 次月红冲
-//专票 红冲先做红字申请
+		//电子普票 只能红冲 不能作废
+		//电子专票 只能红冲 不能作废
+		//纸质专票 当月可以作废 次月红冲
+		//纸质普票  当月作废 次月红冲
+		//专票 红冲先做红字申请
 
          Db::startTrans();
          try{
@@ -964,7 +972,7 @@ class OrderInv extends Base{
 		                        "inv_code"=>$invCode,
 		                        "inv_number"=>$invNum,
 		                        "check_code"=>$checkCode,
-		                        "inv_total"=>0,
+		                        "inv_total"=>$total_fee,
 		                        "inv_subtotal"=>$subtotal_fee,
 		                        "open_date"=>$open_date,
 		                        "item"=>'',

+ 9 - 4
app/admin/controller/Payment.php

@@ -4,7 +4,7 @@ declare (strict_types = 1);
 namespace app\admin\controller;
 
 
-use app\admin\model\CgdInfo;use app\admin\model\FhdChild;use app\admin\model\GoodCombind;use app\admin\model\Pay;use app\admin\model\PayInfo;use app\admin\model\ReportCode;
+use app\admin\model\CgdInfo;use app\admin\model\FhdChild;use app\admin\model\GoodCombind;use app\admin\model\InvoicePay;use app\admin\model\InvoicePool;use app\admin\model\Pay;use app\admin\model\PayInfo;use app\admin\model\ReportCode;
 use think\App;use think\Exception;
 use think\facade\Config;
 use think\facade\Db;
@@ -527,6 +527,14 @@ class Payment extends Base
        	    if(!empty($hpinv)) return error_show(1004,"对账单存在未解除的回票申请单");
        	    if($data['inv_tag']==1)$this->error("存在回票标签未解除");
        	    if($data['pay_tag']==1)$this->error("存在付款标签未解除");
+       	    if($data['is_comon']==1){
+       	    	$invoceAr=InvoicePay::where(["payNo"=>$payNo])->column("invNo");
+       	    	if(!empty($invoceAr)){
+       	    		$ist= InvoicePool::where([["invNo","in",$invoceAr],["status","in",[0,1,2,3,4]]])->select()
+       	    		->isEmpty();
+       	    		if($ist==false)$this->error('通用订单存在开票申请未解除');
+       	    	}
+       	    }
        }
         Db::startTrans();
         try{
@@ -1611,7 +1619,6 @@ class Payment extends Base
             $value['invStatus_cn'] = $this->invStatus[$value['invStatus']]??'';
             $value['item_list'] = isset($invoinfo['item_list']) &&$invoinfo['item_list']!='' ?json_decode($invoinfo['item_list'],true):"";
             $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
-
         }
 
         //结算invlist这个接口当用payNo筛选的时候,返回列表里需要加一项统计筛选后列表的inv_subtotal_amount、total字段的和
@@ -1807,7 +1814,6 @@ class Payment extends Base
     	 return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
     }
 
-
     public function hpinvReturn(){
 		$param =$this->request->only(["hpNo"=>"","reason"=>""],"post","trim");
 		$valide=Validate::rule([
@@ -1942,7 +1948,6 @@ class Payment extends Base
 			Db::rollback();
 			return error_show(1005,$e->getMessage());
 		}
-
     }
 
      public function hpinvReturnInfo(){

+ 29 - 0
app/admin/listener/ComonQrd.php

@@ -15,6 +15,7 @@ class ComonQrd
     {
 		if($event['type']=="pay")$this->payComon($event);
 		if($event['type']=="inv")$this->invComon($event);
+		if($event['type']=="rinv")$this->returnInv($event);
 		if($event['type']=="check")$this->checkPay($event);
     }
     
@@ -22,6 +23,7 @@ class ComonQrd
     	$payinfo = Pay::where("payNo",$data['payNo'])->findOrEmpty();
     	if($payinfo->isEmpty()) return;
     	if($payinfo->is_comon!=1)return;
+    	if(!in_array($payinfo->status,[1,2]))return;
     	$qrdNo = PayInfo::alias("a")->leftJoin("ComonOrder b","a.cgdNo=b.cgdNo")->where(["payNo"=>$data['payNo'],"is_del"=>0,"a.status"=>1])->column("orderCode");
     	$qrdinfo = QrdInfo::where([["sequenceNo","in",$qrdNo],["wpay_fee",">",0]])->select();
     	if($qrdinfo->isEmpty())return;
@@ -79,6 +81,7 @@ class ComonQrd
     	$payinfo = Pay::where('payNo',$invpay['payNo'])->findOrEmpty();
     	if($payinfo->isEmpty()) return;
     	if($payinfo->is_comon!=1)return;
+    	if(!in_array($payinfo->status,[1,2]))return;
     	$ticket =InvoiceTicket::where(["invNo"=>$data['invNo'],"type"=>0])->json(['item'])->findOrEmpty();
     	if($ticket->isEmpty())return;
     	$pay_fee=0;
@@ -154,6 +157,9 @@ class ComonQrd
     			    'change_field'   =>'' ,
     		    ];
     		    InvoiceInfo::create($info);
+    		    $invpay->hpNo = $payinvoice['hpNo'];
+    		    $invpay->status =1;
+    		    $invpay->save();
     }
      protected function checkPay($data){
     	$payinfo = Pay::where('payNo',$data['payNo'])->findOrEmpty();
@@ -182,4 +188,27 @@ class ComonQrd
 		        }
     		}
     }
+    
+    public function returnInv($data){
+            $invinfo =InvoicePool::where(['invNo'=>$data['invNo'],"status"=>[5,6,7,8,9]])->findOrEmpty();
+        	if($invinfo->isEmpty())return;
+        	if($invinfo->is_comon!=1 )return;
+        	$invpay =InvoicePay::where(['invNo'=>$data['invNo']])->findOrEmpty();
+        	if($invpay->isEmpty())return;
+        	if($invpay->status!=1 )return;
+        	$payinfo = Pay::where('payNo',$invpay['payNo'])->findOrEmpty();
+        	if($payinfo->isEmpty()) return;
+        	if($payinfo->is_comon!=1)return;
+        	$payinvoice = PayInvoice::where(["hpNo"=>$invpay->hpNo,"status"=>4])->findOrEmpty();
+        	if($payinvoice->isEmpty())return;
+        	$payinvoice->status=10;
+        	$payinvoice->save();
+        	 $payinfo->winv_fee = $payinfo->winv_fee+$payinvoice->inv_fee;
+        	 $payinfo->ainv_fee = $payinfo->ainv_fee-$payinvoice->inv_fee;
+        	 $payinfo->inv_status = ($payinfo->winv_fee==0 &&$payinfo->inv_fee==0)?3:($payinfo->ainv_fee==0?2:1);
+        	 $this->CheckComonOrder($payinfo);
+        	  $payinfo->save();
+        	  $invpay->status =2;
+        	  $invpay->save();
+    }
 }