shish 4 luni în urmă
părinte
comite
d6c4ace9de

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

@@ -242,7 +242,7 @@ class PurchaseClass extends BaseClass
     public static function takeToPutIn($cg)
     {
         if ($cg->status != 3) {
-            util::fail('订单不是待收货状态哦');
+            util::fail('订单不是待收货状态哦,编号:cg' . $cg->id);
         }
         $saleId = $cg->saleId ?? 0;
         $order = OrderClass::getById($saleId, true);
@@ -1010,30 +1010,30 @@ class PurchaseClass extends BaseClass
 
         //如果有设置指定客户涨价百分之几,然后又设置了涨价的幅度。【这个功能主要用于客户不收他运费,门店不赚钱,收他运费客户不乐意,所以把运费加到花材里】,多处同步修改,关键词 rise_percent_rang
         if (isset($data['itemPrice'])) {
-            if(isset($data['orderReachDiscountPrice'])){
+            if (isset($data['orderReachDiscountPrice'])) {
                 $originActPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2);
-            }else{
+            } else {
                 $originActPrice = $actPrice;
             }
-            if($originActPrice >= $data['itemPrice']){
+            if ($originActPrice >= $data['itemPrice']) {
                 if (isset($ghs['risePercent']) && $ghs['risePercent'] > 0) {
                     if (isset($ghs['riseRange']) && $ghs['riseRange'] > 0) {
                         $risePercent = $ghs['risePercent'];
                         $riseRange = $ghs['riseRange'];
                         // 计算涨价金额:涨价后金额 * (涨价百分比 / (100 + 涨价百分比))
                         $riseAmount = bcmul($data['itemPrice'], bcdiv($risePercent, bcadd(100, $risePercent, 0), 4), 2);
-                        if($riseAmount>$riseRange){
+                        if ($riseAmount > $riseRange) {
                             //应该退回的金额
                             $backAmount = bcsub($riseAmount, $riseRange, 2);
                             $actPrice = bcsub($actPrice, $backAmount, 2);
-                            if(isset($data['orderReachDiscountPrice'])){
-                                if($data['orderReachDiscountPrice']<$backAmount){
+                            if (isset($data['orderReachDiscountPrice'])) {
+                                if ($data['orderReachDiscountPrice'] < $backAmount) {
                                     //前面整单满减的,就不减了,所以这里面加回来
                                     $actPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2);
                                     //改成减多加钱里面的
                                     $data['orderReachDiscountPrice'] = $backAmount;
                                 }
-                            }else{
+                            } else {
                                 $data['orderReachDiscountPrice'] = $backAmount;
                             }
                         }

+ 32 - 60
console/controllers/GhsOrderController.php

@@ -4,6 +4,7 @@ namespace console\controllers;
 
 use biz\shop\classes\ShopClass;
 use bizGhs\order\classes\OrderClass;
+use common\components\noticeUtil;
 use Yii;
 use yii\console\Controller;
 
@@ -38,81 +39,52 @@ class GhsOrderController extends Controller
         $minPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
         $maxPayTime = date('Y-m-d H:i:s', strtotime('-7 day'));
         $extraCondition = [
-            'payStatus' => 1,
             'status' => ['in', [2, 3]],
             'payTime' => ['between', [$minPayTime, $maxPayTime]],
         ];
-
-        $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);
-                    $orders = OrderClass::getAllByCondition($condition, 'id asc', '*', null, true);
-                    if (empty($orders)) {
-                        continue;
-                    }
-                    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;
-                            Yii::error(
-                                "批发订单自动完结失败 mainId={$mainId}, orderId={$orderId}, message={$e->getMessage()}",
-                                'ghsOrderAutoFinish'
-                            );
-                        }
-                    }
-                }
+        $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
+        $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
+        if (empty($orders)) {
+            continue;
+        }
+        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');
             }
         }
-
         Yii::info('批发订单自动完结脚本成功执行');
     }
 
     // 脚本二:历史补偿,处理付款超过 10 天未完结订单
     public function actionSetOldOrderToFinish()
     {
-        $maxPayTime = date('Y-m-d H:i:s', strtotime('-1 day'));
+        $maxPayTime = date('Y-m-d H:i:s', strtotime('-10 day'));
         $extraCondition = [
-            'payStatus' => 1,
             'status' => ['in', [2, 3]],
             'payTime<' => $maxPayTime,
         ];
-
-        $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);
-                    $orders = OrderClass::getAllByCondition($condition, 'id asc', '*', null, true);
-                    if (empty($orders)) {
-                        continue;
-                    }
-                    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;
-                            Yii::error(
-                                "批发订单自动完结失败 mainId={$mainId}, orderId={$orderId}, message={$e->getMessage()}",
-                                'ghsOrderAutoFinish'
-                            );
-                        }
-                    }
-                }
+        $params = ['staffId' => 0, 'staffName' => '系统', 'notice' => false]; // notice设置为 false,实现不发送发货通知
+        $orders = OrderClass::getAllByCondition($extraCondition, 'id asc', '*', null, true);
+        if (empty($orders)) {
+            continue;
+        }
+        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');
             }
         }
         Yii::info('批发订单自动完结历史补偿脚本成功执行');