Hello! My hands got to my long-suffering protracted panel.

It is necessary to resolve the issue of withdrawing money from customers using the services of my panel.

I imagine it so. There is a user, and there is a users table, in which, among other user fields (name, nickname, email, etc.), there is a balance DECIMAL field (12.2). In fact, the value of this field is displayed on the site wherever it is needed (navigation bar, for example). I suppose that the user id is also the account of this user at the same time, and the state of the account is recorded in the balance field.

Every time a user deposits money into an account, or a billing mechanism is triggered, which runs once a day and charges services consumed, the balance field is recalculated (well, just in case). How do you think this is the right approach?

When a user wants to replenish his balance, which document is created, an invoice, or an order? And when do I want to charge the user’s services ?. Do I need to create the payment entity and link it to the documents being created?

A user can simultaneously be ordered several services (services), the cost of each is calculated at the time of ordering services, and is written in the services table in the cost field. Services can be paid only using funds on the account, i.e., one cannot order a service, or use an already ordered service with 0 or a negative balance.

I apologize for the confusion. Ask your requests. I created this topic to try to figure it out myself, because I got confused: (

  • Keep a history of all transactions. it is more convenient when it is a single table that can refer to different types of documents (payments, replenishments). balance can be updated for convenience with changes in history. - Yura Ivanov

1 answer 1

On the coupon site, I made a table of orders.

The client creates an order for the purchase of goods, or to replenish their balance. The order has an amount to be paid, status (new, paid, waiting for payment, etc.) and other attributes.

Created order must be paid. You can go to the payment system, you can pay from the user's balance, if there is enough money.

The user has a "balance" - this is the money in his account. They can be spent on payment for goods. It is updated at the time of confirmation from the payment system of an order to replenish the balance (+), or at the time of payment from the balance of purchase of goods (-).

So two tables: users-with-balance, and orders with the sum, user_id and status.

  • Do you actually have orders (orders)? - nolka
  • Orders of different types: * goods * balance replenishment to pay later on them * bonus promotions - free, without payment * there were some other features - Sergiks