数据库设计:信用充值和交易

发布于 2024-10-02 05:23:33 字数 771 浏览 4 评论 0原文

我们从事的是潜在客户开发业务。客户从我们这里收到线索。他们查看潜在客户的基本信息并决定是否接受或拒绝该潜在客户。如果他们接受潜在客户,则会扣除 1​​ 个积分(针对每个潜在客户),并且他们可以查看潜在客户的详细信息。

因此,每条线索花费 1 个积分(与一定的货币价值挂钩)。

我们有不同类型的客户:保险代理人、房地产经纪人、信用卡公司、俱乐部等。他们为 1 个积分支付不同的价格。

客户可以预付费或后付费。

我对上述所有内容都有下表:

Customers (id, name, address, is_postpaid, customer_type_id)
CustomerTypes (id, name, credit_price) // name: insurance agent, real estate agent, etc
TransactionTypes (id, name) // add to or deduct from credit balance
CustomerTransactions (id, customer_id, quantity, transaction_type_id, credit_balance, credit_unit_price, date_created)

问题:

  • 您对总体方法有何看法?
  • 这种设计适合预付费客户。但是后付费呢?

任何反馈和批评都会受到赞赏。

更新::我已更新上述表格,将 FK 包含在“客户”表格中。

We're in the business of lead generation. Customers receive leads from us. They view basic information about the lead and decide whether to accept the lead or reject. If they accept the lead, they are deducted 1 credit (for each lead) and they can view the detail info of the lead.

So each lead costs 1 credit (which is tied to some monetary value).

We have different type of customers: insurance agents, real estate agents, credit card companies, clubs, etc. They pay different price for 1 credit.

Customers can be prepaid or postpaid.

I have the following tables for all of the above:

Customers (id, name, address, is_postpaid, customer_type_id)
CustomerTypes (id, name, credit_price) // name: insurance agent, real estate agent, etc
TransactionTypes (id, name) // add to or deduct from credit balance
CustomerTransactions (id, customer_id, quantity, transaction_type_id, credit_balance, credit_unit_price, date_created)

Questions:

  • What do you think about the overall approach?
  • This design is OK for prepaid customers. But what about postpaid?

Any feedback and criticism is appreciated.

Update:: I've updated above tables to include the FK in Customers table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

三寸金莲 2024-10-09 05:23:33

如果交易表的粒度确实是一笔交易(无累积字段),则预付费客户和后付费客户之间没有区别。您可以在同一列中输入正数付款和负数借记,或者(正如某些人喜欢的那样)使用两列表示“正数和负数”客户交易。

客户余额始终可以通过以下方式获得:

select
      CustomerName
    , sum(Credits) - sum(Debits) as AccountBalance
from Transactions as t
join Customer     as c  on c.CustomerId = t.CustomerId
group by CustomerName
order by CustomerName ;

If the grain of the transaction table is truly one transaction (no cumulative fields), than there is no difference between pre-paid and post-paid customers. You may enter payments as positive and debits as negative numbers in a same column, or (as some people prefer) use two columns for "positive and negative" customer transactions.

Customer balance can always be obtained by:

select
      CustomerName
    , sum(Credits) - sum(Debits) as AccountBalance
from Transactions as t
join Customer     as c  on c.CustomerId = t.CustomerId
group by CustomerName
order by CustomerName ;
夜夜流光相皎洁 2024-10-09 05:23:33

我会将数据库更改为以下内容:

客户(id、名称、customerType_id、地址、is_postpaid)
客户类型(id、名称、信用价格)
CustomerTransactions(id,customer_id,数量,transaction_type,credit_balance,credit_unit_price,date_created)

我不太确定预付费或后付费的概念。如果可以的话请帮我澄清一下。

I would change the database to the following:

Customers (id, name,customerType_id, address, is_postpaid)
CustomerTypes (id, name, credit_price)
CustomerTransactions (id, customer_id, quantity, transaction_type, credit_balance, credit_unit_price, date_created)

What I am not so sure is about the prepaid or postpaid concept. If you can please clarify it for me.

内心激荡 2024-10-09 05:23:33

我还建议预付款和后付款之间没有区别 - 您只是进行交易。

为了适应前后差异,您可以引入一个新表来描述它:

    customer_type
    --------------
    id    
    pre_or_post
    begin_date
    end_date

i would also suggest that there is no difference between pre and post pay - you just have transactions.

to accomodate the pre-post differences, you could introduce a new table that describes it:

    customer_type
    --------------
    id    
    pre_or_post
    begin_date
    end_date
北凤男飞 2024-10-09 05:23:33

关于信用的一件事是,从会计的角度来看,如果预付的话,它们就是账面上的负债。它们有点像礼品卡,在使用积分之前您无法确认收入。考虑到这一点,您希望积分在一段时间(例如 1 年)后过期。由于积分过期,您需要按从最旧到最新的顺序扣除积分。

您应该有一个表来记录信用使用情况(即 CustomerCreditUsage),另一表用于记录信用购买情况(CustomerTransactions)。购买后,您检查信用余额是否为负,并从信用使用表中注销记录。如果是预付费的,当您记录信用使用交易时,您将从最早的信用购买的信用余额中扣除。

请记住,信用购买和信用使用之间存在松散的关系。您可以只拥有一个而无需另一个。尽管您不希望在没有匹配信用购买的情况下长时间使用信用(后付费)。

One thing about credits is that from an accounting standpoint, they are a liability on the books if prepaid. They are sort of like gift cards, you can't recognize the revenue until the credits are used. With that in mind, you want to have credits expire after a certain length of time, like 1 year. Since credits expire, you then need to deduct credits in order, from oldest to newest.

You should have one table to record credit usage (i.e. CustomerCreditUsage), and another table for credit purchases (CustomerTransactions). Upon purchase, you check for negative credit balance and close out the record(s) from the credit usage table. If prepaid, when you record a credit usage transaction, you deduct from the credit balance of the oldest credit purchase.

Keep in mind that there is a loose relation between credit purchases and credit usage. You can have one without the other. Although you don't want to have a credit usage without a matching credit purchase for too long (post paid).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文