开发者

Reserve amount that will fall back at a specific time if not used

I'm developing an app in Ruby on Rails where companies buy advertising campaigns. First they buy credits to their account on my site, then they buy the campaigns with the credits. The thing is the campaign is payed per view/click. A company reserves a budget of credits for each campaign and these reserved credits can't be used to buy other campaigns with. When a campaign 开发者_开发问答ends and not all credits are used they will be un-reserved and available to buy more campaigns for.

How do I structure the models in the database and how to move/reserve/un-reserve the credits in order to periodically check for any credits that should be un-reserved in a background process?


Have a client/campaigns relationship. Each client has a number of credits. Each client campaign can withdraw credits from the client. As a campaign is viewed/clicked it withdraws credit from the client campaign.

A process periodically checks for lapsed campaigns. When it finds one, any remaining credits are deposited back to the client's main account.


All the money is kept in the company's account all the time. The goal is then to dynamically calculate how much of the funds that are reserved and how much that are not. This can be done if every campaign have a reserved amount attribute and a used amount attribute. When a user clicks on the campaign I withdraw money from the companies account and add them to the campaigns used account.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜