post['companyType'])&&$this->post['companyType']!=='' ? trim($this->post['companyType']):""; if ($companyType==''){ return error_show(1004,"参数 companyType 不能为空"); } if($companyType!="03"){ $buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):""; if($buy_id==''){ return error_show(1004,"参数 buy_id 不能为空"); } $buyinfo =Db::name("customer_invoice")->where(['id'=>$buy_id,"is_del"=>0])->find(); if($buyinfo==false){ return error_show(1004,"购买方发票信息未找到"); } }else{ $username= isset($this->post['username'])&&$this->post['username']!=='' ? trim($this->post['username']):"个人"; $userID=isset($this->post['userID'])&&$this->post['userID']!=='' ? trim($this->post['userID']):""; $buyinfo=[ "invoice_title"=>$username, "invoice_code"=>$userID, "invoice_addr"=>'', "invoice_mobile"=>'', "invoice_bank"=>'', "invoice_bankNo"=>'', ] ; } $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=='' ? trim($this->post['companyNo']):""; if($companyNo==''){ return error_show(1004,"参数 companyNo 不能为空"); } $company = Db::name("company_info")->where(["companyNo"=>$companyNo])->find(); if($company==false){ return error_show(1004,"销售方信息未找到"); } // $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=='' ? trim($this->post['khNo']):""; // if($khNo==''){ // return error_show(1004,"参数 khNo 不能为空"); // } // $customer = Db::name("customer_info")->where(["companyNo"=>$khNo])->find(); // if($customer==false){ // return error_show(1004,"客户信息未找到"); // } $invtype = isset($this->post['invtype'])&&$this->post['invtype']!=='' ? intval($this->post['invtype']):""; if($invtype==''){ return error_show(1004,"参数 invtype 不能为空"); } $email = isset($this->post['email'])&&$this->post['email']!=='' ? trim($this->post['email']):""; $remark = isset($this->post['remark'])&&$this->post['remark']!=='' ? trim($this->post['remark']):""; $orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr']) ? $this->post['orderArr']:[]; if(empty($orderArr)){ return error_show(1004,"参数 orderArr 不能为空"); } $temp =[]; $good=[]; $invNo=makeNo("INV"); $invfee=array_sum(array_column($orderArr,'inv_fee')); Db::startTrans(); try{ foreach ($orderArr as $value){ if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){ Db::rollback(); return error_show(1004,"参数 sequenceNo 不能为空"); } $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find(); if($qrd['status']==2){ Db::rollback(); return error_show(1004,"确认单{$value['sequenceNo']}不参与对账"); } if(!isset($value['inv_fee']) || $value['inv_fee']===''){ Db::rollback(); return error_show(1004,"参数 inv_fee 不能为空"); } if($qrd['winv_fee']<$value['inv_fee']){ Db::rollback(); return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足"); } $good_info = Db::name("good")->where(["spuCode"=>$qrd["goodNo"],"status"=>1])->findOrEmpty(); if(empty($good_info)){ Db::rollback(); return error_show(1004,"确认单{$value['sequenceNo']}商品未确认开票类目"); } $ascc=[ "assocNo"=>makeNo("AS"), "apply_id"=>$this->uid, "apply_name"=>$this->uname, "type"=>1, "orderCode"=>$value['sequenceNo'], "customerNo"=>$value['customerNo'], "viceCode"=>$invNo, "order_total"=>$qrd['totalPrice'], "vice_total"=>$invfee, "cancel_fee"=>$value['inv_fee'], "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $invoice_good=[ "invNo"=>$invNo, "orderCode"=>$value['sequenceNo'], "goodNo"=>$qrd['goodNo'], "goodName"=>$good_info['inv_good_name'], "catName"=>$good_info['inv_cat_name'], "catNo"=>$good_info['inv_cat_code'], "goodPrice"=>$value['inv_cat_code'], "unitName"=>$qrd['goodUnit'], "goodNum"=>$value['num'], "specInfo"=>'', "totalPrice"=>$value['inv_fee'], "tax"=>$good_info['inv_tax'], "is_discount"=>$good_info['is_discount'], "addTax"=>$good_info['addTax'], "inv_tag"=>$good_info['inv_tag'], "taxPrice"=>round($value['inv_fee']*$good_info['inv_tax'],2), "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $update = [ "inv_fee"=>$qrd['inv_fee']+$value['inv_fee'], "winv_fee"=>$qrd['winv_fee']-$value['inv_fee'], "inv_status"=>2, "status"=>1, "updatetime"=>date("Y-m-d H:i:s") ]; $up = Db::name("qrd_info")->where($qrd)->update($update); if($up==false){ Db::rollback(); return error_show(1005,"确认单{$value['sequenceNo']} 更新失败"); } $temp[]=$ascc; $good[]=$invoice_good; $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find(); if($report)$report->setField("invNo",$invNo); } $associn = Db::name("assoc")->insertAll($temp); if($associn==0){ Db::rollback(); return error_show(1005,"确认单申请开票失败"); } $goodin = Db::name("invoice_good")->insertAll($good); if($goodin==0){ Db::rollback(); return error_show(1005,"确认单申请开票失败"); } $inv=[ "invNo"=>$invNo, "inv_value"=>$invfee, "inv_out"=> $companyNo, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "inv_type"=>$invtype,//发票类型 专用 普通 电子专用 电子普通 "open_type"=>0, //开票类型 金税开票 金税线下 纯线下 "is_ticket"=>$company['out_ticket'], //是否支持金税开票 "company_type"=> $buyinfo['company_type'], //类型01 企业,02 机关事业单位,03 个人, 04 其他 "remark"=>$remark, //申请备注 "exam_remark"=>'', //审核备注 "ainv_fee"=>0,//已核销金额 "winv_fee"=>$invfee,//未核销金额 "status"=>0,// 待财务开票/待金税开票 待财务审核 待填写物流 开票完成 开票失败/开票驳回 财务驳回 "is_del"=>0, "email"=>$email, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $invin = Db::name("invoice_pool")->insert($inv); if($invin){ $invinfo=[ "buyer_title"=>$buyinfo['invoice_title'], "buyer_code"=>$buyinfo['invoice_code'], "buyer_addr"=>$buyinfo['invoice_addr'], "buyer_mobile"=>$buyinfo['invoice_mobile'], "buyer_bank"=>$buyinfo['invoice_bank'], "buyer_bankNo"=>$buyinfo['invoice_bankNo'], "seller_title"=>$company['company_name'], "seller_code"=>$company['company_license'], "seller_addr"=>$company['company_address'], "seller_mobile"=>$company['mobile'], "seller_bank"=>$company['bank_name'], "seller_bankNo"=>$company['bankNo'], "invNo"=>$invNo, "voider"=>$company['voider'], "payee"=>$company['payee'], "drawer"=>$company['drawer'], "reviewer"=>$company['reviewer'], "ownerPlace"=>$company['ownerPlace'], "addtime"=>date("Y-m-d H:i:s") ]; $poolinfo =Db::name("invoice_pool_info")->insert($invinfo); if($poolinfo){ Db::commit(); return app_show(0,"确认单发票申请成功",["invNo"=>$invNo]); } } Db::rollback(); return error_show(1004,"确认单发票申请失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } // 0 待财务开票/待金税开票 1待财务审核 2待填写物流 3开票完成 4开票失败/开票驳回 5财务驳回 6退票 7金税开票中 public function status(){ $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):""; if($invNo==""){ return error_show(1004,"参数 invNo 不能为空"); } $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find(); if($invinfo==false){ return error_show(1004,"发票申请数据未找到"); } $status= isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):""; if($status===''){ return error_show(1004,"参数 status 不能为空"); } //open_type 1 金税开票 2 金税线下开票 3 线下开票 $open_type = isset($this->post['open_type'])&&$this->post['open_type']!==''?intval($this->post['open_type']):""; $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):""; // $invArr=isset($this->post['invArr'])&&!empty($this->post['invArr'])?$this->post['invArr']:[]; $invCode =isset($this->post['invCode'])&&$this->post['invCode']!=''?trim($this->post['invCode']):""; $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']):""; $total_fee =isset($this->post['total_fee'])&&$this->post['total_fee']!=''?floor($this->post['total_fee']):""; $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floor($this->post['subtotal_fee']):""; if($status==1){ if($open_type==='')return error_show(1004,"参数 open_type 不能为空"); if($open_type!=1){ if($invCode==='') return error_show(1004,"参数 invCode 不能为空"); if($invNum==='') return error_show(1004,"参数 invNum 不能为空"); if($open_date==='') return error_show(1004,"参数 open_date 不能为空"); if($total_fee==='') return error_show(1004,"参数 tatal_fee 不能为空"); if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空"); if($total_fee!=$invinfo['inv_value'])return error_show(1004,"发票金额不足"); }else{ $status=7; } } $update=[ "status"=>$status, "exam_remark"=>$remark, "updatetime" => date("Y-m-d H:i:s") ]; $status==1 ? $update['open_type']=$open_type :""; Db::startTrans(); try{ $invup =Db::name("invoice_pool")->where($invinfo)->update($update); if($invup){ if($status==1&& $open_type!=1){ $invpool=[ "invNo"=>$invinfo['invNo'], "inv_type"=>$open_type, "inv_code"=>$invCode, "inv_number"=>$invNum, "inv_total"=>$total_fee, "inv_subtotal"=>$subtotal_fee, "open_date"=>$open_date, "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $in = Db::name("invoice_ticket")->insert($invpool); if($in==false){ Db::rollback(); return error_show(1004,"发票信息添加失败"); } } if($status==7 && $open_type==1){ $invpoolinfo =Db::name("invoice_pool_info")->where(["invNo"=>$invNo])->findOrEmpty(); if(empty($invpoolinfo)){ Db::rollback(); return error_show(1004,"开票信息未找到"); } $goodinfo =Db::name("invoice_good") ->where(["invNo"=>$invNo,"is_del"=>0]) ->field("0 as FPHXZ, catNo as SPBM, goodNo as ZXBM, is_discount as YHZCBS, inv_tag as LSLBS, addTax as ZZSTSGL, goodName as XMMC, unitName as DW, goodNum as SPSL, goodPrice as DJ, totalPrice as JE, 1 HSBZ, tax as SL, taxPrice as SE") ->select()->toJson(); if(empty($goodinfo)){ Db::rollback(); return error_show(1004,"开票商品信息未找到"); } $data=[ "invNo"=>$invNo, "KPLX"=>"0", "XHFSBH"=>$invpoolinfo['seller_code'], "XHFMC"=>$invpoolinfo['seller_title'], "XHFDZ"=>$invpoolinfo['seller_addr'], "XHFDH"=>$invpoolinfo['seller_mobile'], "XHFYH"=>$invpoolinfo['seller_bank'], "XHFZH"=>$invpoolinfo['seller_bankNo'], "GMFBM"=>"", "GMFSBH"=>$invpoolinfo['buyer_code'], "GMFMC"=>$invpoolinfo['buyer_title'], "GMFDZ"=>$invpoolinfo['buyer_addr'], "GMFDH"=>$invpoolinfo['buyer_mobile'], "GMFYH"=>$invpoolinfo['buyer_bank'], "GMFZH"=>$invpoolinfo['buyer_bankNo'], "GMFLX"=>$invinfo['company_type'], "GMFSJH"=>"", "GMFDZYX"=>$invinfo['email'], "KPR"=>$invpoolinfo['drawer'], "SKR"=>$invpoolinfo['payee'], "FHR"=>$invpoolinfo['reviewer'], "QDBZ"=>"", "JSHJ"=>$invinfo['inv_value'], "HJJE"=>"0", "HJSE"=>"0", "BZ"=>"", "DDMXXX"=>$goodinfo, "FPLXDM"=>invoiceType($invinfo['inv_type']), "DDQQPCH"=>"", "DDQQLSH"=>randomkeys(26).date("YmdHis"), "status"=>"0", "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $invoice=Db::name("invoice_interface")->insert($data); if($invoice==false){ Db::rollback(); return error_show(1003,"开票信息生成失败"); } Cache::push("invoiceList",$data["DDQQLSH"]); } if($status==4 ||$status==5 ){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->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){ Db::rollback(); return error_show(1003,"确认单信息未找到"); } if($qrdinfo['inv_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 ?0 : 1, "updatetime"=>date("Y-m-d H:i:s"), ]; $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1003,"确认单信息更新失败"); } $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]; $assocup =Db::name("assoc")->where($value)->update($assoc); if($assocup==false){ Db::rollback(); return error_show(1003,"确认单关联信息更新失败"); } $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find(); if($report)$report->rmField("invNo",$invinfo['invNo']); } } } Db::commit(); return app_show(0,"审核成功"); } Db::rollback(); return error_show(1004,"审核失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * 发票设置物流 */ public function SetPost(){ // @param invNo postCompany postCode postFee; $invNo =isset($this->post['invNo'])&&$this->post['invNo']!="" ? trim($this->post['invNo']):""; if($invNo==''){ return error_show(1004,"参数invNo不能为空"); } $invinfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find(); if($invinfo==false){ return error_show(1004,"发票申请信息未找到"); } $post_company =isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):""; if($post_company==''){ return error_show(1004,"参数 post_company 不能为空"); } $post_code =isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):""; if($post_code==''){ return error_show(1004,"参数 post_code 不能为空"); } $post_fee =isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? floor($this->post['post_fee']):"0"; Db::startTrans(); try{ $data=[ "post_company"=>$post_company, "post_code"=>$post_code, "post_fee"=>$post_fee, "status"=>3, "updatetime"=>date("Y-m-d H:i:s") ]; $up =Db::name("invoice_pool")->where($invinfo)->update($data); if($up){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->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){ Db::rollback(); return error_show(1003,"确认单信息未找到"); } if($qrdinfo['inv_fee']<$value['cancel_fee']){ Db::rollback(); return error_show(1003,"确认单信息开票金额不足"); } $update =[ "ainv_fee"=>$qrdinfo['ainv_fee']+$value['cancel_fee'], "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'], "inv_tme"=>date("Y-m-d H:i:s"), "inv_status"=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2, "updatetime"=>date("Y-m-d H:i:s"), ]; $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1003,"确认单信息更新失败"); } $assoc=["status"=>2,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")]; $assocup =Db::name("assoc")->where($value)->update($assoc); if($assocup==false){ Db::rollback(); return error_show(1003,"确认单关联信息更新失败"); } } } Db::commit(); return app_show(0,"更新成功"); } Db::rollback(); return error_show(1003,"发票申请信息更新失败"); }catch (Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * 发票废弃使用 */ public function Discard(){ } /**@param invNo return_reason remark 退票申请 * @return \think\response\Json|void */ public function ReturnAdd(){ $invNo = isset($this->post['invNo']) && $this->post['invNo']!=''? trim($this->post['invNo']) :''; if($invNo==""){ return error_show(1004,"参数 invNo 不能为空"); } $return_reason = isset($this->post['return_reason']) && $this->post['return_reason']!=''? trim($this->post['return_reason']) :''; $remark = isset($this->post['remark']) && $this->post['remark']!=''? trim($this->post['remark']) :''; if($return_reason==""){ return error_show(1004,"参数 return_reason 不能为空"); } if($remark==""){ return error_show(1004,"参数 remark 不能为空"); } $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find(); if($invinfo==false){ return error_show(1004,"发票申请数据未找到"); } if($invinfo['status']!=3){ return error_show(1004,"发票申请未完成"); } $qrd =Db::name("assoc")->where(["viceCode"=>$invNo,"status"=>2,"is_del"=>0])->column("orderCode"); if(empty($qrd)){ return error_show(1004,"未找到开票的销售单信息"); } $returnCode = makeNo("RIN"); $data=[ "returnCode"=>$returnCode, "invNo"=>$invNo, "return_reason"=>$return_reason, "remark"=>$remark, "status"=>0, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $inter = Db::name("invoice_return")->insert($data); if($inter){ foreach ($qrd as $value){ $report=ReportCode::where(["qrdNo"=>$value])->find(); if($report)$report->setField("returnInv",$returnCode); } return app_show(0,"退票申请新建成功",["returnCode"=>$returnCode]); }else{ return error_show(1005,"退票申请新建失败"); } } // 0 待审核 1 待退票 2 退票成功 3 驳回4 退票失败 public function ReturnStatus(){ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):""; if($returnCode==""){ return error_show(1005,"参数 returnCode 不能为空"); } $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):""; if ($status==""){ return error_show(1005,"参数 status 不能为空"); } $return_type = isset($this->post['return_type'])&&$this->post['return_type']!="" ? intval($this->post['return_type']):""; if ($return_type==""){ return error_show(1005,"参数 return_type 不能为空"); } $remark =isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):""; if($remark==""){ return error_show(1005,"参数 remark 不能为空"); } $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find(); if($return==false){ return error_show(1005,"退票申请信息未找到"); } $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find(); if($invinfo==false){ return error_show(1004,"发票申请数据未找到"); } if($invinfo['status']!=3){ return error_show(1004,"发票申请未完成"); } $qrd =Db::name("assoc")->where(["viceCode"=>$return['invNo'],"status"=>2,"is_del"=>0])->column("orderCode"); if(empty($qrd)){ return error_show(1004,"未找到开票的销售单信息"); } Db::startTrans(); try{ $update=["status"=>$status,"return_type"=>$return_type,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")]; $up =Db::name("invoice_return")->where($return)->update($update); if($up){ if($status==2){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0])->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){ Db::rollback(); return error_show(1003,"确认单信息未找到"); } if($qrdinfo['inv_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']==0 ? 1 : 2, "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1, "updatetime"=>date("Y-m-d H:i:s"), ]; $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1003,"确认单信息更新失败"); } $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]; $assocup =Db::name("assoc")->where($value)->update($assoc); if($assocup==false){ Db::rollback(); return error_show(1003,"确认单关联信息更新失败"); } } } } if($status==3 || $status==4){ foreach ($qrd as $value){ $report=ReportCode::where(["qrdNo"=>$value])->find(); if($report)$report->rmField("returnInv",$returnCode); } } Db::commit(); return app_show(0,"退票申请信息更新成功"); } Db::rollback(); return error_show(1005,"退票申请信息更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } //红冲票 public function returnRed(){ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):""; if($returnCode==""){ return error_show(1005,"参数 returnCode 不能为空"); } $redinv =isset($this->post['redinv'])&&$this->post['redinv']!="" ? trim($this->post['redinv']):""; if($redinv==""){ return error_show(1005,"参数 redinv 不能为空"); } $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find(); if($return==false){ return error_show(1005,"退票申请信息未找到"); } $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find(); if($invinfo==false){ return error_show(1005,"发票申请信息未找到"); } Db::startTrans(); try{ $update=["status"=>2,"red_inv"=>$redinv,"updatetime"=>date("Y-m-d H:i:s")]; $up =Db::name("invoice_return")->where($return)->update($update); if($up){ $invup = ["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]; $inv=Db::name("invoice_pool")->where($invinfo)->update($invup); if($inv){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0])->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){ Db::rollback(); return error_show(1003,"确认单信息未找到"); } if($qrdinfo['inv_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']==0 ? 1 : 2, "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1, "updatetime"=>date("Y-m-d H:i:s"), ]; $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1003,"确认单信息更新失败"); } $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")]; $assocup =Db::name("assoc")->where($value)->update($assoc); if($assocup==false){ Db::rollback(); return error_show(1003,"确认单关联信息更新失败"); } } } Db::commit(); return app_show(0,"退票申请信息更新成功"); } } Db::rollback(); return error_show(1005,"退票申请信息更新失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } //退票详情 public function returnInfo(){ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):""; if($returnCode==""){ return error_show(1005,"参数 returnCode 不能为空"); } $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find(); if($return==false){ return error_show(1005,"退票申请信息未找到"); } $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find(); $return['inv_out']= $invinfo['inv_out']??""; $return['inv_value']= $invinfo['inv_value']??""; $return['inv_apply_id']= $invinfo['apply_id']??""; $return['inv_apply_name']= $invinfo['apply_name']??""; $return['inv_type']= $invinfo['inv_type']??""; $return['open_type']= $invinfo['open_type']??""; $return['is_ticket']= $invinfo['is_ticket']??""; $return['email']= $invinfo['email']??""; $return['post_code']= $invinfo['post_code']??""; $return['post_company']= $invinfo['post_company']??""; $poolinfo = Db::name("invoice_pool_info")->where(["invNo"=>$return['invNo']])->find(); $return['buyer_title'] = $poolinfo['buyer_title']??''; $return['buyer_code'] = $poolinfo['buyer_code']??''; $return['buyer_addr'] = $poolinfo['buyer_addr']??''; $return['buyer_mobile'] = $poolinfo['buyer_mobile']??''; $return['buyer_bank'] = $poolinfo['buyer_bank']??''; $return['buyer_bankNo'] = $poolinfo['buyer_bankNo']??''; $return['seller_title'] = $poolinfo['seller_title']??''; $return['seller_addr'] = $poolinfo['seller_addr']??''; $return['seller_code'] = $poolinfo['seller_code']??''; $return['seller_mobile'] = $poolinfo['seller_mobile']??''; $return['seller_bank'] = $poolinfo['seller_bank']??''; $return['seller_bankNo'] = $poolinfo['seller_bankNo']??''; $return['voider'] = $poolinfo['voider']??''; $return['payee'] = $poolinfo['payee']??''; $return['drawer'] = $poolinfo['drawer']??''; $return['reviewer'] = $poolinfo['reviewer']??''; $return['ownerPlace'] = $poolinfo['ownerPlace']??''; $orderList =Db::name("invoice_good")->where(["invNo"=>$return['invNo'],"is_del"=>0])->select()->toArray(); $return['goodList']=$orderList; return app_show(0,"获取成功",$return); } /** *发票池列表 */ public function list(){ $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1; $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15; $condition=[["a.is_del","=",0]]; $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :""; $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :""; if($start!=""){ $condition[]=["a.addtime",">=",$start." 00:00:00"]; } if($end!=""){ $condition[]=["a.addtime","<=",$end." 23:59:59"]; } $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):""; if($status!==""){ $condition[]=["a.status","=",$status]; } $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):""; if($inv_type!==""){ $condition[]=["a.inv_type","=",$inv_type]; } $inv_out= isset($this->post['inv_out'])&&$this->post['inv_out']!=="" ? trim($this->post['inv_out']):""; if($inv_out!==""){ $condition[]=["a.inv_out","=",$inv_out]; } // $inv_in = isset($this->post['inv_in'])&&$this->post['inv_in']!=="" ? trim($this->post['inv_in']):""; // if($inv_in!==""){ // $condition[]=["a.inv_in","=",$inv_in]; // } $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):""; if($invNo!==""){ $condition[]=["a.invNo","like","%$invNo%"]; } $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):""; if($apply_id!==""){ $condition[]=["a.apply_id","=",$apply_id]; } $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :""; if($apply_name!==""){ $condition[]=["a.apply_name","like","%$apply_name%"]; } $count=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where ($condition)->count(); $total =ceil($count/$size); $page= $page>$total ? intval($total):$page; $list=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where($condition) ->page($page,$size)->select()->toArray(); foreach ($list as &$item) { $company =Db::name("company_info")->where(["companyNo"=>$item['inv_out']])->find(); // $kehu =Db::name("customer_info")->where(["companyNo"=>$item['inv_in']])->find(); $item['companyName'] = $company['company_name']??""; // $item['customerName'] = $kehu['companyName']??""; } return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } //获取发票详情 public function info(){ $invNo = isset($this->post['invNo'])&& $this->post['invNo']!='' ? trim($this->post['invNo']):""; if($invNo==''){ return error_show(1004,"参数 invNo 不能为空"); } $poolinfo =Db::name("invoice_pool")->where([["invNo","=",$invNo],["is_del","=",0]])->findOrEmpty(); if(empty($poolinfo)){ return error_show(1004,"为找到开票信息"); } $company =Db::name("company_info")->where(["companyNo"=>$poolinfo['inv_out']])->find(); $poolinfo['companyName'] = $company['company_name']??""; $pool = Db::name("invoice_pool_info")->where(["invNo"=>$invNo])->find(); $poolinfo['buyer_title'] = $pool['buyer_title']??''; $poolinfo['buyer_code'] = $pool['buyer_code']??''; $poolinfo['buyer_addr'] = $pool['buyer_addr']??''; $poolinfo['buyer_mobile'] = $pool['buyer_mobile']??''; $poolinfo['buyer_bank'] = $pool['buyer_bank']??''; $poolinfo['buyer_bankNo'] = $pool['buyer_bankNo']??''; $poolinfo['seller_title'] = $pool['seller_title']??''; $poolinfo['seller_addr'] = $pool['seller_addr']??''; $poolinfo['seller_code'] = $pool['seller_code']??''; $poolinfo['seller_mobile'] = $pool['seller_mobile']??''; $poolinfo['seller_bank'] = $pool['seller_bank']??''; $poolinfo['seller_bankNo'] = $pool['seller_bankNo']??''; $poolinfo['voider'] = $pool['voider']??''; $poolinfo['payee'] = $pool['payee']??''; $poolinfo['drawer'] = $pool['drawer']??''; $poolinfo['reviewer'] = $pool['reviewer']??''; $poolinfo['ownerPlace'] = $pool['ownerPlace']??''; $orderList =Db::name("invoice_good")->where(["invNo"=>$invNo,"is_del"=>0])->select()->toArray(); $poolinfop['goodList']=$orderList; return app_show(0,"获取成功",$poolinfo); } //退票列表 public function returnList(){ $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1; $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15; $condition=[["b.is_del","=",0]]; $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :""; $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :""; if($start!=""){ $condition[]=["a.addtime",">=",$start." 00:00:00"]; } if($end!=""){ $condition[]=["a.addtime","<=",$end." 23:59:59"]; } $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):""; if($inv_type!==""){ $condition[]=["b.inv_type","=",$inv_type]; } $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):""; if($apply_id!==""){ $condition[]=["a.apply_id","=",$apply_id]; } $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :""; if($apply_name!==""){ $condition[]=["a.apply_name","like","%$apply_name%"]; } $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):""; if($status!==""){ $condition[]=["a.status","=",$status]; } $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):""; if($invNo!==""){ $condition[]=["a.invNo","like","%$invNo%"]; } $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!=="" ? trim($this->post['returnCode']):""; if($returnCode!==""){ $condition[]=["a.returnCode","like","%$returnCode%"]; } $count=Db::name("invoice_return")->alias("a") ->leftJoin("invoice_pool b","a.invNo=b.invNo") ->leftJoin("invoice_pool_info c","a.invNo=c.invNo") ->where($condition)->count(); $total =ceil($count/$size); $page= $page>$total ? intval($total):$page; $list=Db::name("invoice_return")->alias("a") ->leftJoin("invoice_pool b","a.invNo=b.invNo") ->leftJoin("invoice_pool_info c","a.invNo=c.invNo") ->where($condition)->page($page,$size)->field("a.*,c.buyer_title,c.buyer_code,c.buyer_addr,c.buyer_mobile,c.buyer_bank, c.buyer_bankNo,c.seller_title,c.seller_code,c.seller_addr,c.seller_mobile,c.seller_bank,c.seller_bankNo,c.voider,c.payee, c.drawer,c.reviewer,c.ownerPlace,b.inv_value,b.inv_out,b.inv_type,b.open_type,is_ticket,b.email, b.winv_fee,b.ainv_fee,b.post_fee,b.post_company,b.post_code")->select()->toArray(); foreach ($list as &$value){ $company =Db::name("company_info")->where(["companyNo"=>$value['inv_out']])->find(); $value['companyName'] = $company['company_name']??""; } return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } }