更新技术实施方案和PRD文档版本历史

This commit is contained in:
2025-09-12 13:10:44 +08:00
parent 320f41f25d
commit bbc7abd69c
13 changed files with 5565 additions and 406 deletions

View File

@@ -22,6 +22,9 @@ const sequelize = new Sequelize(
}
);
// 导入模型定义
const defineOrder = require('./order.js');
// 测试数据库连接
const testConnection = async () => {
try {
@@ -118,15 +121,23 @@ const models = {
}, {
tableName: 'api_users',
timestamps: true
})
}),
// 订单模型
Order: defineOrder(sequelize)
};
// 同步数据库模型
const syncModels = async () => {
try {
// 同步API用户表如果不存在则创建
// 同步API用户表如果不存在则创建
await models.ApiUser.sync({ alter: true });
console.log('✅ API用户表同步成功');
// 同步订单表(如果不存在则创建)
await models.Order.sync({ alter: true });
console.log('✅ 订单表同步成功');
console.log('✅ 数据库模型同步完成');
} catch (error) {
console.error('❌ 数据库模型同步失败:', error);

132
backend/models/order.js Normal file
View File

@@ -0,0 +1,132 @@
// 订单模型定义
const { Sequelize } = require('sequelize');
module.exports = (sequelize) => {
const Order = sequelize.define('Order', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
orderNo: {
type: Sequelize.STRING(20),
allowNull: false,
unique: true,
comment: '订单编号'
},
buyerId: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '买方ID'
},
buyerName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '买方名称'
},
supplierId: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '供应商ID'
},
supplierName: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '供应商名称'
},
traderId: {
type: Sequelize.INTEGER,
allowNull: true,
comment: '贸易商ID'
},
traderName: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '贸易商名称'
},
cattleBreed: {
type: Sequelize.STRING(50),
allowNull: false,
comment: '牛的品种'
},
cattleCount: {
type: Sequelize.INTEGER,
allowNull: false,
comment: '牛的数量'
},
expectedWeight: {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
comment: '预计总重量'
},
actualWeight: {
type: Sequelize.DECIMAL(10, 2),
allowNull: true,
comment: '实际总重量'
},
unitPrice: {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
comment: '单价'
},
totalAmount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
comment: '总金额'
},
paidAmount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
defaultValue: 0,
comment: '已支付金额'
},
remainingAmount: {
type: Sequelize.DECIMAL(15, 2),
allowNull: false,
comment: '剩余金额'
},
status: {
type: Sequelize.ENUM(
'pending', 'confirmed', 'preparing', 'shipping',
'delivered', 'accepted', 'completed', 'cancelled', 'refunded'
),
allowNull: false,
defaultValue: 'pending',
comment: '订单状态'
},
deliveryAddress: {
type: Sequelize.STRING(200),
allowNull: false,
comment: '收货地址'
},
expectedDeliveryDate: {
type: Sequelize.DATE,
allowNull: false,
comment: '预计交货日期'
},
actualDeliveryDate: {
type: Sequelize.DATE,
allowNull: true,
comment: '实际交货日期'
},
notes: {
type: Sequelize.TEXT,
allowNull: true,
comment: '备注信息'
}
}, {
tableName: 'orders',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
indexes: [
{ fields: ['orderNo'] },
{ fields: ['buyerId'] },
{ fields: ['supplierId'] },
{ fields: ['status'] },
{ fields: ['created_at'] }
]
});
return Order;
};