m0_70156489 2 недель назад
Родитель
Сommit
2c826727a7
1 измененных файлов с 29 добавлено и 11 удалено
  1. 29 11
      application/common/library/ProcuremenSupplierScore.php

+ 29 - 11
application/common/library/ProcuremenSupplierScore.php

@@ -3181,6 +3181,7 @@ class ProcuremenSupplierScore
         $now = date('Y-m-d H:i:s');
         try {
             // 只删除当前批次的旧数据,保留同订单其他批次的分数(重新下发只清当前批)
+            // 已锁定的分数(score_locked=1)不删除
             $delQuery = Db::table(self::TABLE_SCORE)->where('ccydh', $ccydh);
             if ($orderBatchNo !== '') {
                 $delQuery->where('order_batch_no', $orderBatchNo);
@@ -3188,7 +3189,9 @@ class ProcuremenSupplierScore
                 // 无批次号时只删无批次记录(兜底)
                 $delQuery->where('order_batch_no', '');
             }
-            $delQuery->delete();
+            $delQuery->where(function ($q) {
+                $q->whereNull('score_locked')->whereOr('score_locked', 0);
+            })->delete();
             $rows = [];
             foreach ($calc as $it) {
                 $rows[] = [
@@ -3280,6 +3283,7 @@ class ProcuremenSupplierScore
             $leadEnabled = $lw > 0 ? 1 : 0;
             $leadSum = (int)round((float)($r['lead_days_sum'] ?? 0));
             $leadScore = (float)($r['lead_score'] ?? 0);
+            $scoreLocked = (int)($r['score_locked'] ?? 0);
             $out[$cn] = [
                 'company_name'         => $cn,
                 'customer_id'          => (int)($r['customer_id'] ?? 0),
@@ -3302,6 +3306,7 @@ class ProcuremenSupplierScore
                 'score_text'           => self::formatScore($r['score'] ?? 0),
                 'rank_text'            => ((int)($r['rank_no'] ?? 0)) > 0 ? (string)(int)($r['rank_no'] ?? 0) : '',
                 '_row_id'              => (int)($r['id'] ?? 0),
+                '_score_locked'        => $scoreLocked,
             ];
         }
 
@@ -3314,6 +3319,14 @@ class ProcuremenSupplierScore
             }
         }
         foreach ($out as $cn => &$it) {
+            // 已锁定的分数不重新计算,保持原样
+            if (!empty($it['_score_locked'])) {
+                $it['price_score_text'] = self::formatScore($it['price_score']);
+                $it['lead_score_text'] = !empty($it['lead_enabled']) ? self::formatScore($it['lead_score']) : '';
+                $it['score_text'] = self::formatScore($it['score']);
+                continue;
+            }
+            
             $qw = (int)($it['quality_weight'] ?? 50);
             $pw = (int)($it['price_weight'] ?? 50);
             $lw = (int)($it['lead_weight'] ?? 0);
@@ -3365,22 +3378,26 @@ class ProcuremenSupplierScore
             $out[$cn]['rank_no'] = $rank;
             $out[$cn]['rank_text'] = (string)$rank;
             $rowId = (int)($out[$cn]['_row_id'] ?? 0);
+            $isLocked = !empty($out[$cn]['_score_locked']);
             if ($rowId > 0) {
                 $upd = [];
                 if ($oldRank !== $rank) {
                     $upd['rank_no'] = $rank;
                 }
-                foreach ($rows as $r) {
-                    if (!is_array($r) || (int)($r['id'] ?? 0) !== $rowId) {
-                        continue;
-                    }
-                    if (abs((float)($r['price_score'] ?? 0) - (float)$out[$cn]['price_score']) > 0.001) {
-                        $upd['price_score'] = $out[$cn]['price_score'];
-                    }
-                    if (abs((float)($r['score'] ?? 0) - (float)$out[$cn]['score']) > 0.001) {
-                        $upd['score'] = $out[$cn]['score'];
+                // 已锁定的分数不更新回数据库
+                if (!$isLocked) {
+                    foreach ($rows as $r) {
+                        if (!is_array($r) || (int)($r['id'] ?? 0) !== $rowId) {
+                            continue;
+                        }
+                        if (abs((float)($r['price_score'] ?? 0) - (float)$out[$cn]['price_score']) > 0.001) {
+                            $upd['price_score'] = $out[$cn]['price_score'];
+                        }
+                        if (abs((float)($r['score'] ?? 0) - (float)$out[$cn]['score']) > 0.001) {
+                            $upd['score'] = $out[$cn]['score'];
+                        }
+                        break;
                     }
-                    break;
                 }
                 if ($upd !== []) {
                     try {
@@ -3390,6 +3407,7 @@ class ProcuremenSupplierScore
                 }
             }
             unset($out[$cn]['_row_id']);
+            unset($out[$cn]['_score_locked']);
         }
 
         return $out;