From b8a10fc982af8e454e94e6352e6f3881c6a65772 Mon Sep 17 00:00:00 2001
From: chengye <chengye@gonn.com.cn>
Date: Tue, 14 Jul 2020 23:34:04 +0800
Subject: [PATCH] =?UTF-8?q?=E7=BC=B4=E8=B4=B9=E5=8D=95=E4=B8=8E=E8=B4=A6?=
 =?UTF-8?q?=E5=8D=95=E5=85=B3=E7=B3=BB=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4?=
 =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 application/em/controller/Payment.php | 32 +++++++++++++--------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/application/em/controller/Payment.php b/application/em/controller/Payment.php
index 3c98160..49393ee 100755
--- a/application/em/controller/Payment.php
+++ b/application/em/controller/Payment.php
@@ -159,26 +159,26 @@ class Payment extends Base
         foreach ($invs as $inv){
             //未生成缴费或已挂起
             $amount += $inv->payment_balance;
-            if($inv->payment_amount >= $inv->payment_balance){
-                //是否已挂起
-                $paymentField = EmPaymentInvoice::field('payment_id')
-                                                ->where('invoice_id','=',$inv->invoice_id)
-                                                ->order('create_time desc')->find();
-                if($paymentField){
-                    //找到关联的缴费单
-                    $payment = EmPayment::where('payment_id','=',$paymentField->payment_id)->find();
-
-                     //如果缴费单并未缴费
-                    if($payment->amount == 0){
-                        $message = '账单号: '.$inv->invoice_id.' 已经挂起,无法生成缴费单';
-                        return json(['status'=>0,'message'=>$message]);
-                    } else {
-                        $idsArr[] = $inv->invoice_id;
-                    }
+            //是否已挂起
+            $epiModel = EmPaymentInvoice::field('payment_id')
+                                            ->where('invoice_id','=',$inv->invoice_id)
+                                            ->order('create_time desc')->find();
+            if($epiModel){
+                //找到关联的缴费单
+                $payment = EmPayment::where('payment_id','=',$epiModel->payment_id)->find();
+
+                if(!$payment) throw new Exception('单据:'.$epiModel->payment_id.'出现异常,单据与账单关系存在,但缴费单不存在!');
+                 //如果缴费单并未缴费
+                if($payment->amount == 0){
+                    $message = '账单号: '.$inv->invoice_id.' 已经挂起,无法生成缴费单';
+                    return json(['status'=>0,'message'=>$message]);
                 } else {
                     $idsArr[] = $inv->invoice_id;
                 }
+            } else {
+                $idsArr[] = $inv->invoice_id;
             }
+
         }
         $ids = $idsArr;
 
-- 
2.17.1