diff --git a/server-api/app/controller/app/AppraisalController.php b/server-api/app/controller/app/AppraisalController.php index 8831353..45af524 100644 --- a/server-api/app/controller/app/AppraisalController.php +++ b/server-api/app/controller/app/AppraisalController.php @@ -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 = [ diff --git a/server-api/database/schema.sql b/server-api/database/schema.sql index 5eb6031..fc506cd 100644 --- a/server-api/database/schema.sql +++ b/server-api/database/schema.sql @@ -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 '', diff --git a/server-api/tools/schema_upgrade_appraisal_brand_input.php b/server-api/tools/schema_upgrade_appraisal_brand_input.php new file mode 100644 index 0000000..2a22548 --- /dev/null +++ b/server-api/tools/schema_upgrade_appraisal_brand_input.php @@ -0,0 +1,48 @@ +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"; diff --git a/user-app/src/pages.json b/user-app/src/pages.json index b1f672a..d6f65b0 100644 --- a/user-app/src/pages.json +++ b/user-app/src/pages.json @@ -25,18 +25,6 @@ "navigationBarTitleText": "选择商品信息" } }, - { - "path": "pages/appraisal/extra", - "style": { - "navigationBarTitleText": "补充商品信息" - } - }, - { - "path": "pages/appraisal/upload", - "style": { - "navigationBarTitleText": "上传鉴定资料" - } - }, { "path": "pages/appraisal/confirm", "style": { diff --git a/user-app/src/pages/appraisal/confirm.vue b/user-app/src/pages/appraisal/confirm.vue index ee855de..252e293 100644 --- a/user-app/src/pages/appraisal/confirm.vue +++ b/user-app/src/pages/appraisal/confirm.vue @@ -12,9 +12,10 @@ const store = useAppraisalStore(); const preview = computed(() => store.preview); const loading = computed(() => !store.preview); const submitting = computed(() => false); -const purchasePriceText = computed(() => { - const price = Number(preview.value?.product_summary.price || 0); - return price > 0 ? `¥${price}` : "未填写"; +const productCategoryBrandText = computed(() => { + const categoryName = preview.value?.product_summary.category_name || ""; + const brandName = preview.value?.product_summary.brand_name || "未填写"; + return categoryName ? `${categoryName} / ${brandName}` : ""; }); const addressSheetVisible = ref(false); const addressesLoading = ref(false); @@ -163,10 +164,11 @@ onShow(fetchAddresses);