chore: release updated anxinyan version
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\support\ExpressCompanyService;
|
||||
use support\Request;
|
||||
|
||||
class ExpressCompaniesController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$enabledOnly = (int)$request->input('enabled_only', 0) === 1;
|
||||
|
||||
return api_success([
|
||||
'list' => $this->service()->list($enabledOnly),
|
||||
'default_company' => $this->service()->defaultName(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$id = (int)$request->input('id', 0);
|
||||
|
||||
try {
|
||||
$companyId = $this->service()->save([
|
||||
'company_name' => $request->input('company_name', ''),
|
||||
'company_code' => $request->input('company_code', ''),
|
||||
'status' => $request->input('status', 'enabled'),
|
||||
'is_default' => $request->input('is_default', false),
|
||||
'sort_order' => $request->input('sort_order', 0),
|
||||
'remark' => $request->input('remark', ''),
|
||||
], $id);
|
||||
} catch (\RuntimeException $e) {
|
||||
return api_error($e->getMessage(), 422);
|
||||
} catch (\Throwable $e) {
|
||||
return api_error('快递公司保存失败', 500, [
|
||||
'detail' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
return api_success([
|
||||
'id' => $companyId,
|
||||
], $id > 0 ? '快递公司已更新' : '快递公司已创建');
|
||||
}
|
||||
|
||||
private function service(): ExpressCompanyService
|
||||
{
|
||||
return new ExpressCompanyService();
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ class ReportsController
|
||||
'r.zhongjian_report_no',
|
||||
'r.report_entry_admin_name',
|
||||
'r.report_entered_at',
|
||||
'r.trace_info_visible',
|
||||
'o.order_no',
|
||||
'p.product_name',
|
||||
'p.category_name',
|
||||
@@ -83,6 +84,7 @@ class ReportsController
|
||||
'zhongjian_report_no' => (string)($item['zhongjian_report_no'] ?? ''),
|
||||
'report_entry_admin_name' => (string)($item['report_entry_admin_name'] ?? ''),
|
||||
'report_entered_at' => (string)($item['report_entered_at'] ?? ''),
|
||||
'trace_info_visible' => (int)($item['trace_info_visible'] ?? 0) === 1,
|
||||
'product_name' => $item['product_name'] ?: (string)($productSnapshot['product_name'] ?? ''),
|
||||
'category_name' => $item['category_name'] ?: (string)($productSnapshot['category_name'] ?? ''),
|
||||
'brand_name' => $item['brand_name'] ?: (string)($productSnapshot['brand_name'] ?? ''),
|
||||
@@ -169,6 +171,7 @@ class ReportsController
|
||||
'report_entry_admin_id' => (int)($report['report_entry_admin_id'] ?? 0),
|
||||
'report_entry_admin_name' => (string)($report['report_entry_admin_name'] ?? ''),
|
||||
'report_entered_at' => (string)($report['report_entered_at'] ?? ''),
|
||||
'trace_info_visible' => (int)($report['trace_info_visible'] ?? 0) === 1,
|
||||
],
|
||||
'product_info' => $productSnapshot,
|
||||
'result_info' => $resultSnapshot,
|
||||
@@ -188,6 +191,32 @@ class ReportsController
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateTraceVisibility(Request $request)
|
||||
{
|
||||
$id = (int)$request->input('id', 0);
|
||||
if (!$id) {
|
||||
return api_error('报告 ID 不能为空', 422);
|
||||
}
|
||||
|
||||
$report = Db::name('reports')->where('id', $id)->find();
|
||||
if (!$report) {
|
||||
return api_error('报告不存在', 404);
|
||||
}
|
||||
|
||||
$visible = $this->boolInput($request->input('trace_info_visible', false));
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
Db::name('reports')->where('id', $id)->update([
|
||||
'trace_info_visible' => $visible ? 1 : 0,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
return api_success([
|
||||
'id' => $id,
|
||||
'trace_info_visible' => $visible,
|
||||
], $visible ? '追溯信息已设为显示' : '追溯信息已隐藏');
|
||||
}
|
||||
|
||||
public function saveInspection(Request $request)
|
||||
{
|
||||
$id = (int)$request->input('id', 0);
|
||||
@@ -540,6 +569,18 @@ class ReportsController
|
||||
return [];
|
||||
}
|
||||
|
||||
private function boolInput(mixed $value): bool
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
return (int)$value === 1;
|
||||
}
|
||||
|
||||
return in_array(strtolower(trim((string)$value)), ['1', 'true', 'yes', 'on'], true);
|
||||
}
|
||||
|
||||
private function loadReportContentMap(array $reportIds): array
|
||||
{
|
||||
if (!$reportIds) {
|
||||
|
||||
@@ -108,12 +108,16 @@ class ReportsController
|
||||
$reportMedia = [
|
||||
'images' => $this->filterAssetsByType($evidenceAttachments, 'image'),
|
||||
];
|
||||
$traceInfo = $this->buildTraceInfo(
|
||||
(int)($reportData['order_id'] ?? 0),
|
||||
$payload['appraisal_snapshot'],
|
||||
$evidenceAttachments,
|
||||
$request
|
||||
);
|
||||
$traceInfoVisible = (int)($reportData['trace_info_visible'] ?? 0) === 1;
|
||||
$traceInfo = $traceInfoVisible
|
||||
? $this->buildTraceInfo(
|
||||
(int)($reportData['order_id'] ?? 0),
|
||||
$payload['appraisal_snapshot'],
|
||||
$evidenceAttachments,
|
||||
$request
|
||||
)
|
||||
: ['visible' => false, 'nodes' => []];
|
||||
$traceInfo['visible'] = $traceInfoVisible;
|
||||
$pdfUrl = $this->ensurePdfFile($request, $reportData, $content ?: [], $verify ?: [], $productDisplay, $reportMedia);
|
||||
|
||||
return api_success([
|
||||
@@ -129,6 +133,7 @@ class ReportsController
|
||||
'zhongjian_report_no' => (string)($reportData['zhongjian_report_no'] ?? ''),
|
||||
'report_entry_admin_name' => (string)($reportData['report_entry_admin_name'] ?? ''),
|
||||
'report_entered_at' => (string)($reportData['report_entered_at'] ?? ''),
|
||||
'trace_info_visible' => $traceInfoVisible,
|
||||
],
|
||||
'result_info' => $payload['result_snapshot'],
|
||||
'product_info' => $payload['product_snapshot'],
|
||||
@@ -353,7 +358,7 @@ class ReportsController
|
||||
$items,
|
||||
$label,
|
||||
$this->textValue($point['point_value'] ?? '') ?: '-',
|
||||
$this->textValue($point['point_remark'] ?? ''),
|
||||
'',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ class AdminAuthMiddleware implements MiddlewareInterface
|
||||
str_starts_with($path, '/api/admin/customers'),
|
||||
str_starts_with($path, '/api/admin/customer/') => ['customers.manage'],
|
||||
str_starts_with($path, '/api/admin/warehouse-workbench/') => ['warehouse_workbench.manage'],
|
||||
str_starts_with($path, '/api/admin/express-companies') && strtoupper($method) === 'GET' => ['warehouse_workbench.manage', 'orders.manage', 'warehouses.manage'],
|
||||
str_starts_with($path, '/api/admin/express-company/') => ['warehouses.manage'],
|
||||
str_starts_with($path, '/api/admin/warehouses'),
|
||||
str_starts_with($path, '/api/admin/warehouse/') => ['warehouses.manage'],
|
||||
str_starts_with($path, '/api/admin/material/') => ['materials.manage'],
|
||||
|
||||
208
server-api/app/support/ExpressCompanyService.php
Normal file
208
server-api/app/support/ExpressCompanyService.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace app\support;
|
||||
|
||||
use support\think\Db;
|
||||
|
||||
class ExpressCompanyService
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->ensureTable();
|
||||
$this->bootstrapDefaults();
|
||||
}
|
||||
|
||||
public function list(bool $enabledOnly = false): array
|
||||
{
|
||||
$query = Db::name('express_companies')
|
||||
->order('is_default', 'desc')
|
||||
->order('sort_order', 'asc')
|
||||
->order('id', 'asc');
|
||||
|
||||
if ($enabledOnly) {
|
||||
$query->where('status', 'enabled');
|
||||
}
|
||||
|
||||
return array_map(fn (array $item) => $this->format($item), $query->select()->toArray());
|
||||
}
|
||||
|
||||
public function save(array $payload, int $id = 0): int
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$companyName = trim((string)($payload['company_name'] ?? ''));
|
||||
$companyCode = trim((string)($payload['company_code'] ?? ''));
|
||||
$status = trim((string)($payload['status'] ?? 'enabled'));
|
||||
$isDefault = !empty($payload['is_default']);
|
||||
|
||||
if ($companyName === '') {
|
||||
throw new \RuntimeException('快递公司名称不能为空');
|
||||
}
|
||||
if (!in_array($status, ['enabled', 'disabled'], true)) {
|
||||
throw new \RuntimeException('快递公司状态无效');
|
||||
}
|
||||
if ($isDefault && $status !== 'enabled') {
|
||||
throw new \RuntimeException('默认快递公司必须保持启用');
|
||||
}
|
||||
if ($companyCode === '') {
|
||||
$companyCode = $this->generateCompanyCode($companyName);
|
||||
}
|
||||
|
||||
$existsByName = Db::name('express_companies')
|
||||
->where('company_name', $companyName)
|
||||
->when($id > 0, fn ($query) => $query->where('id', '<>', $id))
|
||||
->find();
|
||||
if ($existsByName) {
|
||||
throw new \RuntimeException('快递公司名称已存在');
|
||||
}
|
||||
|
||||
$existsByCode = Db::name('express_companies')
|
||||
->where('company_code', $companyCode)
|
||||
->when($id > 0, fn ($query) => $query->where('id', '<>', $id))
|
||||
->find();
|
||||
if ($existsByCode) {
|
||||
throw new \RuntimeException('快递公司编码已存在');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'company_name' => $companyName,
|
||||
'company_code' => $companyCode,
|
||||
'status' => $status,
|
||||
'is_default' => $isDefault ? 1 : 0,
|
||||
'sort_order' => (int)($payload['sort_order'] ?? 0),
|
||||
'remark' => trim((string)($payload['remark'] ?? '')),
|
||||
'updated_at' => $now,
|
||||
];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($isDefault) {
|
||||
Db::name('express_companies')->update([
|
||||
'is_default' => 0,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($id > 0) {
|
||||
Db::name('express_companies')->where('id', $id)->update($data);
|
||||
$companyId = $id;
|
||||
} else {
|
||||
$data['created_at'] = $now;
|
||||
$companyId = (int)Db::name('express_companies')->insertGetId($data);
|
||||
}
|
||||
|
||||
$this->ensureEnabledDefault($now);
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $companyId;
|
||||
}
|
||||
|
||||
public function defaultName(): string
|
||||
{
|
||||
$row = Db::name('express_companies')
|
||||
->where('status', 'enabled')
|
||||
->where('is_default', 1)
|
||||
->find();
|
||||
|
||||
if (!$row) {
|
||||
$row = Db::name('express_companies')
|
||||
->where('status', 'enabled')
|
||||
->order('sort_order', 'asc')
|
||||
->order('id', 'asc')
|
||||
->find();
|
||||
}
|
||||
|
||||
return trim((string)($row['company_name'] ?? ''));
|
||||
}
|
||||
|
||||
private function format(array $item): array
|
||||
{
|
||||
$status = (string)($item['status'] ?? 'enabled');
|
||||
|
||||
return [
|
||||
'id' => (int)$item['id'],
|
||||
'company_name' => (string)$item['company_name'],
|
||||
'company_code' => (string)$item['company_code'],
|
||||
'status' => $status,
|
||||
'status_text' => $status === 'enabled' ? '启用中' : '已停用',
|
||||
'is_default' => (bool)$item['is_default'],
|
||||
'sort_order' => (int)$item['sort_order'],
|
||||
'remark' => (string)($item['remark'] ?? ''),
|
||||
'created_at' => (string)($item['created_at'] ?? ''),
|
||||
'updated_at' => (string)($item['updated_at'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
private function bootstrapDefaults(): void
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$exists = Db::name('express_companies')->where('company_name', '顺丰速运')->find();
|
||||
if (!$exists) {
|
||||
Db::name('express_companies')->insert([
|
||||
'company_name' => '顺丰速运',
|
||||
'company_code' => 'sf_express',
|
||||
'status' => 'enabled',
|
||||
'is_default' => 1,
|
||||
'sort_order' => 1,
|
||||
'remark' => '系统默认快递公司',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->ensureEnabledDefault($now);
|
||||
}
|
||||
|
||||
private function ensureEnabledDefault(string $now): void
|
||||
{
|
||||
$default = Db::name('express_companies')
|
||||
->where('status', 'enabled')
|
||||
->where('is_default', 1)
|
||||
->find();
|
||||
if ($default) {
|
||||
return;
|
||||
}
|
||||
|
||||
$firstEnabled = Db::name('express_companies')
|
||||
->where('status', 'enabled')
|
||||
->order('sort_order', 'asc')
|
||||
->order('id', 'asc')
|
||||
->find();
|
||||
if ($firstEnabled) {
|
||||
Db::name('express_companies')->where('id', $firstEnabled['id'])->update([
|
||||
'is_default' => 1,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function generateCompanyCode(string $companyName): string
|
||||
{
|
||||
return 'express_' . substr(hash('sha256', $companyName), 0, 12);
|
||||
}
|
||||
|
||||
private function ensureTable(): void
|
||||
{
|
||||
Db::execute(<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS express_companies (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
company_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
company_code VARCHAR(64) NOT NULL DEFAULT '',
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'enabled',
|
||||
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_express_companies_name (company_name),
|
||||
UNIQUE KEY uk_express_companies_code (company_code),
|
||||
KEY idx_express_companies_status (status),
|
||||
KEY idx_express_companies_default (is_default)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='快递公司字典'
|
||||
SQL);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ use app\controller\admin\SystemConfigsController as AdminSystemConfigsController
|
||||
use app\controller\admin\AuthController as AdminAuthController;
|
||||
use app\controller\admin\CustomersController as AdminCustomersController;
|
||||
use app\controller\admin\WarehouseWorkbenchController as AdminWarehouseWorkbenchController;
|
||||
use app\controller\admin\ExpressCompaniesController as AdminExpressCompaniesController;
|
||||
use app\controller\admin\FileUploadController as AdminFileUploadController;
|
||||
use app\controller\open\OrdersController as OpenOrdersController;
|
||||
|
||||
@@ -219,6 +220,7 @@ Route::post('/api/admin/catalog/upload-templates/save', [AdminCatalogController:
|
||||
Route::post('/api/admin/catalog/appraisal-templates/save', [AdminCatalogController::class, 'saveAppraisalTemplates']);
|
||||
Route::get('/api/admin/reports', [AdminReportsController::class, 'index']);
|
||||
Route::get('/api/admin/report/detail', [AdminReportsController::class, 'detail']);
|
||||
Route::post('/api/admin/report/trace-visibility', [AdminReportsController::class, 'updateTraceVisibility']);
|
||||
Route::post('/api/admin/report/inspection/save', [AdminReportsController::class, 'saveInspection']);
|
||||
Route::post('/api/admin/report/publish', [AdminReportsController::class, 'publish']);
|
||||
Route::get('/api/admin/appraisal-tasks', [AdminAppraisalTasksController::class, 'index']);
|
||||
@@ -262,6 +264,8 @@ Route::post('/api/admin/customer/event/resend', [AdminCustomersController::class
|
||||
Route::get('/api/admin/warehouses/overview', [AdminWarehousesController::class, 'overview']);
|
||||
Route::get('/api/admin/warehouses', [AdminWarehousesController::class, 'index']);
|
||||
Route::post('/api/admin/warehouse/save', [AdminWarehousesController::class, 'save']);
|
||||
Route::get('/api/admin/express-companies', [AdminExpressCompaniesController::class, 'index']);
|
||||
Route::post('/api/admin/express-company/save', [AdminExpressCompaniesController::class, 'save']);
|
||||
Route::get('/api/admin/warehouse-workbench/inbound/lookup', [AdminWarehouseWorkbenchController::class, 'inboundLookup']);
|
||||
Route::post('/api/admin/warehouse-workbench/inbound/receive', [AdminWarehouseWorkbenchController::class, 'inboundReceive']);
|
||||
Route::post('/api/admin/warehouse-workbench/inbound/evidence/upload', [AdminWarehouseWorkbenchController::class, 'uploadInboundEvidenceFile']);
|
||||
|
||||
@@ -12,6 +12,7 @@ DROP TABLE IF EXISTS enterprise_customer_order_refs;
|
||||
DROP TABLE IF EXISTS enterprise_api_nonces;
|
||||
DROP TABLE IF EXISTS enterprise_customer_apps;
|
||||
DROP TABLE IF EXISTS enterprise_customers;
|
||||
DROP TABLE IF EXISTS express_companies;
|
||||
DROP TABLE IF EXISTS shipping_warehouses;
|
||||
DROP TABLE IF EXISTS user_api_tokens;
|
||||
DROP TABLE IF EXISTS sms_code_logs;
|
||||
@@ -729,6 +730,23 @@ CREATE TABLE order_logistics_nodes (
|
||||
KEY idx_order_logistics_nodes_logistics_id (logistics_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='物流节点';
|
||||
|
||||
CREATE TABLE express_companies (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
company_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
company_code VARCHAR(64) NOT NULL DEFAULT '',
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'enabled',
|
||||
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_express_companies_name (company_name),
|
||||
UNIQUE KEY uk_express_companies_code (company_code),
|
||||
KEY idx_express_companies_status (status),
|
||||
KEY idx_express_companies_default (is_default)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='快递公司字典';
|
||||
|
||||
CREATE TABLE order_abnormals (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
order_id BIGINT UNSIGNED NOT NULL,
|
||||
@@ -949,6 +967,7 @@ CREATE TABLE reports (
|
||||
report_entry_admin_id BIGINT UNSIGNED NULL DEFAULT NULL,
|
||||
report_entry_admin_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
report_entered_at DATETIME NULL DEFAULT NULL,
|
||||
trace_info_visible TINYINT(1) NOT NULL DEFAULT 0,
|
||||
invalid_reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
@@ -26,6 +26,7 @@ $pdo = new PDO(
|
||||
);
|
||||
|
||||
$tables = [
|
||||
'express_companies',
|
||||
'shipping_warehouses',
|
||||
'order_shipping_targets',
|
||||
'material_tag_scan_logs', 'material_batch_download_logs', 'material_tag_codes', 'material_batches',
|
||||
@@ -62,6 +63,9 @@ INSERT INTO shipping_warehouses (id, warehouse_name, warehouse_code, warehouse_t
|
||||
(1, '安心验鉴定中心', 'AXY-WH-DEFAULT', 'detection_center', 'anxinyan', '安心验鉴定中心', '400-800-1314', '广东省', '深圳市', '南山区', '科技园鉴定路 88 号 安心验收件中心', '周一至周日 09:30-18:30', '寄送前请确认订单信息完整,包裹内附上订单号可提升签收后的处理效率。', NULL, NULL, NULL, 'enabled', 1, 1, '默认仓库', '{$now}', '{$now}'),
|
||||
(2, '中检合作鉴定中心', 'ZJ-WH-DEFAULT', 'detection_center', 'zhongjian', '中检合作鉴定中心', '400-800-1314', '广东省', '深圳市', '南山区', '科技园鉴定路 88 号 安心验中检收件中心', '周一至周日 09:30-18:30', '中检鉴定订单请优先附上鉴定单号,寄出后尽快填写运单号。', NULL, NULL, NULL, 'enabled', 1, 1, '默认仓库', '{$now}', '{$now}');
|
||||
|
||||
INSERT INTO express_companies (id, company_name, company_code, status, is_default, sort_order, remark, created_at, updated_at) VALUES
|
||||
(1, '顺丰速运', 'sf_express', 'enabled', 1, 1, '系统默认快递公司', '{$now}', '{$now}');
|
||||
|
||||
INSERT INTO catalog_categories (id, name, code, sort_order, is_enabled, need_shipping, supported_service_types, created_at, updated_at) VALUES
|
||||
(1, '奢侈品箱包', 'luxury_bag', 1, 1, 1, JSON_ARRAY('anxinyan', 'zhongjian'), '{$now}', '{$now}'),
|
||||
(2, '潮流鞋类', 'sneaker', 2, 1, 1, JSON_ARRAY('anxinyan', 'zhongjian'), '{$now}', '{$now}'),
|
||||
|
||||
68
server-api/tools/schema_upgrade_express_companies.php
Normal file
68
server-api/tools/schema_upgrade_express_companies.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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,
|
||||
]
|
||||
);
|
||||
|
||||
$pdo->exec(<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS express_companies (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
company_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
company_code VARCHAR(64) NOT NULL DEFAULT '',
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'enabled',
|
||||
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_express_companies_name (company_name),
|
||||
UNIQUE KEY uk_express_companies_code (company_code),
|
||||
KEY idx_express_companies_status (status),
|
||||
KEY idx_express_companies_default (is_default)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='快递公司字典'
|
||||
SQL);
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$stmt = $pdo->prepare('SELECT id FROM express_companies WHERE company_name = ? LIMIT 1');
|
||||
$stmt->execute(['顺丰速运']);
|
||||
$exists = $stmt->fetch();
|
||||
|
||||
if (!$exists) {
|
||||
$insert = $pdo->prepare('INSERT INTO express_companies (company_name, company_code, status, is_default, sort_order, remark, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
||||
$insert->execute(['顺丰速运', 'sf_express', 'enabled', 1, 1, '系统默认快递公司', $now, $now]);
|
||||
echo "SEED_DEFAULT_EXPRESS_COMPANY\n";
|
||||
}
|
||||
|
||||
$defaultCount = (int)$pdo->query("SELECT COUNT(*) FROM express_companies WHERE status = 'enabled' AND is_default = 1")->fetchColumn();
|
||||
if ($defaultCount === 0) {
|
||||
$row = $pdo->query("SELECT id FROM express_companies WHERE status = 'enabled' ORDER BY sort_order ASC, id ASC LIMIT 1")->fetch();
|
||||
if ($row) {
|
||||
$update = $pdo->prepare('UPDATE express_companies SET is_default = 1, updated_at = ? WHERE id = ?');
|
||||
$update->execute([$now, (int)$row['id']]);
|
||||
echo "SET_DEFAULT_EXPRESS_COMPANY\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "SCHEMA_UPGRADE_OK\n";
|
||||
40
server-api/tools/schema_upgrade_report_trace_visibility.php
Normal file
40
server-api/tools/schema_upgrade_report_trace_visibility.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 hasColumn(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 (!hasColumn($pdo, 'reports', 'trace_info_visible')) {
|
||||
$pdo->exec('ALTER TABLE reports ADD COLUMN trace_info_visible TINYINT(1) NOT NULL DEFAULT 0 AFTER report_entered_at');
|
||||
echo "ADD_COLUMN reports.trace_info_visible\n";
|
||||
}
|
||||
|
||||
echo "SCHEMA_UPGRADE_REPORT_TRACE_VISIBILITY_OK\n";
|
||||
Reference in New Issue
Block a user