new api
This commit is contained in:
+11
-6
@@ -1,16 +1,21 @@
|
||||
const mysql = require('mysql2/promise')
|
||||
require('dotenv').config()
|
||||
|
||||
const config = {
|
||||
host: '110.42.255.239',
|
||||
port: 3306,
|
||||
user: 'admin',
|
||||
password: 'Admin@123',
|
||||
database: 'miniprogram',
|
||||
host: process.env.DB_HOST || '110.42.255.239',
|
||||
port: parseInt(process.env.DB_PORT || '3306'),
|
||||
user: process.env.DB_USER || 'admin',
|
||||
password: process.env.DB_PASSWORD || 'Admin@123',
|
||||
database: process.env.DB_NAME || 'miniprogram',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
}
|
||||
|
||||
/*
|
||||
# 登录服务器,找到 Koa 进程
|
||||
ssh ubuntu@110.42.255.239
|
||||
pm2 restart weixin
|
||||
*/
|
||||
const pool = mysql.createPool(config)
|
||||
|
||||
async function query(sql, params = []) {
|
||||
|
||||
+54
-1
@@ -81,4 +81,57 @@ CREATE TABLE IF NOT EXISTS `stock` (
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `goods_id` (`goods_id`),
|
||||
CONSTRAINT `stock_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='库存表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='库存表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `suppliers` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(200) NOT NULL COMMENT '供应商名称',
|
||||
`contact` varchar(100) DEFAULT '' COMMENT '联系人',
|
||||
`phone` varchar(20) DEFAULT '' COMMENT '联系电话',
|
||||
`address` varchar(500) DEFAULT '' COMMENT '地址',
|
||||
`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='供应商表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `purchases` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`supplier_id` int(11) DEFAULT NULL COMMENT '供应商ID',
|
||||
`supplier_name` varchar(200) DEFAULT '' COMMENT '供应商名称(冗余)',
|
||||
`total` decimal(10,2) DEFAULT 0.00 COMMENT '采购总金额',
|
||||
`status` tinyint(4) DEFAULT 0 COMMENT '状态 0-待入库 1-已入库',
|
||||
`remarks` text COMMENT '备注',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `supplier_id` (`supplier_id`),
|
||||
CONSTRAINT `purchases_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='采购单表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `purchase_items` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`purchase_id` int(11) NOT NULL COMMENT '采购单ID',
|
||||
`goods_id` int(11) NOT NULL COMMENT '商品ID',
|
||||
`goods_name` varchar(200) DEFAULT '' COMMENT '商品名称(冗余)',
|
||||
`quantity` int(11) DEFAULT 0 COMMENT '采购数量',
|
||||
`purchase_price` decimal(10,2) DEFAULT 0.00 COMMENT '采购单价',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `purchase_id` (`purchase_id`),
|
||||
KEY `goods_id` (`goods_id`),
|
||||
CONSTRAINT `purchase_items_ibfk_1` FOREIGN KEY (`purchase_id`) REFERENCES `purchases` (`id`) ON DELETE CASCADE,
|
||||
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 `points_goods` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(200) NOT NULL COMMENT '商品名称',
|
||||
`points` int(11) DEFAULT 0 COMMENT '所需积分',
|
||||
`stock` int(11) DEFAULT 0 COMMENT '库存',
|
||||
`image` varchar(500) DEFAULT '' COMMENT '图片',
|
||||
`description` text COMMENT '描述',
|
||||
`is_show` tinyint(4) DEFAULT 1 COMMENT '是否显示',
|
||||
`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='积分商品表';
|
||||
Reference in New Issue
Block a user