$invNo,"status"=>1,"type"=>"1"])->field("id,orderCode,cancel_fee")->select(); if(!$list->isEmpty()){ try{ $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']==1 &&$order[$v['orderCode']]['inv_status']==1 ? 0 : 1; } } (new QrdInfo())->saveAll($order); self::where(['id'=>$list->column('id')])->save(['status'=>2,'assoc_time'=>date('Y-m-d H:i:s')]); }catch (\Exception $exception){ throw new \Exception($exception->getMessage()); } } } 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']==1 &&$order[$v['orderCode']]['inv_status']==1 ? 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']==1 &&$order[$v['orderCode']]['inv_status']==1 ? 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(!empty($asscoinfo)){ foreach ($asscoinfo as $k=>$v){ if($v['type']==1){ $pool = InvoicePool::where('invNo',$v['viceCode'])->findOrEmpty(); $temp=['type'=>'结算销售单开票申请','username'=> $pool->apply_name,'orderCode'=>$v['viceCode'],'companyName'=>$pool->inv_company]; $data[]=$temp; } if($v['type']==2){ $pool = TradePool::with(['company'])->where('logNo',$v['viceCode'])->findOrEmpty(); $temp=['type'=>'结算销售单资金认领','username'=> $pool->apply_name,'orderCode'=>$v['viceCode'],'companyName'=>$pool->companyName]; $data[]=$temp; } } } } }