data-init.sql 9.3 KB
-- 外卖配送中台 初始化数据脚本
-- 执行前请确保已执行 schema.sql 建表
-- 执行方式:mysql -u root -p dili_rider < data-init.sql

USE dili_rider;

-- ============================================================
-- 1. 城市数据(省+市两级)
-- ============================================================
INSERT INTO `city` (`id`, `pid`, `name`, `area_code`, `status`, `rate`, `list_order`, `config`) VALUES
(1, 0, '广东省', '44000000', 0, 0.00, 1, NULL),
(2, 1, '广州市', '44010000', 1, 10.00, 1,
'{
  "type": [6],
  "type6": {
    "feeMode": 2,
    "fixMoney": 0,
    "distanceSwitch": 1,
    "distanceBasic": 3,
    "distanceBasicMoney": 4.00,
    "distanceMoreMoney": 1.50,
    "distanceMode": 1,
    "distanceType": 1,
    "weightSwitch": 0,
    "weightBasic": 0,
    "weightBasicMoney": 0,
    "weightMoreMoney": 0,
    "weightType": 1,
    "times": [
      {"start": 0,    "end": 480,  "isOpen": 0, "money": 0},
      {"start": 480,  "end": 1320, "isOpen": 1, "money": 0},
      {"start": 1320, "end": 1440, "isOpen": 1, "money": 2}
    ]
  },
  "distanceBasic": 3,
  "distanceBasicTime": 30,
  "distanceMoreTime": 10
}'),
(3, 1, '深圳市', '44030000', 1, 10.00, 2,
'{
  "type": [6],
  "type6": {
    "feeMode": 1,
    "fixMoney": 5.00,
    "distanceSwitch": 0,
    "distanceBasic": 0,
    "distanceBasicMoney": 0,
    "distanceMoreMoney": 0,
    "distanceMode": 1,
    "distanceType": 1,
    "weightSwitch": 0,
    "weightBasic": 0,
    "weightBasicMoney": 0,
    "weightMoreMoney": 0,
    "weightType": 1,
    "times": []
  },
  "distanceBasic": 3,
  "distanceBasicTime": 25,
  "distanceMoreTime": 8
}');

-- ============================================================
-- 2. 分站管理员(每个已开通城市一个)
-- 默认密码均为 admin123(MD5: 0192023a7bbd73250516f069df18b500)
-- ============================================================
INSERT INTO `sys_role` (`code`, `name`, `role_scope`, `status`, `create_time`) VALUES
('platform_admin', '平台管理员', 'PLATFORM', 1, UNIX_TIMESTAMP()),
('substation_admin', '分站管理员', 'SUBSTATION', 1, UNIX_TIMESTAMP());

INSERT INTO `sys_menu` (`code`, `name`, `type`, `path`, `icon`, `parent_id`, `menu_scope`, `list_order`, `visible`, `status`, `create_time`) VALUES
('dashboard', '工作台', 'MENU', '/dashboard', 'HomeOutlined', 0, 'BOTH', 10, 1, 1, UNIX_TIMESTAMP()),
('city.manage', '租户管理', 'MENU', '/city', 'GlobalOutlined', 0, 'PLATFORM', 20, 1, 1, UNIX_TIMESTAMP()),
('substation.manage', '分站管理', 'MENU', '/substation', 'ApartmentOutlined', 0, 'PLATFORM', 30, 1, 1, UNIX_TIMESTAMP()),
('merchant.root', '商家管理', 'DIR', '', 'ShopOutlined', 0, 'PLATFORM', 40, 1, 1, UNIX_TIMESTAMP()),
('merchant.enter', '入驻申请', 'MENU', '/merchant/enter', '', 4, 'PLATFORM', 41, 1, 1, UNIX_TIMESTAMP()),
('merchant.store', '店铺管理', 'MENU', '/merchant/store', '', 4, 'PLATFORM', 42, 1, 1, UNIX_TIMESTAMP()),
('rider.list', '骑手管理', 'MENU', '/rider', 'UserOutlined', 0, 'BOTH', 50, 1, 1, UNIX_TIMESTAMP()),
('rider.evaluate', '骑手评价', 'MENU', '/rider/evaluate', 'StarOutlined', 0, 'BOTH', 60, 1, 1, UNIX_TIMESTAMP()),
('order.root', '订单管理', 'DIR', '', 'UnorderedListOutlined', 0, 'BOTH', 70, 1, 1, UNIX_TIMESTAMP()),
('order.list', '订单列表', 'MENU', '/order', '', 9, 'BOTH', 71, 1, 1, UNIX_TIMESTAMP()),
('order.refund', '退款管理', 'MENU', '/refund', '', 9, 'BOTH', 72, 1, 1, UNIX_TIMESTAMP()),
('order.delivery', '配送订单', 'MENU', '/delivery/order', '', 9, 'BOTH', 73, 1, 1, UNIX_TIMESTAMP()),
('config.root', '配置中心', 'DIR', '', 'ControlOutlined', 0, 'BOTH', 80, 1, 1, UNIX_TIMESTAMP()),
('fee.plan', '配送费配置', 'MENU', '/config/fee-plan', '', 13, 'BOTH', 81, 1, 1, UNIX_TIMESTAMP()),
('dispatch.rule', '调度配置', 'MENU', '/dispatch/rule', '', 13, 'BOTH', 82, 1, 1, UNIX_TIMESTAMP()),
('open.root', '开放平台', 'DIR', '', 'ApiOutlined', 0, 'PLATFORM', 90, 1, 1, UNIX_TIMESTAMP()),
('open.app', '应用管理', 'MENU', '/open', '', 16, 'PLATFORM', 91, 1, 1, UNIX_TIMESTAMP()),
('open.mock_delivery', '模拟推单', 'MENU', '/open/mock-delivery', '', 16, 'PLATFORM', 92, 1, 1, UNIX_TIMESTAMP()),
('system.root', '系统管理', 'DIR', '', 'ControlOutlined', 0, 'PLATFORM', 100, 1, 1, UNIX_TIMESTAMP()),
('system.menu', '菜单管理', 'MENU', '/system/menu', '', 19, 'PLATFORM', 101, 1, 1, UNIX_TIMESTAMP()),
('system.role_menu', '角色菜单', 'MENU', '/system/role-menu', '', 19, 'PLATFORM', 102, 1, 1, UNIX_TIMESTAMP()),
('admin.user', '平台账号', 'MENU', '/admin-user', '', 19, 'PLATFORM', 103, 1, 1, UNIX_TIMESTAMP());

INSERT INTO `sys_role_menu` (`role_id`, `menu_id`, `create_time`)
SELECT 1, id, UNIX_TIMESTAMP() FROM `sys_menu` WHERE `menu_scope` IN ('PLATFORM', 'BOTH');

INSERT INTO `sys_role_menu` (`role_id`, `menu_id`, `create_time`)
SELECT 2, id, UNIX_TIMESTAMP() FROM `sys_menu` WHERE `menu_scope` IN ('SUBSTATION', 'BOTH');

INSERT INTO `substation` (`city_id`, `user_login`, `user_nickname`, `user_pass`, `mobile`, `user_status`, `role_id`, `create_time`) VALUES
(2, 'gz_admin', '广州分站管理员', '0192023a7bbd73250516f069df18b500', '13800000001', 1, 2, UNIX_TIMESTAMP()),
(3, 'sz_admin', '深圳分站管理员', '0192023a7bbd73250516f069df18b500', '13800000002', 1, 2, UNIX_TIMESTAMP());

-- ============================================================
-- 3. 骑手等级配置(广州)
-- ============================================================
INSERT INTO `rider_level` (`city_id`, `level_id`, `name`, `is_default`, `trans_nums`,
  `run_fee_mode`, `run_fix_money`, `run_rate`, `distance_basic`, `distance_basic_money`,
  `distance_more_money`, `distance_max_money`, `work_fee_mode`, `work_fix_money`, `work_rate`) VALUES
-- 普通骑手:按比例拿配送费的70%
(2, 1, '普通骑手', 1, 3,
  2, 0.00, 70.00, 0, 0.00, 0.00, 0.00,
  1, 5.00, 0.00),
-- 资深骑手:按比例拿配送费的80%
(2, 2, '资深骑手', 0, 5,
  2, 0.00, 80.00, 0, 0.00, 0.00, 0.00,
  1, 6.00, 0.00);

-- 深圳骑手等级
INSERT INTO `rider_level` (`city_id`, `level_id`, `name`, `is_default`, `trans_nums`,
  `run_fee_mode`, `run_fix_money`, `run_rate`, `distance_basic`, `distance_basic_money`,
  `distance_more_money`, `distance_max_money`, `work_fee_mode`, `work_fix_money`, `work_rate`) VALUES
(3, 1, '普通骑手', 1, 3,
  2, 0.00, 70.00, 0, 0.00, 0.00, 0.00,
  1, 5.00, 0.00);

-- ============================================================
-- 4. 示例骑手账号
-- 默认密码均为 test1234(MD5: 16d7a4fca7442dda3ad93c9a726597e4)
-- ============================================================
INSERT INTO `rider` (`mobile`, `user_login`, `user_nickname`, `user_pass`, `city_id`, `level_id`,
  `type`, `user_status`, `balance`, `is_rest`, `create_time`) VALUES
('13900000001', 'phone_rider001', '张骑手', '16d7a4fca7442dda3ad93c9a726597e4', 2, 1, 1, 1, 0.00, 0, UNIX_TIMESTAMP()),
('13900000002', 'phone_rider002', '李骑手', '16d7a4fca7442dda3ad93c9a726597e4', 2, 1, 2, 1, 0.00, 0, UNIX_TIMESTAMP());

-- ============================================================
-- 5. 示例商家店铺
-- ============================================================
INSERT INTO `merchant_store` (`name`, `thumb`, `city_id`, `address`, `lng`, `lat`,
  `operating_state`, `automatic_order`, `shipping_type`, `free_shipping`, `up_to_send`,
  `open_date`, `open_time`, `about`, `list_order`, `is_del`, `add_time`) VALUES
('测试餐厅', '', 2, '广州市天河区测试路1号', '113.330010', '23.132891',
  1, 1, 1, 30.00, 15.00,
  '[1,2,3,4,5,6,7]', '["09:00","22:00"]', '测试店铺,仅供开发调试', 1, 0, UNIX_TIMESTAMP());

-- 创建商家账号
INSERT INTO `merchant_users` (`store_id`, `mobile`, `user_nickname`, `user_status`, `type`, `create_time`)
VALUES (LAST_INSERT_ID(), '13700000001', '测试餐厅老板', 1, 1, UNIX_TIMESTAMP());

-- ============================================================
-- 6. 开放平台示例应用
-- ============================================================
INSERT INTO `open_app` (`app_name`, `app_key`, `app_secret`, `store_id`, `status`,
  `webhook_url`, `webhook_events`, `remark`, `create_time`) VALUES
('内部电商系统', 'TESTAPPKEY00001', 'testsecret0000000000000000000000000000000000000000000000000001', 0, 1,
  '', '["order.paid","order.completed","order.cancelled"]', '用于测试的内部应用', UNIX_TIMESTAMP());

-- ============================================================
-- 完成提示
-- ============================================================
SELECT '初始化完成!' AS 提示;
SELECT '骑手登录账号: 13900000001 / 13900000002,密码: test1234' AS 骑手账号;
SELECT '分站管理员: gz_admin / sz_admin,密码: admin123' AS 分站账号;
SELECT '商家手机号: 13700000001' AS 商家账号;
SELECT '开放平台 AppKey: TESTAPPKEY00001' AS 开放平台;

-- ============================================================
-- 7. 超级管理员账号
-- 默认密码:admin123(MD5: 0192023a7bbd73250516f069df18b500)
-- ============================================================
INSERT INTO `admin_user` (`user_login`, `user_pass`, `user_nickname`, `user_status`, `role_id`, `create_time`) VALUES
('admin', '0192023a7bbd73250516f069df18b500', '超级管理员', 1, 1, UNIX_TIMESTAMP());

SELECT '超级管理员: admin / admin123(role=admin)' AS 超管账号;
SELECT '系统管理菜单: /system/menu /system/role-menu /admin-user' AS 系统管理;