创建一个带有产品、零售商、制造商、物流中心、仓库、存放、管理、制造、运输作为实体的物流信息管理系统含mysql代码
时间: 2023-10-28 08:05:22 浏览: 144
首先,我们需要创建一个数据库,命名为 "logistics_management_system",并创建以下表格:
1. 产品表格(products):
```
CREATE TABLE products (
product_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(50) NOT NULL,
product_description TEXT,
product_price DOUBLE NOT NULL,
product_manufacturer_id INT(11) NOT NULL,
product_retailer_id INT(11) NOT NULL,
product_stock INT(11) NOT NULL
);
```
2. 制造商表格(manufacturers):
```
CREATE TABLE manufacturers (
manufacturer_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
manufacturer_name VARCHAR(50) NOT NULL,
manufacturer_address VARCHAR(100) NOT NULL,
manufacturer_phone VARCHAR(20) NOT NULL
);
```
3. 零售商表格(retailers):
```
CREATE TABLE retailers (
retailer_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
retailer_name VARCHAR(50) NOT NULL,
retailer_address VARCHAR(100) NOT NULL,
retailer_phone VARCHAR(20) NOT NULL
);
```
4. 物流中心表格(logistics_centers):
```
CREATE TABLE logistics_centers (
logistics_center_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
logistics_center_name VARCHAR(50) NOT NULL,
logistics_center_address VARCHAR(100) NOT NULL,
logistics_center_phone VARCHAR(20) NOT NULL
);
```
5. 仓库表格(warehouses):
```
CREATE TABLE warehouses (
warehouse_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
warehouse_name VARCHAR(50) NOT NULL,
warehouse_address VARCHAR(100) NOT NULL,
warehouse_phone VARCHAR(20) NOT NULL,
warehouse_logistics_center_id INT(11) NOT NULL
);
```
6. 存放表格(storages):
```
CREATE TABLE storages (
storage_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
storage_product_id INT(11) NOT NULL,
storage_warehouse_id INT(11) NOT NULL,
storage_quantity INT(11) NOT NULL,
FOREIGN KEY (storage_product_id) REFERENCES products (product_id),
FOREIGN KEY (storage_warehouse_id) REFERENCES warehouses (warehouse_id)
);
```
7. 管理表格(managements):
```
CREATE TABLE managements (
management_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
management_product_id INT(11) NOT NULL,
management_warehouse_id INT(11) NOT NULL,
management_quantity INT(11) NOT NULL,
management_type VARCHAR(20) NOT NULL,
management_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (management_product_id) REFERENCES products (product_id),
FOREIGN KEY (management_warehouse_id) REFERENCES warehouses (warehouse_id)
);
```
8. 运输表格(transports):
```
CREATE TABLE transports (
transport_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
transport_product_id INT(11) NOT NULL,
transport_origin_warehouse_id INT(11) NOT NULL,
transport_destination_warehouse_id INT(11) NOT NULL,
transport_quantity INT(11) NOT NULL,
transport_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (transport_product_id) REFERENCES products (product_id),
FOREIGN KEY (transport_origin_warehouse_id) REFERENCES warehouses (warehouse_id),
FOREIGN KEY (transport_destination_warehouse_id) REFERENCES warehouses (warehouse_id)
);
```
以上是创建表格的代码,接下来我们可以插入一些测试数据:
1. 插入制造商数据:
```
INSERT INTO manufacturers (manufacturer_name, manufacturer_address, manufacturer_phone) VALUES
('Apple Inc.', '1 Apple Park Way, Cupertino, CA 95014', '+1-408-996-1010'),
('Samsung Electronics Co., Ltd.', '129, Samsung-ro, Maetan 3-dong, Yeongtong-gu, Suwon-si, Gyeonggi-do, Korea', '+82-2-2255-0114');
```
2. 插入零售商数据:
```
INSERT INTO retailers (retailer_name, retailer_address, retailer_phone) VALUES
('Amazon.com, Inc.', '410 Terry Avenue North, Seattle, WA 98109', '+1-206-266-1000'),
('Walmart Inc.', '702 SW 8th St, Bentonville, AR 72716', '+1-479-273-4000');
```
3. 插入物流中心数据:
```
INSERT INTO logistics_centers (logistics_center_name, logistics_center_address, logistics_center_phone) VALUES
('FedEx Ground', '1000 FedEx Drive, Moon Township, PA 15108', '+1-800-463-3339'),
('UPS Supply Chain Solutions', '6201 NW 36th St, Miami, FL 33166', '+1-800-742-5877');
```
4. 插入仓库数据:
```
INSERT INTO warehouses (warehouse_name, warehouse_address, warehouse_phone, warehouse_logistics_center_id) VALUES
('Moon Township Warehouse', '1000 FedEx Drive, Moon Township, PA 15108', '+1-412-787-3640', 1),
('Miami Warehouse', '6201 NW 36th St, Miami, FL 33166', '+1-305-592-1700', 2);
```
5. 插入产品数据:
```
INSERT INTO products (product_name, product_description, product_price, product_manufacturer_id, product_retailer_id, product_stock) VALUES
('iPhone 12 Pro', 'The most powerful iPhone ever', 999.00, 1, 1, 100),
('Galaxy S21 Ultra', 'The ultimate smartphone experience', 1199.99, 2, 2, 100);
```
6. 插入存放数据:
```
INSERT INTO storages (storage_product_id, storage_warehouse_id, storage_quantity) VALUES
(1, 1, 50),
(2, 2, 50);
```
7. 插入管理数据:
```
INSERT INTO managements (management_product_id, management_warehouse_id, management_quantity, management_type) VALUES
(1, 1, 20, 'IN'),
(1, 1, 30, 'IN'),
(2, 2, 20, 'IN'),
(2, 2, 30, 'IN');
```
8. 插入运输数据:
```
INSERT INTO transports (transport_product_id, transport_origin_warehouse_id, transport_destination_warehouse_id, transport_quantity) VALUES
(1, 1, 2, 25),
(2, 2, 1, 25);
```
以上是插入测试数据的代码,你可以根据实际情况自行更改。
最后,我们需要连接数据库并查询一些数据:
```
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "logistics_management_system";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 查询所有产品
$sql = "SELECT * FROM products";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["product_id"]. " - Name: " . $row["product_name"]. " - Description: " . $row["product_description"]. " - Price: $" . $row["product_price"]. "<br>";
}
} else {
echo "没有产品数据";
}
$conn->close();
?>
```
以上代码将查询所有产品并将其打印出来。
希望这个示例对你有所帮助!
阅读全文