Simplify manual order creation

This commit is contained in:
wushumin
2026-05-21 18:55:01 +08:00
parent d0c4332468
commit b98d6164a7
5 changed files with 49 additions and 233 deletions

View File

@@ -938,6 +938,7 @@ class OrdersController
$categoryId = (int)($productInput['category_id'] ?? 0);
$brandId = (int)($productInput['brand_id'] ?? 0);
$brandName = $this->limitManualText(trim((string)($productInput['brand_name'] ?? '')), 128);
$productName = trim((string)($productInput['product_name'] ?? ''));
$consignee = trim((string)($returnAddressInput['consignee'] ?? ''));
$mobile = trim((string)($returnAddressInput['mobile'] ?? ''));
@@ -949,8 +950,8 @@ class OrdersController
if ($serviceProvider === '') {
return api_error('服务类型不正确', 422);
}
if ($categoryId <= 0 || $brandId <= 0) {
return api_error('请完整填写品类和品牌', 422);
if ($categoryId <= 0) {
return api_error('请选择品类', 422);
}
if ($consignee === '' || $mobile === '' || $province === '' || $city === '' || $district === '' || $detailAddress === '') {
return api_error('请完整填写寄回收件信息', 422);
@@ -960,9 +961,18 @@ class OrdersController
if (!$category) {
return api_error('品类不存在', 422);
}
$brand = Db::name('catalog_brands')->where('id', $brandId)->find();
if (!$brand) {
return api_error('品牌不存在', 422);
$brand = null;
if ($brandId > 0) {
$brand = Db::name('catalog_brands')->where('id', $brandId)->find();
if (!$brand) {
return api_error('品牌不存在', 422);
}
if ($brandName === '') {
$brandName = (string)$brand['name'];
}
}
if ($productName === '') {
$productName = trim((string)$category['name'] . ' ' . $brandName);
}
$now = date('Y-m-d H:i:s');
@@ -1006,8 +1016,8 @@ class OrdersController
'order_id' => $orderId,
'category_id' => $categoryId,
'category_name' => (string)$category['name'],
'brand_id' => $brandId,
'brand_name' => (string)$brand['name'],
'brand_id' => $brandId > 0 ? $brandId : null,
'brand_name' => $brandName,
'color' => trim((string)($productInput['color'] ?? '')),
'size_spec' => trim((string)($productInput['size_spec'] ?? '')),
'serial_no' => trim((string)($productInput['serial_no'] ?? '')),
@@ -1547,6 +1557,15 @@ class OrdersController
};
}
private function limitManualText(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 formatAdminLogisticsDesc(string $logisticsType, string $status, string $expressCompany, string $trackingNo, string $fallback): string
{
$expressCompany = trim($expressCompany);