dsewbh5588 2011-07-15 12:37
浏览 28
已采纳

如何从电子商务应用程序中设计收入表?

I'm actually worried about designing the perfect tables to handle transactions and commissions. especially that we really don't want tables to be out of sync in any case.

Basically this is like ebay, where merchants sell to buyers and we get a commission out of each transaction.

The app is already built using Codeigniter, and it has:

Merchants(id,name,balance)
Transactions(id,merchant_id,buyer_id,amount,transaction_id)

Now what other tables to make if needed to make us able to fetch our revenue and the seller's revenue, and what's the best DB mechanism to process a refund?

And should we make another table of each deposit to the merchant's balance rather than +x the balance row.

  • 写回答

2条回答 默认 最新

  • dqb78642 2011-07-15 16:54
    关注

    Whenever you are dealing with any financial tasks, always store as much information about it as possible.

    There are two ways of keeping all your tables in sync.

    • Database level - using options such as stored procedures and triggers

    • Application level - Use transactions (innoDB) and make sure that the transactions are atomic. (I would suggest to go with this)

    Regarding the database design -

    Add a column commission to Transactions that tracks your commission. Data for this can be either calculate beforehand when pricing the item or on the fly during the transaction.

    The buyer pays product cost + commission, seller gets product cost and you get commission. If your commission is a variable (not a flat rate and changes from item to item), you could have a column in the Items table which stores it. Things should be trivial from now on. You just have to maintain a History table that keeps a list of transactions with respect to the user. It would look something like

    AccountHistory(id, transaction_type, transaction_id, amount)
    

    You could split AccountHistory into two - one for incoming money and one for outgoing money.

    So everytime a transaction takes place the following happens

    1. Entry into to Transactions table.
    2. Entry into AccountHistory for buyer
    3. Update buyer balance
    4. Entry into AccountHistory for seller
    5. Update seller balance

    All this should be atomic.

    For rollbacks, you could add a column transaction_type to distinguish rollbacks from normal transaction or you could maintain a separate table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程