Browse Source

自助结账

shish 2 năm trước cách đây
mục cha
commit
815ca055d1

+ 4 - 0
app-ghs/controllers/CustomController.php

@@ -27,10 +27,14 @@ class CustomController extends BaseController
     //供货商给客户充值和结账 ssh 20240309
     public function actionRecharge()
     {
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
         $staff = $this->shopAdmin;
         if (isset($staff->finance) == false || $staff->finance == 0) {
             util::fail('请让财务充值');
         }
+
         $get = Yii::$app->request->get();
         $amount = $get['amount'] ?? 0;
         $customId = $get['customId'] ?? 0;

+ 26 - 1
biz-ghs/order/classes/OrderClearClass.php

@@ -38,7 +38,32 @@ class OrderClearClass extends BaseClass
         if (floatval($customBalance) == 0) {
             return true;
         }
-        
+        $where = ['customId' => $customId, 'debt' => 1];
+        $orderList = OrderClass::getAllByCondition($where, 'id asc', '*', null, true);
+        if (empty($orderList)) {
+            return true;
+        }
+        $totalAmount = 0;
+        foreach ($orderList as $order) {
+            $remainDebtPrice = $order->remainDebtPrice ?? 0;
+            $totalAmount = bcadd($totalAmount, $remainDebtPrice, 2);
+            if ($totalAmount <= $customBalance) {
+
+            } else {
+                break;
+            }
+        }
+
+        $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
+        $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
+        if (!empty($list)) {
+            foreach ($list as $item) {
+                //只要新建账单,老账单就取消掉
+                $item->status = PurchaseClearClass::STATUS_EXPIRE;
+                $item->save();
+            }
+        }
+
     }
 
     //订单结算 ssh 2021.3.14