|
@@ -31,6 +31,7 @@ class ProcuremenSupplierScore
|
|
|
self::$schemaReady = true;
|
|
self::$schemaReady = true;
|
|
|
self::ensureDefaultRule();
|
|
self::ensureDefaultRule();
|
|
|
self::ensureScoreWeightColumns();
|
|
self::ensureScoreWeightColumns();
|
|
|
|
|
+ self::ensureIntegerColumns();
|
|
|
|
|
|
|
|
return;
|
|
return;
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
@@ -54,6 +55,7 @@ class ProcuremenSupplierScore
|
|
|
self::$schemaReady = true;
|
|
self::$schemaReady = true;
|
|
|
self::ensureDefaultRule();
|
|
self::ensureDefaultRule();
|
|
|
self::ensureScoreWeightColumns();
|
|
self::ensureScoreWeightColumns();
|
|
|
|
|
+ self::ensureIntegerColumns();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 历史表补质量/价格百分比字段 */
|
|
/** 历史表补质量/价格百分比字段 */
|
|
@@ -63,13 +65,13 @@ class ProcuremenSupplierScore
|
|
|
$cols = Db::query("SHOW COLUMNS FROM `" . self::TABLE_SCORE . "` LIKE 'quality_weight'");
|
|
$cols = Db::query("SHOW COLUMNS FROM `" . self::TABLE_SCORE . "` LIKE 'quality_weight'");
|
|
|
if (!is_array($cols) || $cols === []) {
|
|
if (!is_array($cols) || $cols === []) {
|
|
|
Db::execute(
|
|
Db::execute(
|
|
|
- "ALTER TABLE `" . self::TABLE_SCORE . "` ADD COLUMN `quality_weight` decimal(5,2) NOT NULL DEFAULT 50.00 COMMENT '质量百分比' AFTER `quality_score`"
|
|
|
|
|
|
|
+ "ALTER TABLE `" . self::TABLE_SCORE . "` ADD COLUMN `quality_weight` int unsigned NOT NULL DEFAULT 50 COMMENT '质量百分比' AFTER `quality_score`"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
$cols2 = Db::query("SHOW COLUMNS FROM `" . self::TABLE_SCORE . "` LIKE 'price_weight'");
|
|
$cols2 = Db::query("SHOW COLUMNS FROM `" . self::TABLE_SCORE . "` LIKE 'price_weight'");
|
|
|
if (!is_array($cols2) || $cols2 === []) {
|
|
if (!is_array($cols2) || $cols2 === []) {
|
|
|
Db::execute(
|
|
Db::execute(
|
|
|
- "ALTER TABLE `" . self::TABLE_SCORE . "` ADD COLUMN `price_weight` decimal(5,2) NOT NULL DEFAULT 50.00 COMMENT '价格百分比' AFTER `price_sum`"
|
|
|
|
|
|
|
+ "ALTER TABLE `" . self::TABLE_SCORE . "` ADD COLUMN `price_weight` int unsigned NOT NULL DEFAULT 50 COMMENT '价格百分比' AFTER `price_sum`"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
@@ -77,6 +79,40 @@ class ProcuremenSupplierScore
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 将权重/质量分/单价合计等字段改为整数(去掉 .00) */
|
|
|
|
|
+ protected static function ensureIntegerColumns(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $defs = [
|
|
|
|
|
+ self::TABLE_RULE => [
|
|
|
|
|
+ 'quality_weight' => "int unsigned NOT NULL DEFAULT 50 COMMENT '上年度质量评分权重(%)'",
|
|
|
|
|
+ 'price_weight' => "int unsigned NOT NULL DEFAULT 50 COMMENT '单价评分权重(%)'",
|
|
|
|
|
+ ],
|
|
|
|
|
+ self::TABLE_SCORE => [
|
|
|
|
|
+ 'quality_score' => "int NOT NULL DEFAULT 0 COMMENT '上年度质量评分'",
|
|
|
|
|
+ 'quality_weight' => "int unsigned NOT NULL DEFAULT 50 COMMENT '质量百分比'",
|
|
|
|
|
+ 'price_sum' => "int NOT NULL DEFAULT 0 COMMENT '本单工序单价合计'",
|
|
|
|
|
+ 'price_weight' => "int unsigned NOT NULL DEFAULT 50 COMMENT '价格百分比'",
|
|
|
|
|
+ ],
|
|
|
|
|
+ ];
|
|
|
|
|
+ foreach ($defs as $table => $cols) {
|
|
|
|
|
+ foreach ($cols as $col => $def) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $info = Db::query("SHOW COLUMNS FROM `{$table}` LIKE '{$col}'");
|
|
|
|
|
+ if (!is_array($info) || $info === []) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $type = strtolower((string)($info[0]['Type'] ?? $info[0]['type'] ?? ''));
|
|
|
|
|
+ if (preg_match('/^(tiny|small|medium|big)?int\b/', $type)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::execute("ALTER TABLE `{$table}` MODIFY COLUMN `{$col}` {$def}");
|
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
|
|
+ Log::write("supplier score int column {$table}.{$col}: " . $e->getMessage(), 'error');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
protected static function ensureDefaultRule(): void
|
|
protected static function ensureDefaultRule(): void
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
@@ -111,7 +147,7 @@ class ProcuremenSupplierScore
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @return array{id:int,name:string,quality_weight:float,price_weight:float}
|
|
|
|
|
|
|
+ * @return array{id:int,name:string,quality_weight:int,price_weight:int}
|
|
|
*/
|
|
*/
|
|
|
public static function getDefaultRule(): array
|
|
public static function getDefaultRule(): array
|
|
|
{
|
|
{
|
|
@@ -129,8 +165,8 @@ class ProcuremenSupplierScore
|
|
|
return [
|
|
return [
|
|
|
'id' => (int)($row['id'] ?? 0),
|
|
'id' => (int)($row['id'] ?? 0),
|
|
|
'name' => trim((string)($row['name'] ?? '')),
|
|
'name' => trim((string)($row['name'] ?? '')),
|
|
|
- 'quality_weight' => (float)($row['quality_weight'] ?? 50),
|
|
|
|
|
- 'price_weight' => (float)($row['price_weight'] ?? 50),
|
|
|
|
|
|
|
+ 'quality_weight' => (int)($row['quality_weight'] ?? 50),
|
|
|
|
|
+ 'price_weight' => (int)($row['price_weight'] ?? 50),
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
@@ -139,8 +175,8 @@ class ProcuremenSupplierScore
|
|
|
return [
|
|
return [
|
|
|
'id' => 0,
|
|
'id' => 0,
|
|
|
'name' => '内置默认',
|
|
'name' => '内置默认',
|
|
|
- 'quality_weight' => 50.0,
|
|
|
|
|
- 'price_weight' => 50.0,
|
|
|
|
|
|
|
+ 'quality_weight' => 50,
|
|
|
|
|
+ 'price_weight' => 50,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -183,7 +219,7 @@ class ProcuremenSupplierScore
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
$raw = $r['score'] ?? null;
|
|
$raw = $r['score'] ?? null;
|
|
|
- $score = ($raw === null || $raw === '') ? 0.0 : (float)$raw;
|
|
|
|
|
|
|
+ $score = ($raw === null || $raw === '') ? 0 : (int)round((float)$raw);
|
|
|
$map[$cn] = [
|
|
$map[$cn] = [
|
|
|
'id' => (int)($r['id'] ?? 0),
|
|
'id' => (int)($r['id'] ?? 0),
|
|
|
'score' => $score,
|
|
'score' => $score,
|
|
@@ -255,12 +291,12 @@ class ProcuremenSupplierScore
|
|
|
$priceSum += (float)$am;
|
|
$priceSum += (float)$am;
|
|
|
$hasPrice = true;
|
|
$hasPrice = true;
|
|
|
}
|
|
}
|
|
|
- $quality = (float)($custMap[$cn]['score'] ?? 0);
|
|
|
|
|
|
|
+ $quality = (int)round((float)($custMap[$cn]['score'] ?? 0));
|
|
|
$items[$cn] = [
|
|
$items[$cn] = [
|
|
|
'company_name' => $cn,
|
|
'company_name' => $cn,
|
|
|
'customer_id' => (int)($custMap[$cn]['id'] ?? 0),
|
|
'customer_id' => (int)($custMap[$cn]['id'] ?? 0),
|
|
|
'quality_score' => $quality,
|
|
'quality_score' => $quality,
|
|
|
- 'price_sum' => $hasPrice ? $priceSum : 0.0,
|
|
|
|
|
|
|
+ 'price_sum' => $hasPrice ? (int)round($priceSum) : 0,
|
|
|
'has_price' => $hasPrice,
|
|
'has_price' => $hasPrice,
|
|
|
'price_score' => 0.0,
|
|
'price_score' => 0.0,
|
|
|
'score' => 0.0,
|
|
'score' => 0.0,
|
|
@@ -373,10 +409,10 @@ class ProcuremenSupplierScore
|
|
|
'ccydh' => $ccydh,
|
|
'ccydh' => $ccydh,
|
|
|
'score' => (float)($it['score'] ?? 0),
|
|
'score' => (float)($it['score'] ?? 0),
|
|
|
'rank_no' => (int)($it['rank_no'] ?? 0),
|
|
'rank_no' => (int)($it['rank_no'] ?? 0),
|
|
|
- 'quality_score' => (float)($it['quality_score'] ?? 0),
|
|
|
|
|
- 'quality_weight' => (float)($rule['quality_weight'] ?? 50),
|
|
|
|
|
- 'price_sum' => (float)($it['price_sum'] ?? 0),
|
|
|
|
|
- 'price_weight' => (float)($rule['price_weight'] ?? 50),
|
|
|
|
|
|
|
+ 'quality_score' => (int)round((float)($it['quality_score'] ?? 0)),
|
|
|
|
|
+ 'quality_weight' => (int)($rule['quality_weight'] ?? 50),
|
|
|
|
|
+ 'price_sum' => (int)round((float)($it['price_sum'] ?? 0)),
|
|
|
|
|
+ 'price_weight' => (int)($rule['price_weight'] ?? 50),
|
|
|
'price_score' => (float)($it['price_score'] ?? 0),
|
|
'price_score' => (float)($it['price_score'] ?? 0),
|
|
|
'rule_id' => (int)($rule['id'] ?? 0),
|
|
'rule_id' => (int)($rule['id'] ?? 0),
|
|
|
'createtime' => $now,
|
|
'createtime' => $now,
|