$invNo,"status"=>1,"type"=>"1"])->field("id,orderCode,cancel_fee")->select(); if(!$list->isEmpty()){ $order= QrdInfo::whereIn("sequenceNo",$list->column("orderCode")) ->column("id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status","sequenceNo"); foreach ($list as $k=>$v){ if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据"); if($v['cancel_fee']>0){ if($v['cancel_fee']>$order[$v['orderCode']]['inv_fee']){ throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票中金额{$order[$v['orderCode']]['inv_fee']}"); } $order[$v['orderCode']]['inv_fee']-=$v['cancel_fee']; $order[$v['orderCode']]['ainv_fee']+=$v['cancel_fee']; $order[$v['orderCode']]['invtime']=date("Y-m-d H:i:s"); $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['winv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 3 : 2; $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1; } } (new QrdInfo())->saveAll($order); self::where(["id"=>$list->column('id')])->save(['status'=>2,'assoc_time'=>date("Y-m-d H:i:s")]); } } public static function addOrder($invNo) { $list = self::where(["viceCode"=>$invNo,"status"=>1,"type"=>"1"])->field('id,orderCode,cancel_fee')->select(); if(!$list->isEmpty()){ $order= QrdInfo::whereIn('sequenceNo',$list->column('orderCode')) ->column('id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status','sequenceNo'); foreach ($list as $k=>$v){ if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据"); if($v['cancel_fee']>0){ if($v['cancel_fee']>$order[$v['orderCode']]['inv_fee']){ throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票中金额{$order[$v['orderCode']]['inv_fee']}"); } $order[$v['orderCode']]['inv_fee']-=$v['cancel_fee']; $order[$v['orderCode']]['winv_fee']+=$v['cancel_fee']; $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['ainv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 1 : 2; $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1; } } (new QrdInfo())->saveAll($order); self::where(['id'=>$list->column('id')])->save(['status'=>3]); InvoiceGood::where(['is_del' => 0,'invNo' => $invNo,'orderCode' => $list->column('orderCode')])->save(["goodNum"=>0,"updatetime"=>date("Y-m-d H:i:s")]); } } //开票流程已走完 取消发票 从已开票中直接扣除到未开票中 public static function addOrderWinv($invNo) { $list = self::where(['viceCode'=>$invNo,'status'=>2,'type'=>'1'])->field('id,orderCode,cancel_fee')->select(); if(!$list->isEmpty()){ $order= QrdInfo::whereIn('sequenceNo',$list->column('orderCode')) ->column('id,sequenceNo,winv_fee,inv_fee,ainv_fee,invtime,inv_status,status,pay_status','sequenceNo'); foreach ($list as $k=>$v){ if(!isset($order[$v['orderCode']])) throw new \Exception("订单{$v['orderCode']}未找到数据"); if($v['cancel_fee']>0){ if($v['cancel_fee']>$order[$v['orderCode']]['ainv_fee']){ throw new \Exception("订单{$v['orderCode']}开票金额{$v['cancel_fee']}超过实际开票金额{$order[$v['orderCode']]['ainv_fee']}"); } $order[$v['orderCode']]['ainv_fee']-=$v['cancel_fee']; $order[$v['orderCode']]['winv_fee']+=$v['cancel_fee']; $order[$v['orderCode']]['inv_status']= $order[$v['orderCode']]['ainv_fee']==0 &&$order[$v['orderCode']]['inv_fee']==0 ? 1 : 2; $order[$v['orderCode']]['status']= $order[$v['orderCode']]['pay_status']==0 &&$order[$v['orderCode']]['inv_status']==0 ? 0 : 1; } } (new QrdInfo())->saveAll($order); self::where(['id'=>$list->column('id')])->save(['status'=>3]); InvoiceGood::where(['is_del' => 0,'invNo' => $invNo,'orderCode' => $list->column('orderCode')])->save(['goodNum'=>0,'updatetime'=>date('Y-m-d H:i:s')]); } } public static function CheckQrd($orderCode,&$data) { $asscoinfo =self::where(['orderCode'=>$orderCode,'status'=>[1,2],'is_del'=>0])->column ('viceCode','type'); if(isset($asscoinfo[1])){ $pool = InvoicePool::where('invNo',$asscoinfo[1])->findOrEmpty(); $temp=['type'=>'结算销售单开票申请','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[1],'companyName'=>$pool->inv_company]; $data[]=$temp; } if(isset($asscoinfo[2])){ $pool = TradePool::with(["company"])->where('logNo',$asscoinfo[2])->findOrEmpty(); $temp=['type'=>'结算销售单资金认领','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[2],'companyName'=>$pool->companyName]; $data[]=$temp; } } }