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,"购买方发票信息未找到"); } $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 =[]; $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']}待开票金额不足"); } $ascc=[ "assocNo"=>makeNo("AS"), "apply_id"=>$this->uid, "apply_name"=>$this->uname, "type"=>1, "orderCode"=>$value['sequenceNo'], "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") ]; $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; $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find(); $report->setField("invNo",$invNo); } $associn = Db::name("assoc")->insertAll($temp); if($associn==0){ Db::rollback(); return error_show(1005,"确认单申请开票失败"); } $inv=[ "invNo"=>$invNo, "inv_value"=>$invfee, "inv_out"=> $companyNo, "inv_in"=>$khNo, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "inv_type"=>$invtype,//发票类型 专用 普通 电子专用 电子普通 "open_type"=>0, //开票类型 金税开票 金税线下 纯线下 "is_ticket"=>$company['out_ticket'], //是否支持金税开票 "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退票 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,"发票金额不足"); } } $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){ $temp=[]; $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") ]; // foreach ($invArr as $value){ // $invpool=[ // "invNo"=>$invinfo['invNo'], // "in_type"=>$open_type, // "inv_code"=>$value['inv_code'], // "inv_number"=>$value['inv_number'], // "inv_total"=>$value['inv_total'], // "inv_subtotal"=>$value['inv_subtotal'], // "open_date"=>$value['open_date'], // "status"=>1, // "addtime"=>date("Y-m-d H:i:s"), // "updatetime"=>date("Y-m-d H:i:s") // ]; // $temp[]=$invpool; // } // $in = Db::name("invoice_ticket")->insertAll($temp); $in = Db::name("invoice_ticket")->insert($invpool); if($in==false){ Db::rollback(); return error_show(1004,"发票信息添加失败"); } } 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(); $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(); $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(); $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 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")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where ([["a.invNo","=",$invNo],["a.is_del","=",0]])->findOrEmpty(); if(empty($poolinfo)){ return error_show(1004,"为找到开票信息"); } $company =Db::name("company_info")->where(["companyNo"=>$poolinfo['inv_out']])->find(); $kehu =Db::name("customer_info")->where(["companyNo"=>$poolinfo['inv_in']])->find(); $poolinfo['companyName'] = $company['company_name']??""; $poolinfo['customerName'] = $kehu['companyName']??""; 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("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_in,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,a.*")->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } }