Adjust user appraisal order flow

This commit is contained in:
wushumin
2026-05-21 17:56:35 +08:00
parent cfd21b462a
commit d0c4332468
8 changed files with 163 additions and 158 deletions

View File

@@ -103,6 +103,9 @@ class AppraisalController
}
$product = Db::name('appraisal_draft_products')->where('draft_id', $draftId)->find();
if ($product) {
$product['brand_name'] = $this->resolveBrandName($product);
}
$extra = Db::name('appraisal_draft_extras')->where('draft_id', $draftId)->find();
return api_success([
@@ -140,10 +143,16 @@ class AppraisalController
]);
if ($productInfo) {
$brandId = !empty($productInfo['brand_id']) ? (int)$productInfo['brand_id'] : null;
$brandName = $this->limitText(trim((string)($productInfo['brand_name'] ?? '')), 128);
if ($brandName === '' && $brandId) {
$brandName = $this->lookupName('catalog_brands', 'name', $brandId);
}
$payload = [
'draft_id' => $draftId,
'category_id' => $productInfo['category_id'] ?? null,
'brand_id' => $productInfo['brand_id'] ?? null,
'brand_id' => $brandId,
'brand_name' => $brandName,
'color' => $productInfo['color'] ?? '',
'size_spec' => $productInfo['size_spec'] ?? '',
'serial_no' => $productInfo['serial_no'] ?? '',
@@ -305,7 +314,7 @@ class AppraisalController
'product_summary' => [
'product_name' => $this->resolveProductName($product),
'category_name' => $this->lookupName('catalog_categories', 'name', $product['category_id'] ?? null),
'brand_name' => $this->lookupName('catalog_brands', 'name', $product['brand_id'] ?? null),
'brand_name' => $this->resolveBrandName($product),
'price' => $extra['purchase_price'] ?? 0,
],
'upload_summary' => [
@@ -398,8 +407,8 @@ class AppraisalController
'order_id' => $orderId,
'category_id' => $product['category_id'] ?? null,
'category_name' => $this->lookupName('catalog_categories', 'name', $product['category_id'] ?? null),
'brand_id' => $product['brand_id'] ?? null,
'brand_name' => $this->lookupName('catalog_brands', 'name', $product['brand_id'] ?? null),
'brand_id' => !empty($product['brand_id']) ? (int)$product['brand_id'] : null,
'brand_name' => $this->resolveBrandName($product),
'color' => $product['color'] ?? '',
'size_spec' => $product['size_spec'] ?? '',
'serial_no' => $product['serial_no'] ?? '',
@@ -562,13 +571,27 @@ class AppraisalController
return (string)Db::name($table)->where('id', $id)->value($field);
}
private function resolveBrandName(?array $product): string
{
if (!$product) {
return '';
}
$brandName = trim((string)($product['brand_name'] ?? ''));
if ($brandName !== '') {
return $brandName;
}
return $this->lookupName('catalog_brands', 'name', $product['brand_id'] ?? null);
}
private function resolveProductName(?array $product): string
{
if (!$product) {
return '';
}
$categoryName = $this->lookupName('catalog_categories', 'name', $product['category_id'] ?? null);
$brandName = $this->lookupName('catalog_brands', 'name', $product['brand_id'] ?? null);
$brandName = $this->resolveBrandName($product);
$fallbackName = trim($categoryName . ' ' . $brandName);
if ($fallbackName !== '') {
return $fallbackName;
@@ -576,6 +599,14 @@ class AppraisalController
return '';
}
private function limitText(string $value, int $maxLength): string
{
if (function_exists('mb_substr')) {
return mb_substr($value, 0, $maxLength, 'UTF-8');
}
return substr($value, 0, $maxLength);
}
private function serviceConfig(string $serviceProvider): array
{
$configs = [

View File

@@ -455,6 +455,7 @@ CREATE TABLE appraisal_draft_products (
draft_id BIGINT UNSIGNED NOT NULL,
category_id BIGINT UNSIGNED NULL DEFAULT NULL,
brand_id BIGINT UNSIGNED NULL DEFAULT NULL,
brand_name VARCHAR(128) NOT NULL DEFAULT '',
color VARCHAR(64) NOT NULL DEFAULT '',
size_spec VARCHAR(64) NOT NULL DEFAULT '',
serial_no VARCHAR(128) NOT NULL DEFAULT '',

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
$dotenv->safeLoad();
$dsn = sprintf(
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
$_ENV['DB_HOST'] ?? '127.0.0.1',
$_ENV['DB_PORT'] ?? '3306',
$_ENV['DB_DATABASE'] ?? '',
$_ENV['DB_CHARSET'] ?? 'utf8mb4'
);
$pdo = new PDO(
$dsn,
$_ENV['DB_USERNAME'] ?? '',
$_ENV['DB_PASSWORD'] ?? '',
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
);
function abiHasColumn(PDO $pdo, string $table, string $column): bool
{
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
$stmt->execute([$table, $column]);
return (int)$stmt->fetchColumn() > 0;
}
if (!abiHasColumn($pdo, 'appraisal_draft_products', 'brand_name')) {
$pdo->exec("ALTER TABLE appraisal_draft_products ADD COLUMN brand_name VARCHAR(128) NOT NULL DEFAULT '' AFTER brand_id");
echo "ADD_COLUMN appraisal_draft_products.brand_name\n";
}
$pdo->exec(<<<'SQL'
UPDATE appraisal_draft_products p
JOIN catalog_brands b ON b.id = p.brand_id
SET p.brand_name = b.name
WHERE p.brand_name = ''
AND p.brand_id IS NOT NULL
SQL);
echo "SCHEMA_UPGRADE_APPRAISAL_BRAND_INPUT_OK\n";