# Happ. 選物 Schema 規劃 ## 考慮 - 折扣? - 運費? - 物流? ## Entity - __product__ - __order__ - __order_item__ - __order_invoice*__ - __order_log*__ ## Schema ### products - __id__ - __name__(string) - __desc__(text) - __price__(x) ### product_options - __id__ - __product_id__ - __price__(float) - __option__(string|text) ```json= id, product_id, price, {size: '10x10', color: 'black'} {size: '10x10', color: 'white'} {size: '20x20', color: 'black'} {size: '20x20', color: 'white'} ``` ### product_images - id - option_id - url > 產品的 Schema 先使用 config 來儲存 ```json= products: { id: 1, name: xxx, desc: xxx, product_options:[ { id: 1, price: 1000, option: {}, product_images: [] } ] } ``` ### product_orders - __id__ - __no__(string) - __user_id__ - __shipping_user__(string) - __shipping_address__(string) - __shipping_phone__(string) - __note__(text) - __amount__(float) - __status__(enum){1: 未付款, 2: 付款成功, 3: 付款失敗, 4: 退款} - __timestemp__ ### product_order_items(`product_orders` --N--> `order_items`) - __id__ - __product_order_id__ - __product_id__ - __quanity__(int) - __product_object__(text|json){Product} - __amount__(float) - __timestemp__ ### product_order_logs - __id__ - __send_data__ - __return_data__ - __timestemp__ ### product_order_refund(*是否需要考慮個別商品的退款?) - __id__ - __no__ - __product_order_id__ - __amount__ - __status__ - __timestemp__ ### product_order_refund_logs - __id__ - __product_order_id__ - __send_data__ - __return_data__ - __timestemp__ ### product_order_invoice - __id__ - __product_order_id__ - __invoice_no__ - __buyer_type__ - __buyer_name__ - __buyer_address__ - __buyer_email__ - __category__ - __carrier_type__ - __carrier_num__ - __love_code__ - __company_num__ - __status__ - __timestemp__ ### product_order_invoice_allowances - __id__ - __product_order_id__ - __allowance_no__ - __amount__ - __status__ - __timestemp__ ### product_order_invoice_logs - __id__ - __product_order_id__ - __send_data__ - __return_data__ - __type__ - __amount__ - __status__ - __timestemp__ ### cart (session) - __id__ - __user_id__ - __content__(text|json) ```json= content: [Product1, Product2...] ``` ## Setting ### Option Config Setting ```json= config: { size: ['10x10', '20x20'], color: ['black', 'white'] } ``` ## 前端流程 - 產品列表詳細頁 `action`: 點擊商品跳轉顯示個別產品資訊 - 產品個別頁 `action`: 選擇尺寸各項規格 `action`: 點擊結帳按鈕 - 付款模組畫面 `action`: 輸入付款資訊 `action`: 輸入收貨資訊 `action`: 輸入發票資訊 `action`: 點擊確認付款按鈕 `action`: 跳轉顯示付款完成?訂單列表顯示頁? - 訂單列表顯示頁 `action`: 查看各項訂單資訊 ## 後端流程 - 產品列表 `function`: 抓出所有產品顯示頁面 - 產品個別頁面 `function`: 抓出個別產品的完整資訊 - 結帳流程 1. 接收前端送出資料(包含產品資訊、付款資訊、收貨資訊、發票資訊) 2. 金額試算防呆 3. 建立初始 `product_orders` 資料 4. 建立 `product_order_items` 資料 5. 將訂單與付款資訊送出藍新金流,同時建立 `product_order_logs` 資料 6. 接收藍新回傳結果更改 `product_orders` 狀態,同時將回傳資料寫回 `product_order_logs` 7. 開立發票,撰寫發票 log 8. 回傳購買結果 - 退款流程 // 待確認... - 訂單列表顯示頁 `function`: 抓出個別使用者訂單資料