how to organize this OBD structure



  • Subject: The user selects the period of use, pays and gets access. The period is closing. My structure of work is as follows:

    CREATE TABLE `users` (
        `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
        `name` VARCHAR(100) NOT NULL COLLATE 'utf8_unicode_ci',
        `email` VARCHAR(100) NOT NULL COLLATE 'utf8_unicode_ci',
        PRIMARY KEY (`id`)
    )
    

    //Таблица периодов пользования, а также сумма за период пользования
    CREATE TABLE settings (
    id INT(11) NOT NULL AUTO_INCREMENT,
    price DECIMAL(10,2) NOT NULL DEFAULT '0.00',
    start DATE NULL DEFAULT NULL, //начальная дата
    end DATE NULL DEFAULT NULL, //конечная дата
    PRIMARY KEY (id)
    )
    //История оплаты за пользования
    CREATE TABLE payments (
    id INT(11) NOT NULL AUTO_INCREMENT,
    suma INT(11) NOT NULL DEFAULT '0',
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    user_id INT(11) UNSIGNED NOT NULL,
    payment_id INT(11) UNSIGNED NOT NULL,
    PRIMARY KEY (id),
    INDEX FK_payments_users (user_id),
    CONSTRAINT FK_payments_users FOREIGN KEY (user_id) REFERENCES users (id)
    )

    How do you check the user ' s access or not?



  • Make 4 tables: (1) Users, (2) Periods, (3) payments to accruals, and (4) interchange to periods. To grant access if the full cost of the period is paid in the 4 table. Well, the period hasn't come up yet.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2