如何在MySQL中创建拆分账单的数据库结构?

如何在MySQL中创建拆分账单的数据库结构?,mysql,sql,Mysql,Sql,我有一个事务表,其结构如下: | transaction_id | customer_id | amount | transaction_type_id | status | transaction_id => is the id of the transaction customer_id => is the customer id who did the transaction amount => Total transaction amount transaction_t

我有一个事务表,其结构如下:

| transaction_id | customer_id | amount | transaction_type_id | status |
transaction_id => is the id of the transaction
customer_id => is the customer id who did the transaction
amount => Total transaction amount
transaction_type_id => Type of transaction 
status => status of the transaction => pending, complete, canceled
split_bill
split_bill_id|transaction_ids | initiator | total_amount
split_bill_id => id of the split bill
transaction_ids => All the customer transaction id separated by comma
initiator => the customer_id who initiate split bill
total_amount => total of the bill

split_bill_request
split_bill_request_id | split_bill_id | customer_id | status
split_bill_request_id => id of split bill request
split_bill_id => id of the split bill
customer_id => id of the customer who receive split bill request from initiator
status => status of the request pending,accept,reject
我想为我的程序创建拆分账单功能,该功能的工作原理如下:

| transaction_id | customer_id | amount | transaction_type_id | status |
transaction_id => is the id of the transaction
customer_id => is the customer id who did the transaction
amount => Total transaction amount
transaction_type_id => Type of transaction 
status => status of the transaction => pending, complete, canceled
split_bill
split_bill_id|transaction_ids | initiator | total_amount
split_bill_id => id of the split bill
transaction_ids => All the customer transaction id separated by comma
initiator => the customer_id who initiate split bill
total_amount => total of the bill

split_bill_request
split_bill_request_id | split_bill_id | customer_id | status
split_bill_request_id => id of split bill request
split_bill_id => id of the split bill
customer_id => id of the customer who receive split bill request from initiator
status => status of the request pending,accept,reject
  • 客户输入要拆分的账单的总金额
  • 客户添加另一个客户(n个客户)以拆分账单,并指定金额
  • 将为状态为“待定”且指定金额的拆分账单中的所有客户进行交易
  • 其他客户将收到拆分账单请求,以拒绝或接受拆分账单
  • 如果其中一个客户拒绝拆分票据请求,则交易将被取消,但如果所有客户都接受该请求,则交易状态将为“完成”
  • 到目前为止,我已经找到了解决方案,通过创建主拆分账单表和拆分账单请求,如下所示:

    | transaction_id | customer_id | amount | transaction_type_id | status |
    transaction_id => is the id of the transaction
    customer_id => is the customer id who did the transaction
    amount => Total transaction amount
    transaction_type_id => Type of transaction 
    status => status of the transaction => pending, complete, canceled
    
    split_bill
    split_bill_id|transaction_ids | initiator | total_amount
    split_bill_id => id of the split bill
    transaction_ids => All the customer transaction id separated by comma
    initiator => the customer_id who initiate split bill
    total_amount => total of the bill
    
    split_bill_request
    split_bill_request_id | split_bill_id | customer_id | status
    split_bill_request_id => id of split bill request
    split_bill_id => id of the split bill
    customer_id => id of the customer who receive split bill request from initiator
    status => status of the request pending,accept,reject
    

    我不知道这是否是正确的方法,您能建议另一种方法吗,因为我对拆分账单表中的交易ID或执行此操作的有效方法有疑问,并且因为我没有修改交易表的权限?

    这个问题很主观,所有与设计相关的问题也是如此。在事务ID字段上有一些值得思考的地方:它们只是“请求”,因为它们是“挂起的”。但实际上,您不会将它们移动到某个单独的表中,因此我认为将它们存储为“请求”是没有帮助的。它们只是“拆分”,尽管未经确认。哦,“事务ID”的想法很糟糕!