shish 5 anni fa
parent
commit
cbcb6b3e42

+ 3 - 5
app-hd/controllers/PurchaseClearController.php

@@ -30,11 +30,9 @@ class PurchaseClearController extends BaseController
                 }
             }
         }
-        $ids = $post['id'];
-        $data['sjId'] = $this->sjId;
-        $data['shopId'] = $this->shopId;
-        $data['id'] = $ids;
-        $respond = PurchaseClearClass::addClear($data);
+        $post['sjId'] = $this->sjId;
+        $post['shopId'] = $this->shopId;
+        $respond = PurchaseClearClass::addOrder($post);
         util::success($respond);
     }
 

+ 4 - 4
app-hd/controllers/PurchaseController.php

@@ -133,10 +133,10 @@ class PurchaseController extends BaseController
     //待结款明细 ssh 2021.1.26
     public function actionDebtList()
     {
-        $where = [
-            'merchantId' => $this->sjId,
-            'debt' => PurchaseClass::DEBT_YES
-        ];
+        $id = Yii::$app->request->get('id', 0);
+        $info = GhsClass::getGhsInfo($id);
+        GhsClass::valid($info, $this->sjId);
+        $where = ['ghsId' => $id];
         $respond = PurchaseService::getDebtList($where);
         util::success($respond);
     }

+ 19 - 7
biz-hd/purchase/classes/PurchaseClearClass.php

@@ -2,6 +2,7 @@
 
 namespace bizHd\purchase\classes;
 
+use biz\ghs\classes\GhsClass;
 use bizHd\base\classes\BaseClass;
 use common\components\orderSn;
 use common\components\util;
@@ -16,11 +17,11 @@ class PurchaseClearClass extends BaseClass
     const STATUS_HAS_PAY = 2;
     const STATUS_EXPIRE = 3;
 
-    public static function addClear($data)
+    public static function addOrder($data)
     {
         $orderSn = orderSn::getPurchaseClearSn();
-        $ids = $data['id'];
-        $arr = explode(',', $ids);
+        $purchaseIds = $data['purchaseIds'];
+        $arr = explode(',', $purchaseIds);
         if (empty($arr)) {
             util::fail('请选择采购单');
         }
@@ -38,10 +39,8 @@ class PurchaseClearClass extends BaseClass
         $data['actPrice'] = $totalPrice;
         $data['prePrice'] = $totalPrice;
         $data['orderSn'] = $orderSn;
-        $data['purchaseIds'] = $ids;
         $deadTime = time() + 120;
         $data['deadline'] = date("Y-m-d H:i:s", $deadTime);
-        unset($data['id']);
         return self::add($data);
     }
 
@@ -73,9 +72,20 @@ class PurchaseClearClass extends BaseClass
         }
         $order->status = self::STATUS_HAS_PAY;
         $order->save();
+
+        $clearId = $order->id;
         $orderSn = $order->orderSn;
-        $ids = $order->purchaseIds;
-        $arr = explode(',', $ids);
+        $purchaseIds = $order->purchaseIds;
+        $arr = explode(',', $purchaseIds);
+
+        //供货商欠款数变更
+        $ghsId = $order->ghsId;
+        $ghs = GhsClass::getById($ghsId, true);
+        $ghs->debtAmount = bcsub($ghs->debtAmount, $order->actPrice, 2);
+        $ghs->debtNum -= count($arr);
+        $ghs->save();
+
+
         if (empty($arr)) {
             $msg = "结算订单 orderSn:{$orderSn} 支付成功,回调处理,没有找到采购订单";
             util::fail($msg);
@@ -85,9 +95,11 @@ class PurchaseClearClass extends BaseClass
             $msg = "结算订单 orderSn:{$orderSn} 支付成功,回调处理,没有找到采购订单!";
             util::fail($msg);
         }
+        //采购单状态变化
         foreach ($list as $purchase) {
             $purchase->debt = 2;
             $purchase->payWay = $payWay;
+            $purchase->clearId = $clearId;
             $purchase->save();
         }
     }

+ 3 - 1
sql.sql

@@ -2279,4 +2279,6 @@ ALTER TABLE `xhGhs` DROP COLUMN `customId`;
 ALTER TABLE `xhGhsCustom` DROP COLUMN `ghsId`;
 ALTER TABLE xhPurchaseClear ADD `status` TINYINT NOT NULL DEFAULT 1 COMMENT '状态 1待付款 2已付款 3已取消,已失效' AFTER `changePrice`;
 ALTER TABLE xhPurchaseClear ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER `merchantId`;
-ALTER TABLE xhPurchaseClear CHANGE `merchantId` `sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家id'
+ALTER TABLE xhPurchaseClear CHANGE `merchantId` `sjId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家id';
+ALTER TABLE xhPurchaseClear ADD ghsId INT NOT NULL DEFAULT 0 COMMENT '供货商id' AFTER `orderSn`;
+ALTER TABLE `xhPurchase` ADD clearId INT NOT NULL DEFAULT 0 COMMENT '欠款结算id' AFTER `payWay`;