shish 1 gadu atpakaļ
vecāks
revīzija
a6685fca1b

+ 34 - 0
app-ghs/controllers/ExpressController.php

@@ -13,6 +13,40 @@ use Yii;
 class ExpressController extends BaseController
 {
 
+    public function actionCancelWayBill()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $fhWlNo = $order->fhWlNo ?? '';
+        if (empty($fhWlNo)) {
+            util::fail('没有找到物流单');
+        }
+
+        if (getenv('YII_ENV') == 'production') {
+            $bizId = $bizIdMap[$mainId] ?? 0;
+            if (empty($bizId)) {
+                util::fail('没有找到月结账号');
+            }
+            //暂时只支持顺丰
+            $deliveryId = 'SF';
+        } else {
+            $deliveryId = 'TEST';
+            $bizId = 'test_biz_id';
+        }
+        $params = [
+            'deliveryId' => $deliveryId,
+            'bizId' => $bizId,
+        ];
+        ExpressClass::cancel($params, $order);
+    }
+
     //新建运单 ssh
     public function actionCreateWayBill()
     {

+ 37 - 0
biz-ghs/express/classes/ExpressClass.php

@@ -17,6 +17,43 @@ class ExpressClass extends BaseClass
 
     public static $baseFile = '\bizGhs\express\models\DeliveryOrder';
 
+    public static function cancel($params, $order)
+    {
+        $cgId = $order->purchaseId;
+        $cg = PurchaseClass::getById($cgId, true);
+        if (empty($cg)) {
+            util::fail('订单信息缺失');
+        }
+
+        $merchant = WxOpenClass::getGhsWxInfo();
+        $ptStyle = dict::getDict('ptStyle', 'ghs');
+
+        $orderSn = $params['orderSn'];
+        $openId = $params['openId'];
+        $deliveryId = $params['deliveryId'];
+        $bizId = $params['bizId'];
+
+        $wayBillId = $order->fhWlNo ?? '';
+
+        $data = [
+            'openid' => $openId,
+            'deliveryId' => $deliveryId,
+            'waybill_id' => $wayBillId,
+            'order_id' => $orderSn
+        ];
+
+        $ret = expressUtil::cancelOrder($merchant, $data, $ptStyle);
+        if ($ret['errcode'] == 0) {
+            $order->fhWlStatus = 2;
+            $order->save();
+            $cg->fhWlStatus = 2;
+            $cg->save();
+            util::complete('取消成功');
+        } else {
+            util::fail('取消失败');
+        }
+    }
+
     //新增运单 ssh 20250703
     public static function addWayBill($params, $order)
     {