1

I'm trying to create a carry-forward wallet system.

  • Recharge part
  • I'm developing an app that has the carry forwarding token wallet concept. However, when an user recharge their wallet, an amount of the token will be credited to their wallet with an expiration date (suppose expiration date will be 1 month).
  • If the user recharges their wallet compared to the amount of the new token before the expiration of their current token, it will add to the amount of the old token and extend the expiration date as well.
  • In between that when ever an action performs that related to token deduction,code will check the expiration date before deduct the token.

I've already designed a database structure. Please have a look.

  1. Order Table to manage all token transactions.
token_order
+----+---------+------------+-----------+-----------+----------------+-------------+------------+--------+------------+-------------+
| id | user_id | order_date | sub_total | tax_total | discount_total | grand_total | ip_address | status | created_at | modified_at |
+----+---------+------------+-----------+-----------+----------------+-------------+------------+--------+------------+-------------+
| 1  | 20      | 2020-04-20 | 1000      | 100       | null           | 1100        | 127.0.0.1  | 1      | 2020-04-20 | 2020-04-20  |
+----+---------+------------+-----------+-----------+----------------+-------------+------------+--------+------------+-------------+
  1. Token_order and token_order_details are linked to fetch order information.
token_order_details
+----+----------------+-------------+-----------+------------+----------------+-----------------+---------------+-------------+--------+------------+-------------+
| id | token_order_id | token_price | token_qty | tax_amount | tax_percentage | discount_amount | purchase_date | expiry_date | status | created_at | modified_at |
+----+----------------+-------------+-----------+------------+----------------+-----------------+---------------+-------------+--------+------------+-------------+
| 2  | 1              | 10          | 100       | 100        | 10             | null            | 2020-04-20    | 2020-05-20  | 1      | 2020-04-20 | 2020-04-20  |
+----+----------------+-------------+-----------+------------+----------------+-----------------+---------------+-------------+--------+------------+-------------+
  1. This table connects the wallet with respective user.
token_wallet_details
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+
| id | wallet_id | action_id | token_qty | transaction_description | ip_address | transaction_status | created_at | modified_at |
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+
| 1  | 1         | 1         | 1.5       | dummy description       | 127.0.0.1  | success            | 2020-04-20 | 2020-04-20  |
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+
  1. This table holds the token deduction details.
token_wallet_details
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+
| id | wallet_id | action_id | token_qty | transaction_description | ip_address | transaction_status | created_at | modified_at |
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+
| 1  | 1         | 1         | 1.5       | dummy description       | 127.0.0.1  | success            | 2020-04-20 | 2020-04-20  |
+----+-----------+-----------+-----------+-------------------------+------------+--------------------+------------+-------------+

Am I going to the right direction with this tables and their fields to handle these things mentioned above?

1
  • When you have mysql workbench, you can choose Database--> reverse Enggenering there you get an ER diagram that shows you how your tables relate. but i thinkl a user table that can have at least one wallet (eventually two persons can have also one wallet) and order has only to be connected to a wallt, aou can get from wallt the user. the you have a actions which connect one wallt to 2 possible action increae and decrease, two aren't needed at all. as you see information should one be stored once...
    – nbk
    Apr 21, 2020 at 23:35

0