Hello. There is a site that stores virtual finance for the site and a system of enrollment, withdrawal, transfer between users, etc. Closer to the topic, one person could somehow withdraw the amount two times the same, the whole thing happened at once , the date of the two transactions is the same, the amount of the first transaction is the total cost of its finance on the site, and the second one turns out the transaction that was created it should not have been created since the amount on the account is 0. All protection against F5 and the like are present. Question: how was it done?
The solution, as I understand it, lies in mysql transactions, and how to use it, I understand something, I’m more interested in how this can be done to understand more.
Here is a piece of code that is responsible for creating the application:
$paySys = Paymsys::findByName($this->tasys_in, $this->amount_in)->setPersent(true); if ($paySys->sysAbbr == null) { Yii::$app->session->setFlash('error', "<div class=\"alert alert-danger text-center\">Направильное имя системы</div>"); return false; } $this->amount_in_origin = $paySys->sum; $this->tasys_in = $paySys->sys; $this->user_real_sum = UserMoney::getSum($paySys->sysAbbr); $money = OperationsMoney::start($paySys)->moneyDeduct(); if (!$money->save()) { Yii::$app->session->setFlash('alert', $money->getError() . " " . $money->getSum() . ' ' . $paySys->sysAbbr); return false; } The date is stored in the usual format. 2016-08-22 00:21:51