Ai config
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
module.exports = {
|
||||
// 积分倍率 (每消费1元获得的积分)
|
||||
POINTS_RATE: 1,
|
||||
|
||||
// 默认密码
|
||||
DEFAULT_PASSWORD: process.env.DEFAULT_PASSWORD || '123456',
|
||||
|
||||
// 利润率估算
|
||||
COST_RATIO: 0.6,
|
||||
PROFIT_RATIO: 0.4,
|
||||
|
||||
// 分页默认值
|
||||
DEFAULT_PAGE_SIZE: 20,
|
||||
MAX_PAGE_SIZE: 100,
|
||||
|
||||
// 库存预警阈值
|
||||
LOW_STOCK_THRESHOLD: 5,
|
||||
|
||||
// 上传限制
|
||||
UPLOAD_MAX_SIZE: 5 * 1024 * 1024,
|
||||
UPLOAD_ALLOWED_TYPES: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
||||
|
||||
// AI 配置
|
||||
AI_TEXT_MODEL: 'qwen3.5-flash',
|
||||
AI_VL_MODEL: 'qwen-vl-max',
|
||||
AI_TEMPERATURE: 0.7,
|
||||
AI_VL_TEMPERATURE: 0.3,
|
||||
AI_MAX_TOKENS: 500,
|
||||
AI_TIMEOUT: 30000,
|
||||
AI_VL_TIMEOUT: 60000,
|
||||
AI_RECOGNIZE_LIMIT: 5,
|
||||
|
||||
// 微信通知
|
||||
WECHAT_TOKEN_BUFFER: 300,
|
||||
WECHAT_MINIPROGRAM_STATE: 'formal',
|
||||
|
||||
// 默认分类颜色
|
||||
DEFAULT_CATEGORY_COLOR: '#1890ff',
|
||||
|
||||
// 订单号随机后缀范围
|
||||
ORDER_ID_RANDOM_MAX: 1000,
|
||||
}
|
||||
@@ -62,9 +62,25 @@ async function initDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
async function transaction(callback) {
|
||||
const connection = await pool.getConnection()
|
||||
try {
|
||||
await connection.beginTransaction()
|
||||
const result = await callback(connection)
|
||||
await connection.commit()
|
||||
return result
|
||||
} catch (error) {
|
||||
await connection.rollback()
|
||||
throw error
|
||||
} finally {
|
||||
connection.release()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
pool,
|
||||
query,
|
||||
transaction,
|
||||
initDatabase,
|
||||
config
|
||||
}
|
||||
+4
-10
@@ -1,15 +1,9 @@
|
||||
// 服务端域名配置常量 - 备案完成后只需修改这里
|
||||
// 服务端域名配置 - 从环境变量读取,默认 IP
|
||||
const BASE_URL = process.env.BASE_URL || 'http://110.42.255.239:3006'
|
||||
|
||||
const DOMAIN_CONFIG = {
|
||||
// 临时域名(备案期间使用)
|
||||
BASE_URL: 'http://110.42.255.239:3006',
|
||||
|
||||
// 正式域名(备案完成后启用,取消注释并注释上面一行)
|
||||
// BASE_URL: 'https://donghy.top',
|
||||
|
||||
// API 路径前缀
|
||||
BASE_URL: BASE_URL,
|
||||
API_PATH: '/api',
|
||||
|
||||
// 图片路径前缀
|
||||
IMG_PATH: '/img'
|
||||
}
|
||||
|
||||
|
||||
+72
-2
@@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS `categories` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL COMMENT '分类名称',
|
||||
`icon` varchar(50) DEFAULT NULL COMMENT '分类图标',
|
||||
`color` varchar(20) DEFAULT '#1890ff' COMMENT '分类颜色',
|
||||
`is_show` tinyint(1) DEFAULT 1 COMMENT '是否显示',
|
||||
`sort_order` int(11) DEFAULT 0 COMMENT '排序顺序',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -9,6 +10,8 @@ CREATE TABLE IF NOT EXISTS `categories` (
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商品分类表';
|
||||
|
||||
ALTER TABLE `categories` ADD COLUMN IF NOT EXISTS `color` varchar(20) DEFAULT '#1890ff' COMMENT '分类颜色';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `goods` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(200) NOT NULL COMMENT '商品名称',
|
||||
@@ -39,10 +42,13 @@ CREATE TABLE IF NOT EXISTS `users` (
|
||||
`points` int(11) DEFAULT 0 COMMENT '积分',
|
||||
`role` tinyint(1) DEFAULT 0 COMMENT '角色 0-普通用户 1-店员',
|
||||
`status` tinyint(1) DEFAULT 1 COMMENT '状态 1-正常 0-禁用',
|
||||
`openid` varchar(100) DEFAULT NULL COMMENT '微信openid',
|
||||
`token` varchar(100) DEFAULT NULL COMMENT '登录token',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `phone` (`phone`)
|
||||
UNIQUE KEY `phone` (`phone`),
|
||||
KEY `openid` (`openid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `orders` (
|
||||
@@ -59,6 +65,23 @@ CREATE TABLE IF NOT EXISTS `orders` (
|
||||
CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `order_items` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`order_id` varchar(64) NOT NULL COMMENT '订单ID',
|
||||
`goods_id` int NOT NULL COMMENT '商品ID',
|
||||
`goods_name` varchar(255) NOT NULL COMMENT '商品名称',
|
||||
`price` decimal(10,2) NOT NULL COMMENT '单价',
|
||||
`quantity` int NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`weight` decimal(10,2) DEFAULT NULL COMMENT '称重(kg)',
|
||||
`subtotal` decimal(10,2) NOT NULL COMMENT '小计',
|
||||
`unit` varchar(20) DEFAULT '' COMMENT '单位',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `order_id` (`order_id`),
|
||||
KEY `goods_id` (`goods_id`),
|
||||
CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单商品明细表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `points_logs` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL COMMENT '用户ID',
|
||||
@@ -123,6 +146,34 @@ CREATE TABLE IF NOT EXISTS `purchase_items` (
|
||||
CONSTRAINT `purchase_items_ibfk_2` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='采购单明细表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `goods_specs` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`goods_id` int(11) NOT NULL COMMENT '商品ID',
|
||||
`spec_name` varchar(100) NOT NULL COMMENT '规格名称(如 330ml/500ml/1L)',
|
||||
`price` decimal(10,2) NOT NULL COMMENT '规格售价',
|
||||
`stock` int(11) DEFAULT 0 COMMENT '规格库存',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `goods_id` (`goods_id`),
|
||||
CONSTRAINT `goods_specs_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商品规格表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `addresses` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL COMMENT '用户ID',
|
||||
`name` varchar(100) NOT NULL COMMENT '收货人姓名',
|
||||
`phone` varchar(20) NOT NULL COMMENT '联系电话',
|
||||
`region` varchar(200) DEFAULT '' COMMENT '地区',
|
||||
`detail` varchar(500) NOT NULL COMMENT '详细地址',
|
||||
`is_default` tinyint(1) DEFAULT 0 COMMENT '是否默认',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
CONSTRAINT `addresses_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='收货地址表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `points_goods` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(200) NOT NULL COMMENT '商品名称',
|
||||
@@ -134,4 +185,23 @@ CREATE TABLE IF NOT EXISTS `points_goods` (
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='积分商品表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='积分商品表';
|
||||
|
||||
-- 订单表索引:按状态筛选、按时间排序
|
||||
ALTER TABLE `orders` ADD INDEX IF NOT EXISTS `idx_orders_status` (`status`);
|
||||
ALTER TABLE `orders` ADD INDEX IF NOT EXISTS `idx_orders_created_at` (`created_at`);
|
||||
|
||||
-- 商品表索引:热销/新品筛选、名称搜索
|
||||
ALTER TABLE `goods` ADD INDEX IF NOT EXISTS `idx_goods_is_hot` (`is_hot`);
|
||||
ALTER TABLE `goods` ADD INDEX IF NOT EXISTS `idx_goods_is_new` (`is_new`);
|
||||
ALTER TABLE `goods` ADD INDEX IF NOT EXISTS `idx_goods_name` (`name`(100));
|
||||
|
||||
-- 分类表索引:按排序字段排序
|
||||
ALTER TABLE `categories` ADD INDEX IF NOT EXISTS `idx_categories_sort_order` (`sort_order`);
|
||||
|
||||
-- 积分记录表索引:按类型筛选
|
||||
ALTER TABLE `points_logs` ADD INDEX IF NOT EXISTS `idx_points_logs_type` (`type`);
|
||||
|
||||
-- 采购单表索引:按状态筛选、按时间排序
|
||||
ALTER TABLE `purchases` ADD INDEX IF NOT EXISTS `idx_purchases_status` (`status`);
|
||||
ALTER TABLE `purchases` ADD INDEX IF NOT EXISTS `idx_purchases_created_at` (`created_at`);
|
||||
Reference in New Issue
Block a user