重构动物模型和路由系统,优化查询逻辑并新增商户和促销活动功能
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
-- 解班客数据库完整结构创建脚本
|
||||
-- 结伴客数据库完整结构创建脚本
|
||||
-- 创建时间: 2024年
|
||||
-- 数据库: jbkdata
|
||||
|
||||
|
||||
@@ -46,6 +46,44 @@ CREATE TABLE IF NOT EXISTS orders (
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 创建促销活动表
|
||||
CREATE TABLE IF NOT EXISTS promotion_activities (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
description TEXT,
|
||||
type ENUM('signup', 'invitation', 'purchase', 'custom') NOT NULL,
|
||||
status ENUM('active', 'inactive', 'expired') DEFAULT 'active',
|
||||
start_date DATE NOT NULL,
|
||||
end_date DATE NOT NULL,
|
||||
reward_type ENUM('cash', 'points', 'coupon') NOT NULL,
|
||||
reward_amount DECIMAL(15,2) NOT NULL,
|
||||
participation_limit INT DEFAULT 0 COMMENT '0表示无限制',
|
||||
current_participants INT DEFAULT 0,
|
||||
rules JSON COMMENT '活动规则配置',
|
||||
created_by INT NOT NULL COMMENT '创建人ID',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (created_by) REFERENCES admins(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 创建奖励记录表
|
||||
CREATE TABLE IF NOT EXISTS promotion_rewards (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
user_name VARCHAR(100) NOT NULL,
|
||||
user_phone VARCHAR(20),
|
||||
activity_id INT NOT NULL,
|
||||
activity_name VARCHAR(100) NOT NULL,
|
||||
reward_type ENUM('cash', 'points', 'coupon') NOT NULL,
|
||||
reward_amount DECIMAL(15,2) NOT NULL,
|
||||
status ENUM('pending', 'issued', 'failed') DEFAULT 'pending',
|
||||
issued_at TIMESTAMP NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (activity_id) REFERENCES promotion_activities(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 插入默认管理员账号
|
||||
INSERT INTO admins (username, password, email, role) VALUES
|
||||
('admin', '$2b$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin@jiebanke.com', 'super_admin'),
|
||||
@@ -64,4 +102,11 @@ CREATE INDEX idx_users_email ON users(email);
|
||||
CREATE INDEX idx_users_phone ON users(phone);
|
||||
CREATE INDEX idx_orders_user_id ON orders(user_id);
|
||||
CREATE INDEX idx_orders_order_no ON orders(order_no);
|
||||
CREATE INDEX idx_orders_status ON orders(status);
|
||||
CREATE INDEX idx_orders_status ON orders(status);
|
||||
CREATE INDEX idx_promotion_activities_status ON promotion_activities(status);
|
||||
CREATE INDEX idx_promotion_activities_type ON promotion_activities(type);
|
||||
CREATE INDEX idx_promotion_activities_dates ON promotion_activities(start_date, end_date);
|
||||
CREATE INDEX idx_promotion_rewards_user_id ON promotion_rewards(user_id);
|
||||
CREATE INDEX idx_promotion_rewards_activity_id ON promotion_rewards(activity_id);
|
||||
CREATE INDEX idx_promotion_rewards_status ON promotion_rewards(status);
|
||||
CREATE INDEX idx_promotion_rewards_created_at ON promotion_rewards(created_at);
|
||||
@@ -8,8 +8,9 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
const config = require('../config/env');
|
||||
|
||||
// 引入database.js配置
|
||||
const dbConfig = require('../src/config/database').pool.config;
|
||||
// 引入环境配置
|
||||
const envConfig = require('../config/env');
|
||||
const dbConfig = envConfig.mysql;
|
||||
|
||||
// 数据库配置已从database.js导入
|
||||
|
||||
|
||||
Reference in New Issue
Block a user