rabin 3 päivää sitten
vanhempi
commit
09f6c490f3
2 muutettua tiedostoa jossa 44 lisäystä ja 18 poistoa
  1. 11 7
      src/dai/seller/app/Api/Task.php
  2. 33 11
      src/dai/seller/app/Lib/Channel.php

+ 11 - 7
src/dai/seller/app/Api/Task.php

@@ -14,13 +14,17 @@ class Task
             $cur = time();
             foreach ($seller as $v) {
                 if ($v['chaoshi'] > 0) {
-                    $time = $cur + $v['chaoshi']*60;
+                    $time = $cur - $v['chaoshi']*60;
+                    $where = [];
+                    $where['seller_id'] = $v['id'];
                     $where['status'] = ['<=', 2];
-                    $where['cdate'] = ['<=', $time];
-                    $order = Dever::db('seller/order')->load($where);
-                    Dever::db('seller/order')->update($where, ['status' => 11]);
-                    foreach ($order as $v1) {
-                        Dever::load(\Seller\Lib\Order::class)->notify($v1, '失败');
+                    $where['cdate'] = ['<', $time];
+                    $order = Dever::db('seller/order')->select($where);
+                    if ($order) {
+                        Dever::db('seller/order')->update($where, ['status' => 11]);
+                        foreach ($order as $v1) {
+                            Dever::load(\Seller\Lib\Order::class)->notify($v1, '失败');
+                        }
                     }
                 }
             }
@@ -256,4 +260,4 @@ class Task
         }
         return 'ok';
     }
-}
+}

+ 33 - 11
src/dai/seller/app/Lib/Channel.php

@@ -47,8 +47,8 @@ class Channel
         // 优先级排序
         usort($channels, fn($a, $b) => $a['sort'] <=> $b['sort']);
 
-        // 取当前优先级
-        $candidate = $this->filterByPriority($channels);
+        // 取当前可用优先级
+        $candidate = $this->filterByPriorityWithLimit($channels);
         if (!$candidate) return false;
 
         // Least-Used 调度
@@ -146,20 +146,42 @@ class Channel
      *   同优先级过滤
      * ===============================
      */
-    private function filterByPriority($channels)
+    private function filterByPriorityWithLimit($channels)
     {
-        $priority = $channels[0]['sort'];
-        $res = [];
+        if (!$channels) {
+            return [];
+        }
 
-        foreach ($channels as $c) {
-            if ($c['sort'] == $priority) {
-                $res[] = $c;
-            } else {
-                break;
+        $groups = [];
+        foreach ($channels as $channel) {
+            $groups[$channel['sort']][] = $channel;
+        }
+        ksort($groups);
+
+        $redis = Redis::connect();
+        $now = time();
+
+        foreach ($groups as $priority => $list) {
+            $available = [];
+            foreach ($list as $c) {
+                $limit = (float)($c['limit_sec'] ?? 0);
+                if ($limit <= 0) {
+                    $available[] = $c;
+                    continue;
+                }
+                $lastUsed = (int)$redis->get("channel_last_used:{$c['id']}");
+                if (!$lastUsed || ($now - $lastUsed) >= $limit) {
+                    $available[] = $c;
+                }
+            }
+            if ($available) {
+                return $available;
             }
         }
 
-        return $res;
+        // 没有可用渠道时,降级使用最高优先级(保持与旧逻辑一致)
+        $firstGroup = reset($groups);
+        return $firstGroup ? array_values($firstGroup) : [];
     }