Explorar o código

Merge branch 'zhongqi-itemUpdate' of git.huaml.com:zhh/huahuibao into zhongqi-itemUpdate

shizhongqi hai 4 meses
pai
achega
02f9c10fb4

+ 5 - 1
app-ghs/controllers/ClearController.php

@@ -76,6 +76,10 @@ class ClearController extends BaseController
         if ($ghs->shopId != $this->shopId) {
             util::fail('不是你的账单哦');
         }
+
+        $staff = $this->shopAdmin;
+        $staffName = $staff->name ?? '';
+
         if ($clear->status == ClearClass::STATUS_HAS_PAY) {
             util::fail('账单已完成');
         }
@@ -83,7 +87,7 @@ class ClearController extends BaseController
             util::fail('账单已取消');
         }
         $clear->status = ClearClass::STATUS_EXPIRE;
-        $clear->remark = "商家手动取消 ".date("Y-m-d H:i:s");
+        $clear->remark = "商家手动取消 " . date("Y-m-d H:i:s") . ' 操作人:' . $staffName;
         $clear->save();
 
         $ghsShop = $this->shop;

+ 9 - 3
app-ghs/controllers/CustomController.php

@@ -231,7 +231,7 @@ class CustomController extends BaseController
             }
             //泉城花卉批发,只有指定人才能结账
             if (in_array($this->shopId, [447])) {
-                if (!in_array($this->adminId, [1398,2448,2457,2499,82260])) {
+                if (!in_array($this->adminId, [1398, 2448, 2457, 2499, 82260])) {
                     util::fail('不能充值销账,请联系小娟');
                 }
             }
@@ -828,7 +828,7 @@ class CustomController extends BaseController
         if (getenv('YII_ENV') == 'production') {
             //源花汇,只有指定的人,才能看累计消费和挂账金额,有多处要同步修改 manage_custom_data
             $hideMainId = 10536;
-            $hideAdminIds = [18505, 15187, 11961, 11648, 11644, 11641, 11976,22534, 4];
+            $hideAdminIds = [18505, 15187, 11961, 11648, 11644, 11641, 11976, 22534, 4];
         } else {
             $hideMainId = 0;
             $hideAdminIds = [0];
@@ -884,7 +884,7 @@ class CustomController extends BaseController
         if (getenv('YII_ENV') == 'production') {
             //源花汇,只有指定的人,才能看累计消费和挂账金额,有多处要同步修改 manage_custom_data
             $hideMainId = 10536;
-            $hideAdminIds = [18505, 15187, 11961, 11648, 11644, 11641, 11976,22534, 4];
+            $hideAdminIds = [18505, 15187, 11961, 11648, 11644, 11641, 11976, 22534, 4];
         } else {
             $hideMainId = 0;
             $hideAdminIds = [0];
@@ -1121,6 +1121,12 @@ class CustomController extends BaseController
                     util::fail('请闵总修改');
                 }
             }
+            //惠雅6号线
+            if ($this->mainId == 2128) {
+                if ($this->adminId == 3407) {
+                    util::fail('无法修改');
+                }
+            }
         }
 
         $get = Yii::$app->request->get();

+ 1 - 1
app-ghs/controllers/ProductController.php

@@ -808,7 +808,7 @@ class ProductController extends BaseController
                 }
                 $hjPrice = $product['hjPrice'] ?? 0;
                 if (!isset($productInfo->mainId) || $productInfo->mainId != $this->mainId) {
-                    util::fail('无法访问');
+                    util::fail('无法访问..');
                 }
                 if ($hjPrice > $price) {
                     util::fail($productName . ' 批发价要大于会员价');

+ 7 - 6
app-ghs/controllers/TestController.php

@@ -466,7 +466,8 @@ class TestController extends BaseController
             //['name' => '永城花语鲜花批发', 'merchantNo' => '82250605992008U', 'wx' => [866677786, 866678419], 'zfb' => '2088380428301720'],
             //['name' => '昆明木鱼花草堂', 'merchantNo' => '8227310599200ZU', 'wx' => [874780341, 874779360], 'zfb' => '2088480009915486'],
             //['name' => '永城花鲜谷鲜花批发', 'merchantNo' => '82250605992008V', 'wx' => [874955479, 874955569], 'zfb' => '2088480025639193'],
-            ['name' => '任丘蓝色雨鲜花批发', 'merchantNo' => '82214305992007M', 'wx' => [875610544, 875611929], 'zfb' => '2088480065124374'],
+            //['name' => '任丘蓝色雨鲜花批发', 'merchantNo' => '82214305992007M', 'wx' => [875610544, 875611929], 'zfb' => '2088480065124374'],
+            ['name' => '云南熙朵花卉', 'merchantNo' => '82273105992010C', 'wx' => [876755672, 876755475], 'zfb' => '2088480109605151'],
             //['name' => '藏花林', 'merchantNo' => '8227310599200ZC', 'wx' => [868558224, 868558410], 'zfb' => '2088380587657250'],
             //['name' => '昆明藏花林花卉', 'merchantNo' => '8227310599200ZN', 'wx' => [869670880, 869668881], 'zfb' => '2088380691198135'],
             //['name' => '昆明藏花林鲜花', 'merchantNo' => '8227310599200ZJ', 'wx' => [869361939, 869362520], 'zfb' => '2088380669365761'],
@@ -806,7 +807,7 @@ class TestController extends BaseController
 
     public function actionClearQuery()
     {
-        $shopId = 77125;
+        $shopId = 10649;
         $shop = ShopClass::getById($shopId, true);
         if (empty($shop)) {
             util::stop('没有找到门店20');
@@ -822,7 +823,7 @@ class TestController extends BaseController
             'lklCertificatePath' => $lklCertificatePath,
         ];
         $laResource = new Lakala($params);
-        $orderSn = 'CL29263855';
+        $orderSn = 'CL29336665';
         $queryParams = [
             'orderSn' => $orderSn,
             //'tradeNo' => '66222923861204',
@@ -1003,13 +1004,13 @@ class TestController extends BaseController
             'lklCertificatePath' => $lklCertificatePath,
         ];
         $laResource = new Lakala($params);
-        $orderSn = 'CG30510277';
-        $tradeNo = '66223788481731';
+        $orderSn = 'CG30574681';
+        $tradeNo = '66223936904050';
         $queryParams = [
             'orderSn' => $orderSn,
             'tradeNo' => $tradeNo,
         ];
-        $response = $laResource->query($queryParams, 0);
+        $response = $laResource->query($queryParams, 1);
         echo "<pre>";
         print_r($response);
         util::stop();

+ 8 - 3
app-hd/controllers/GhsController.php

@@ -466,12 +466,17 @@ class GhsController extends BaseController
             util::fail('已有批发商了');
         }
 
-        // 找出附近批发店,之后自动给建立关系,然后补充二个店之间的距离
-        GhsClass::buildNearbyGhsRelations($this->shop['id'], $this->shop->pfShopId, $toLat, $toLnt);
-
         $shop = $this->shop;
         $mobile = $shop->mobile;
         $name = $shop->merchantName ?? '';
+        $city = $shop->city ?? '';
+        $address = $shop->address ?? '';
+
+        noticeUtil::push("有新花店上来 {$this->shopId} {$toLat} {$toLnt} {$locationType} {$city}{$address}", '15280215347');
+
+        // 找出附近批发店,之后自动给建立关系,然后补充二个店之间的距离
+        GhsClass::buildNearbyGhsRelations($this->shop['id'], $this->shop->pfShopId, $toLat, $toLnt);
+
         noticeUtil::push("花店 {$name} {$mobile} 新注册,已推荐批发店", '15280215347');
 
         util::complete();

+ 1 - 1
app-hd/controllers/ProductController.php

@@ -616,7 +616,7 @@ class ProductController extends BaseController
                 }
                 $hjPrice = $product['hjPrice'] ?? 0;
                 if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
-                    util::fail('无法访问');
+                    util::fail('无法访问。。');
                 }
                 if ($hjPrice > $price) {
                     util::fail($productName . ' 批发价要大于会员价');

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

@@ -64,8 +64,9 @@ class PurchaseController extends BaseController
         if (empty($info)) {
             util::fail('没有找到采购单');
         }
-        if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
-            util::fail('无法访问');
+        if (!isset($info->mainId) || $info->mainId != $this->mainId) {
+            //重要,这个不能限制,因为开单分享给客户付款的,要显示支付宝二维码,限制了会不显示!!!!!! shish 20260326
+            //util::fail('无法访问!');
         }
         if (getenv('YII_ENV') == 'production') {
             $url = "https://mall.huahb.cn/#/admin/cg/alipay?orderSn={$orderSn}";
@@ -88,7 +89,7 @@ class PurchaseController extends BaseController
             util::fail('没有找到采购单');
         }
         if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
-            util::fail('无法访问');
+            util::fail('无法访问!!');
         }
         PurchaseClass::confirmTake($info);
         util::complete('确认成功');
@@ -103,7 +104,7 @@ class PurchaseController extends BaseController
             util::fail('没有找到采购单');
         }
         if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
-            util::fail('无法访问');
+            util::fail('无法访问。。。');
         }
         $orderSn = $info['orderSn'] ?? '';
         $ghsId = $info['ghsId'] ?? 0;

+ 1 - 1
biz-ghs/order/classes/OrderClass.php

@@ -493,7 +493,7 @@ class OrderClass extends BaseClass
         if (empty($cgInfo)) {
             util::fail('没有找到采购信息');
         }
-        $notice = isset($params['notice']) ? $params['notice'] : true; // 兼容处理,实现控制是否发发货通知
+        $notice = $params['notice'] ?? true; // 兼容处理,实现控制是否发发货通知
         PurchaseClass::orderFh($cgInfo, $params, $allowRepeat, $notice);
     }
 

+ 1 - 1
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -1278,7 +1278,7 @@ class PurchaseOrderClass extends BaseClass
             util::fail('订单不存在');
         }
         if (isset($orderData['shopId']) == false || $orderData['shopId'] != $shopId) {
-            util::fail('无法访问');
+            util::fail('无法访问,编号669');
         }
         $orderInfo = PurchaseOrderItemClass::getOrderItemDetail($orderSn);
         if ($orderInfo) {

+ 1 - 1
biz-hd/cg/classes/CgRefundClass.php

@@ -441,7 +441,7 @@ class CgRefundClass extends BaseClass
     public static function valid($refund, $mainId)
     {
         if (isset($refund->mainId) == false || $refund->mainId != $mainId) {
-            util::fail('无法访问');
+            util::fail('无法访问,编号5');
         }
         return true;
     }

+ 4 - 4
biz-hd/purchase/classes/PurchaseClass.php

@@ -142,20 +142,20 @@ class PurchaseClass extends BaseClass
     //订单发货子方法 ssh 20231119
     public static function orderFh($cg, $params, $allowRepeat = false, $notice = false)
     {
-        if ($notice == true) {
+        if ($notice) {
             $noticeText = json_encode(['id' => $cg->id]);
             $noticeKey = "ghsKdNoticeHd";
             Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
         }
         if ($cg->status == 3) {
-            if ($allowRepeat == false) {
+            if (!$allowRepeat) {
                 util::fail('订单已发货');
             } else {
                 return true;
             }
         }
         $fhType = $params['fhType'] ?? 0;
-        if (is_numeric($fhType) == false) {
+        if (!is_numeric($fhType)) {
             util::fail('请选择发货类型');
         }
         if ($fhType == 1) {
@@ -1422,7 +1422,7 @@ class PurchaseClass extends BaseClass
     public static function valid($cg, $shopId)
     {
         if (isset($cg->shopId) == false || $cg->shopId != $shopId) {
-            util::fail('无法访问');
+            util::fail('无法访问,编号1255');
         }
     }
 

+ 1 - 1
biz-hd/px/classes/PxClassClass.php

@@ -83,7 +83,7 @@ class PxClassClass extends BaseClass
         if ($info['sjId'] == $sjId) {
             return true;
         }
-        util::fail('无法访问');
+        util::fail('无法访问,编号766');
     }
 
     //添加培训班 ssh 2021.3.18

+ 1 - 1
biz-mall/px/classes/PxClassClass.php

@@ -57,7 +57,7 @@ class PxClassClass extends BaseClass
         if ($info['sjId'] == $sjId) {
             return true;
         }
-        util::fail('无法访问');
+        util::fail('无法访问,编号563');
     }
 
     //添加培训班 ssh 2021.3.18

+ 88 - 28
biz/ghs/classes/GhsClass.php

@@ -333,61 +333,95 @@ class GhsClass extends BaseClass
     public static function buildNearbyGhsRelations($shopId, $pfShopId, $toLat, $toLnt)
     {
         if (empty($toLat) || empty($toLnt)) {
-            util::fail('门店未定位');
+            noticeUtil::push("批发关系建立失败:目标门店坐标为空,shopId={$shopId}");
+            return false;
+        }
+        if (!self::isValidAmapCoordinate($toLat, $toLnt)) {
+            noticeUtil::push("批发关系建立失败:目标门店坐标非法,shopId={$shopId},lat={$toLat},lng={$toLnt}");
+            return false;
         }
 
         // 获取除虚拟外的所有批发店
-        $nearbyShops = ShopClass::getAllByCondition(['ptStyle'=>2, 'live'=>1, 'actTime>=' => strtotime('yesterday')], null, 'id, merchantName, lat, long');
+        $nearbyShops = ShopClass::getAllByCondition(['ptStyle' => 2, 'live' => 1, 'actTime>=' => strtotime('yesterday')], null, 'id, merchantName, lat, long');
         if (empty($nearbyShops)) {
-            return;
+            return false;
         }
 
-        $origins = [];
-        $validNearbyShops = [];
+        //要排除的批发店
+        $exclude = [64112, 62304, 42385, 56611, 38143, 15373, 42946, 15375, 15734, 15736, 15738, 15740, 24132, 29044, 29161, 30902, 44724, 48608, 48642, 82971, 38231, 1105, 3, 154, 208, 23580, 24713, 8249, 16070, 83690, 86726, 1596, 2167];
+        foreach ($nearbyShops as $key => $nearbyShop) {
+            if (in_array($nearbyShop['id'], $exclude)) {
+                unset($nearbyShops[$key]);
+            }
+        }
+
+        $nearbyShopOriginPairs = [];
         foreach ($nearbyShops as $nearbyShop) {
             if ($nearbyShop['id'] == $pfShopId) {
                 continue;
             }
-            if ($nearbyShop['lat'] && $nearbyShop['long']) {
-                $origins[] = [
-                    'lat' => $nearbyShop['lat'],
-                    'lng' => $nearbyShop['long'],
+            if (!empty($nearbyShop['lat']) && !empty($nearbyShop['long']) && self::isValidAmapCoordinate($nearbyShop['lat'], $nearbyShop['long'])) {
+                $nearbyShopOriginPairs[] = [
+                    'shop' => $nearbyShop,
+                    'origin' => [
+                        'lat' => $nearbyShop['lat'],
+                        'lng' => $nearbyShop['long'],
+                    ],
                 ];
-                $validNearbyShops[] = $nearbyShop;
             } else {
                 // 发送钉钉通知
-                noticeUtil::push('批发商:' . $nearbyShop['merchantName'] . '(' . $nearbyShop['id'] . ')未设置经纬度');
+                noticeUtil::push('批发商:' . $nearbyShop['merchantName'] . '(' . $nearbyShop['id'] . ')经纬度无效,lat=' . ($nearbyShop['lat'] ?? '') . ',lng=' . ($nearbyShop['long'] ?? ''));
             }
         }
 
-        if (empty($origins)) {
-            return;
+        if (empty($nearbyShopOriginPairs)) {
+            return false;
         }
 
         // 高德批量测距接口最多支持 100 个起点,需分批处理
-        $chunkOrigins = array_chunk($origins, 100);
-        $allDistances = [];
+        $chunkPairs = array_chunk($nearbyShopOriginPairs, 100);
+        $distanceShopPairs = [];
+
+        foreach ($chunkPairs as $chunk) {
+            $chunkOrigins = array_column($chunk, 'origin');
+            $distances = \common\components\mapUtil::calculateBatchDistance($chunkOrigins, $toLnt, $toLat);
 
-        foreach ($chunkOrigins as $chunk) {
-            $distances = \common\components\mapUtil::calculateBatchDistance($chunk, $toLnt, $toLat);
-            $allDistances = array_merge($allDistances, $distances);
+            if (empty($distances)) {
+                noticeUtil::push("批发关系建立失败:高德批量测距返回空结果,shopId={$shopId}");
+                continue;
+            }
+
+            foreach ($chunk as $index => $pair) {
+                if (!isset($distances[$index]) || !is_numeric($distances[$index])) {
+                    continue;
+                }
+                $distanceShopPairs[] = [
+                    'distance' => (float)$distances[$index],
+                    'shop' => $pair['shop'],
+                ];
+            }
         }
 
-        // 建立关系前要先执照距离从小到大排序
-        // 注意:array_multisort($allDistances, SORT_ASC, $validNearbyShops) 能保证 $allDistances 与 $validNearbyShops 保持索引同步,
-        // 即排序后 $validNearbyShops[$i] 就是排序后第 $i 小距离的门店信息,$allDistances[$i] 为其对应距离。
-        array_multisort($allDistances, SORT_ASC, $validNearbyShops);
+        if (empty($distanceShopPairs)) {
+            noticeUtil::push("批发关系建立失败:没有可用距离数据,shopId={$shopId}");
+            return false;
+        }
+
+        // 建立关系前按距离从小到大排序
+        usort($distanceShopPairs, function ($a, $b) {
+            return $a['distance'] <=> $b['distance'];
+        });
 
         // 取前6个
-        $allDistances = array_slice($allDistances, 0, 6);
-        $validNearbyShops = array_slice($validNearbyShops, 0, 6);
+        $distanceShopPairs = array_slice($distanceShopPairs, 0, 6);
 
         // 建立关系并保存距离
-        foreach ($validNearbyShops as $index => $nearbyShop) {
+        foreach ($distanceShopPairs as $pair) {
+            $nearbyShop = $pair['shop'];
             $ghsShopId = $nearbyShop['id'];
-            $distance = $allDistances[$index] ?? 0;
-            // 距离大于60公里不建立关系
-            if ($distance > 60*1000) {
+            $distance = $pair['distance'] ?? 0;
+            // 距离大于39公里不建立关系
+            if ($distance > 39 * 1000) {
                 continue;
             }
 
@@ -395,8 +429,34 @@ class GhsClass extends BaseClass
             $ghs = self::build($ghsShopId, $shopId);
             if (!empty($ghs) && $distance > 0) {
                 $ghsId = $ghs['id'];
+                $ghsName = $ghs['name'] ?? '';
+                noticeUtil::push("建立了一个关系:ghsId:" . $ghsId . ' name:' . $ghsName);
                 self::updateById($ghsId, ['distance' => $distance]);
             }
         }
+        return true;
+    }
+
+    /**
+     * 高德坐标有效性校验(仅保留中国大陆范围坐标)
+     * @param mixed $lat
+     * @param mixed $lng
+     * @return bool
+     */
+    private static function isValidAmapCoordinate($lat, $lng)
+    {
+        if (!is_numeric($lat) || !is_numeric($lng)) {
+            return false;
+        }
+        $lat = (float)$lat;
+        $lng = (float)$lng;
+
+        if ($lng < 72.004 || $lng > 137.8347) {
+            return false;
+        }
+        if ($lat < 0.8293 || $lat > 55.8271) {
+            return false;
+        }
+        return true;
     }
 }

+ 2 - 1
common/components/mapUtil.php

@@ -75,13 +75,14 @@ class mapUtil
         $curl = new curl\Curl();
         $result = $curl->get($url);
         $result = \yii\helpers\Json::decode($result);
-
         $distances = [];
         if (!empty($result['status']) && $result['status'] == 1 && !empty($result['results'])) {
             foreach ($result['results'] as $index => $res) {
                 // 返回的结果顺序与传入的 origins 顺序一致
                 $distances[$index] = $res['distance'] ?? 0; 
             }
+        }else{
+            noticeUtil::push("高德批量测距接口返回失败:".json_encode($result)." url:".$url);
         }
         
         return $distances;

+ 65 - 54
console/controllers/GhsOrderController.php

@@ -5,87 +5,98 @@ namespace console\controllers;
 use biz\shop\classes\ShopClass;
 use bizGhs\order\classes\OrderClass;
 use common\components\noticeUtil;
-use common\components\util;
 use Yii;
 use yii\console\Controller;
 
 class GhsOrderController extends Controller
 {
 
-    public function actionBcId()
-    {
-        ini_set('memory_limit', '2045M');
-        set_time_limit(0);
-
-        $list = OrderClass::getAllByCondition(['mainId' => 0], null, '*', null, true);
-        if (!empty($list)) {
-            foreach ($list as $order) {
-                $shopId = $order->shopId ?? 0;
-                $shop = ShopClass::getById($shopId, true);
-                $mainId = $shop->mainId ?? 0;
-                if (!empty($mainId)) {
-                    $order->mainId = $mainId;
-                    $order->save();
-                }
-            }
-        }
-    }
-
     // 脚本一:每天 03:20 执行,处理付款时间 7~10 天前订单
-    public function actionAutoSetOrderToFinish()
+    public function actionAutoFinish()
     {
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
 
-        $minPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
-        $maxPayTime = date('Y-m-d H:i:s', strtotime('-7 day'));
+        $minPayTime = date('Y-m-d H:i:s', strtotime('-12 day'));
+        $maxPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
         $extraCondition = [
+            'payStatus' => 1,
             'status' => ['in', [2, 3]],
             'payTime' => ['between', [$minPayTime, $maxPayTime]],
         ];
-        $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
-        $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
-        if (empty($orders)) {
-            util::stop('没有数据需要处理');
-        }
-        foreach ($orders as $order) {
-            $connection = Yii::$app->db;
-            $transaction = $connection->beginTransaction();
-            try {
-                OrderClass::confirmReach($order, $params);
-                $transaction->commit();
-            } catch (\Exception $e) {
-                $transaction->rollBack();
-                $orderId = $order->id ?? 0;
-                noticeUtil::push("批发订单自动完结失败 orderId={$orderId}, message={$e->getMessage()}", '15280215347');
+
+        $ghsShops = ShopClass::getAllByCondition(['ptStyle' => 2, 'live' => 1], null, 'mainId');
+        if (!empty($ghsShops)) {
+            $mainIds = array_unique(array_filter(array_column($ghsShops, 'mainId')));
+            if (!empty($mainIds)) {
+                $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
+                foreach ($mainIds as $mainId) {
+                    $condition = array_merge(['mainId' => $mainId], $extraCondition);
+                    $query = OrderClass::getActiveRecord()->conditionQuery($condition)->orderBy('id asc');
+                    foreach ($query->batch(1000) as $orders) {
+                        if (empty($orders)) {
+                            continue;
+                        }
+                        foreach ($orders as $order) {
+                            $connection = Yii::$app->db;
+                            $transaction = $connection->beginTransaction();
+                            try {
+                                OrderClass::confirmReach($order, $params);
+                                $transaction->commit();
+//                                $payTime = $order->payTime ?? 0;
+//                                echo $order->id . " " . $payTime . " ok \n";
+                            } catch (\Exception $e) {
+                                $transaction->rollBack();
+                                $orderId = $order->id ?? 0;
+                                noticeUtil::push("订单自动完结失败 orderId={$orderId}, message={$e->getMessage()}", '15280215347');
+                            }
+                        }
+                    }
+                }
             }
         }
+
         Yii::info('批发订单自动完结脚本成功执行');
     }
 
     // 脚本二:历史补偿,处理付款超过 10 天未完结订单
-    public function actionSetOldOrderToFinish()
+    public function actionAutoFinishHistory()
     {
         $maxPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
         $extraCondition = [
+            'payStatus' => 1,
             'status' => ['in', [2, 3]],
             'payTime<' => $maxPayTime,
         ];
-        $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
-        $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
-        if (empty($orders)) {
-            util::stop('没有数据需要处理');
-        }
-        foreach ($orders as $order) {
-            $connection = Yii::$app->db;
-            $transaction = $connection->beginTransaction();
-            try {
-                OrderClass::confirmReach($order, $params);
-                $transaction->commit();
-            } catch (\Exception $e) {
-                $transaction->rollBack();
-                $orderId = $order->id ?? 0;
-                noticeUtil::push("批发订单自动完结失败 orderId={$orderId}, message={$e->getMessage()}", '15280215347');
+
+        $ghsShops = ShopClass::getAllByCondition(['ptStyle' => 2, 'live' => 1], null, 'mainId');
+        if (!empty($ghsShops)) {
+            $mainIds = array_unique(array_filter(array_column($ghsShops, 'mainId')));
+            if (!empty($mainIds)) {
+                $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
+                foreach ($mainIds as $mainId) {
+                    $condition = array_merge(['mainId' => $mainId], $extraCondition);
+                    $query = OrderClass::getActiveRecord()->conditionQuery($condition)->orderBy('id asc');
+                    foreach ($query->batch(1000) as $orders) {
+                        if (empty($orders)) {
+                            continue;
+                        }
+                        foreach ($orders as $order) {
+                            $connection = Yii::$app->db;
+                            $transaction = $connection->beginTransaction();
+                            try {
+                                OrderClass::confirmReach($order, $params);
+                                $transaction->commit();
+                                $payTime = $order->payTime ?? 0;
+                                echo $order->id . " " . $payTime . " ok \n";
+                            } catch (\Exception $e) {
+                                $transaction->rollBack();
+                                $orderId = $order->id ?? 0;
+                                noticeUtil::push("自动完结失败,orderId={$orderId}, message={$e->getMessage()}", '15280215347');
+                            }
+                        }
+                    }
+                }
             }
         }
         Yii::info('批发订单自动完结历史补偿脚本成功执行');