###### tags: `Reports`
# Report 3 (5/20)
[toc]
## E-R diagram 轉成 Relational Table 之 DDL 的形式
```
create table User
(id int NOT NULL AUTO_INCREMENT,
username varchar(20),
password varchar(40) NOT NULL, #encrypted by sha1() hashing function
primary key (id)
) ENGINE=INNODB;
create table Product
(user_id int,
product_id int NOT NULL AUTO_INCREMENT,
name varchar(20),
description TEXT,
category varchar(30)
check (category in
('Antiques', 'Art', 'Books', 'CDs, DVDs, Games', 'Clothing', 'Collectibles', 'Computers',
'Dining', 'Electronics', 'Food & Gourmet Items', 'For Your Pet', 'Golf & Sports Gear',
'Handbags', 'Health & Fitness', 'Home', 'Jewelry', 'Lawn & Garden', 'Memorabilia', 'Other',
'Services', 'Spa & Beauty', 'Tickets-Entertainment', 'Tickets-Sports', 'Toys', 'Travel',
'Unique Experiences', 'Wine'
)),
image varchar(10000), #stores URL
start_time DATE NOT NULL,
end_time DATE NOT NULL,
start_price int check(start_price >= 0),
current_price int DEFAULT -1,
date_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
primary key (product_id),
foreign key (user_id) references User(id)
on delete cascade,
) ENGINE=INNODB;
create table watchlist
(user_id int,
product_id int,
primary key (user_id, product_id),
foreign key (user_id) references User(id)
on delete cascade,
foreign key (product_id) references Product(product_id)
on delete cascade
) ENGINE=INNODB;
create table comments
(user_id int,
product_id int,
comment TEXT,
date_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
primary key (user_id, product_id, date_time),
foreign key (user_id) references User(id) on delete cascade,
foreign key (product_id) references Product(product_id) on delete cascade
) ENGINE=INNODB;
create table winner
(user_id int,
product_id int,
primary key (user_id, product_id),
foreign key (user_id) references User(id)
on delete cascade,
foreign key (product_id) references Product(product_id)
on delete cascade
) ENGINE=INNODB;
BID_FINAL 沒有用到!!!!!!!!!
create table bid_final
(user_id int,
product_id int,
is_notified boolean,
date_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
primary key (user_id, product_id),
foreign key (user_id) references User(id)
on delete cascade,
foreign key (product_id) references Product(product_id)
on delete cascade,
) ENGINE=INNODB;
create table Bid_record
(user_id int,
product_id int,
date_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
bid_price int,
primary key (user_id, product_id, date_time),
foreign key (user_id) references User(id)
on delete cascade,
foreign key (product_id) references Product(product_id)
on delete cascade,
) ENGINE=INNODB;
```
## 系統內容功能詳細敘述
### 管理者:
功能
##### 解決下標糾紛:
* 檢視下標列表
管理者能夠檢視網站近期所以的下標明細,如果有消費糾紛的話,能夠調閱資料維護消費公平性。
* 強制下架商品
管理者發現有違反規定之物品,或是拍賣狀態有異常時,能夠手動下架這些物品,避免發生更多問題。
### 使用者:
主要功能:
* 瀏覽商品
提供使用者瀏覽目前正在進行的競標
* 瀏覽使用者商品
提供使用者瀏覽自己上架的競標,與得標的商品
* 上架商品
提供使用者上架欲拍賣的商品,使用者需填寫商品名稱、商品類別、商品照片、競標開始與結束時間與起標價格等資訊
* 依據商品的類別搜尋
於瀏覽商品頁面能根據不同商品類別搜尋,類別包含
>`Antiques, Art, Books, CDs DVDs Games, Clothing, Collectibles, Computers,
Dining, Electronics, Food & Gourmet Items, For Your Pet, Golf & Sports Gear,
Handbags, Health & Fitness, Home, Jewelry, Lawn & Garden, Memorabilia, Other,
Services, Spa & Beauty, Tickets-Entertainment, Tickets-Sports, Toys, Travel,
Unique Experiences, Wine`
* 於商品頁面競標
在各個商品頁面,設置可以競標的區塊,讓使用者進行競標
附加功能:
* 於商品頁面留言
在商品的頁面下留下你的言論,記錄了問題內容,使用者id及時間。
* 將商品加入或刪除於觀看名單
每個使用者會有自己的觀看名單,而在商品頁會有個按鈕讓使用者可以將此商品加入自己的觀看名單,方便使用者下次查詢
* 瀏覽觀看名單的商品
提供使用者瀏覽自己加入觀看名單的競標,包含正在進行與結束的競標
* 通知小鈴鐺
此小鈴鐺通知使用者,有其他使用者出的價格更高,或是由他人得標,或是競標時間即將結束。
## 系統功能實作規劃
### 流程圖 (許欣平)

### 介面設計 (許哲安)
|編號| 頁面 |
| -------| -------- |
|FE-01| 登入 |
|FE-02| 瀏覽商品 |
|FE-03| 上架商品 |
|FE-04| 競標商品 |
|FE-05| 商品列表 |
|FE-06| 商品下標列表 |
* FE-01
#### 包含登入與創建新帳號
登入Login

創建新帳號CreateNewAccount

* FE-02
Listing

* FE-03
CreateListing

* FE-04
Product

* FE-05
BidListAuction

* FE-06
BidList

### 連結資料庫部份之技術 (林俊誠)
**django + mysql**
django是個用 Python 寫成的,免費而且開放原始碼的 Web 應用程式框架。他是個 Web 框架,可以幫助開發網站。
django會有些固定的檔案結構
manage.py
settings.py
urls.py
wsgi.py
__init__.py
為了連接mysql資料庫,將settings.py中預設
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
```
更改為
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'databaseName',
'USER': 'databaseUser',
'PASSWORD': 'databasePassword',
'HOST': 'localhost',
'PORT': 'portNumber',
}
}
```
| 密鑰 | 內容 |
| -------- | -------- |
| NAME | 此鍵存儲您的 MySQL 數據庫的名稱。 |
| USER | 此密鑰存儲您的 MySQL 帳戶的用戶名,將使用該用戶名連接 MySQL 數據庫。 |
| PASSWORD | 此密鑰存儲該 MySQL 帳戶的密碼。 |
| HOST |此密鑰存儲託管 MySQL 數據庫的 IP 地址。 |
| PORT |此密鑰存儲託管 MySQL 數據庫的端口號。 |
## 預定工作分配
許哲安
* 前端設計
* 瀏覽商品
* 上架商品
* 依據商品的類別搜尋
* 瀏覽觀看名單的商品
許欣平
* 檢視下標列表
* 強制下架商品
* 登入、登出
林俊誠
* 於商品頁面競標
* 於商品頁面留言
* 將商品加入或刪除於觀看名單
* 通知小鈴鐺