瀏覽代碼

结帐订单

shish 5 年之前
父節點
當前提交
d314d2d140

+ 8 - 1
app-ghs/controllers/OrderClearController.php

@@ -17,12 +17,19 @@ class OrderClearController extends BaseController
         if (empty($id)) {
             util::fail('请选择交易记录');
         }
+        //抹零之后的价格
+        $modifyPrice = Yii::$app->request->post('modifyPrice', 0.00);
+        if (is_numeric($modifyPrice) == false || $modifyPrice <= 0) {
+            util::fail('金额填错了哦');
+        }
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
+        $name = $this->shopAdmin['name'] ?? '';
         $data = [
             'customId' => $customId,
             'ghsShopAdminId' => $this->shopAdminId,
-            'ghsShopAdminName' => $this->shopAdmin['name'],
+            'ghsShopAdminName' => $name,
+            'modifyPrice' => $modifyPrice,
         ];
         try {
             OrderClearClass::clear($data, $id, $this->sjId, $this->shopId);

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

@@ -2,6 +2,7 @@
 
 namespace hd\controllers;
 
+use biz\ghs\classes\GhsClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
@@ -12,13 +13,16 @@ use common\components\util;
 class PurchaseClearController extends BaseController
 {
 
-    //生成结订单 ssh 2021.1.26
+    //生成结订单 ssh 2021.1.26
     public function actionCreateOrder()
     {
         $post = Yii::$app->request->post();
         $current = time();
-        //查找还有没待清算的订单
-        $list = PurchaseClearClass::getAllByCondition(['shopId' => $this->shopId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY], null, '*', null, true);
+        $ghsId = $post['ghsId'] ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        GhsClass::valid($ghs, $this->shopId);
+        //查找有没结帐订单还没有过期
+        $list = PurchaseClearClass::getAllByCondition(['ghsId' => $ghsId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY], null, '*', null, true);
         if (!empty($list)) {
             foreach ($list as $item) {
                 $deadline = $item->deadline;
@@ -27,7 +31,7 @@ class PurchaseClearController extends BaseController
                     $item->status = PurchaseClearClass::STATUS_EXPIRE;
                     $item->save();
                 } else {
-                    util::fail('您还有结算订单没有付款');
+                    util::fail('请勿频繁提交,2分钟后再操作');
                 }
             }
         }
@@ -38,7 +42,7 @@ class PurchaseClearController extends BaseController
         $shopAdmin = $this->shopAdmin;
         $shopAdminName = $shopAdmin['name'] ?? '';
         $post['customShopAdminName'] = $shopAdminName;
-        $respond = PurchaseClearClass::addOrder($post);
+        $respond = PurchaseClearClass::addOrder($post, $ghs);
         util::success($respond);
     }
 

+ 27 - 8
biz-ghs/order/classes/OrderClearClass.php

@@ -5,6 +5,7 @@ namespace bizGhs\order\classes;
 use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopClass;
 use bizGhs\custom\classes\CustomClass;
+use common\components\dict;
 use common\components\orderSn;
 use common\components\util;
 use bizGhs\base\classes\BaseClass;
@@ -19,7 +20,7 @@ class OrderClearClass extends BaseClass
     //订单结算 ssh 2021.3.14
     public static function clear($post, $idText, $sjId, $shopId)
     {
-        $customId = $post['customId'];
+        $customId = $post['customId'] ?? 0;
         $data = json_decode($idText, true);
         $ids = array_column($data, 'id');
         if (empty($ids)) {
@@ -30,6 +31,9 @@ class OrderClearClass extends BaseClass
             util::fail('请选择订单');
         }
         $amount = 0;
+
+        $modifyPrice = $post['modifyPrice'] ?? 0.00;
+
         $purchaseArr = [];
         foreach ($list as $key => $val) {
             if ($val['sjId'] != $sjId) {
@@ -56,6 +60,13 @@ class OrderClearClass extends BaseClass
         if (empty($custom)) {
             util::fail('没有找到客户');
         }
+
+        $ghsId = $custom->ghsId;
+        $ghs = GhsClass::getLockById($ghsId);
+        if (empty($ghs)) {
+            util::fail('没有找到供应商');
+        }
+
         $debtAmount = $custom->debtAmount ?? 0.00;
         if ($debtAmount < $amount) {
             util::fail('客户欠款金额有问题');
@@ -85,8 +96,13 @@ class OrderClearClass extends BaseClass
         $orderSn = orderSn::getPurchaseClearSn();
         $clearData = [
             'prePrice' => $amount,
-            'actPrice' => $amount,
-            'ghsId' => $custom->ghsId,
+            'actPrice' => $modifyPrice,
+            'realPrice' => $modifyPrice,
+            'ghsId' => $ghsId,
+            'ghsName' => $ghs['name'] ?? '',
+            'ghsMobile' => $ghs['mobile'] ?? '',
+            'ghsAvatar' => $ghs['avatar'] ?? '',
+            'ghsAddress' => $ghs['address'] ?? '',
             'ghsShopAdminId' => $post['ghsShopAdminId'],
             'ghsShopAdminName' => $post['ghsShopAdminName'],
             'sjId' => $sjId,
@@ -96,9 +112,17 @@ class OrderClearClass extends BaseClass
             'status' => 2,
             'type' => 2,
             'customId' => $customId,
+            'customName' => $custom['name'] ?? '',
+            'customAvatar' => $custom['avatar'] ?? '',
+            'customMobile' => $custom['mobile'] ?? '',
+            'customAddress' => $custom['address'] ?? '',
             'deadline' => date("Y-m-d H:i:s"),
             'purchaseIds' => $purchaseString,
         ];
+        if ($modifyPrice < $amount) {
+            $clearData['discountAmount'] = bcsub($amount, $modifyPrice, 2);
+            $clearData['discountType'] = dict::getDict('discountType', 'discount');
+        }
         $return = PurchaseClearClass::add($clearData);
         $clearId = $return['id'];
 
@@ -107,11 +131,6 @@ class OrderClearClass extends BaseClass
         // 采购单状态变更
         PurchaseClass::updateByIds($purchaseArr, ['debt' => 2, 'clearId' => $clearId]);
 
-        $ghsId = $custom->ghsId;
-        $ghs = GhsClass::getLockById($ghsId);
-        if (empty($ghs)) {
-            util::fail('没有找到供应商');
-        }
         $remainAmount = bcsub($ghs->debtAmount, $amount, 2);
         if ($remainAmount < 0) {
             util::fail('客户欠款金额有问题!');

+ 5 - 2
biz-ghs/order/services/OrderService.php

@@ -85,7 +85,10 @@ class OrderService extends BaseService
             'getType' => $getType,
         ];
         if (isset($data['modifyPrice']) && is_numeric($data['modifyPrice'])) {
-            //商家打折,修改金额
+            //抹零之后的金额
+            if (is_numeric($data['modifyPrice']) == false || $data['modifyPrice'] <= 0) {
+                util::fail('金额填错了哦');
+            }
             $purchaseData['modifyPrice'] = $data['modifyPrice'];
         }
         $purchase = PurchaseClass::addPurchase($purchaseData);
@@ -563,7 +566,7 @@ class OrderService extends BaseService
     }
 
     //退款订单
-    public static function refund($order,$productData)
+    public static function refund($order, $productData)
     {
 
     }

+ 25 - 3
biz-hd/purchase/classes/PurchaseClearClass.php

@@ -23,8 +23,15 @@ class PurchaseClearClass extends BaseClass
     const STATUS_HAS_PAY = 2;
     const STATUS_EXPIRE = 3;
 
-    public static function addOrder($data)
+    public static function addOrder($data, $ghs)
     {
+        $ghsId = $ghs->id;
+        $customId = $ghs->customId;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+
         $orderSn = orderSn::getPurchaseClearSn();
         $purchaseIds = $data['purchaseIds'];
         $arr = explode(',', $purchaseIds);
@@ -51,11 +58,26 @@ class PurchaseClearClass extends BaseClass
         }
         $saleString = implode(',', $saleArr);
         $data['saleIds'] = $saleString;
-        $data['actPrice'] = $totalPrice;
         $data['prePrice'] = $totalPrice;
+        $data['actPrice'] = $totalPrice;
+        $data['realPrice'] = $totalPrice;
         $data['orderSn'] = $orderSn;
         $deadTime = time() + 120;
         $data['deadline'] = date("Y-m-d H:i:s", $deadTime);
+        $arr = [
+            'ghsId' => $ghsId,
+            'ghsName' => $ghs['name'] ?? '',
+            'ghsMobile' => $ghs['mobile'] ?? '',
+            'ghsAvatar' => $ghs['avatar'] ?? '',
+            'ghsAddress' => $ghs['address'] ?? '',
+            'customId' => $customId,
+            'customName' => $custom['name'] ?? '',
+            'customAvatar' => $custom['avatar'] ?? '',
+            'customMobile' => $custom['mobile'] ?? '',
+            'customAddress' => $custom['address'] ?? '',
+            'deadline' => date("Y-m-d H:i:s"),
+        ];
+        $data = array_merge($data, $arr);
         return self::add($data);
     }
 
@@ -186,7 +208,7 @@ class PurchaseClearClass extends BaseClass
         }
         $currentMayPay = bcsub($customShop->mayPay, $order->actPrice, 2);
         $customShop->mayPay = $currentMayPay;
-        if($ghs->debtNum == 0){
+        if ($ghs->debtNum == 0) {
             $customShop->mayPayNum -= 1;
         }
         $customShop->save();