Филиал Аукциона'; const AUC_WIN = 'Вы выиграли торги. Предмет "%s" за %s кр. был добавлен к вам в инвентарь.'; const AUC_SELL = 'Предмет "%s" был продан на торгах, %s кр. за товар отправлены вам по почте.'; const AUC_NOT_SELL = 'Предмет "%s" не был продан, он возвращен вам в инвентарь.'; function sendToChat(string $message, string $to = '', string $from = '') { $sql = 'insert into chat (new, login, `to`, text, time, type) values (1, ?, ?, ?, unix_timestamp(), 6)'; Db::sql($sql, [$from, $to, $message]); } function changeOwner(int $userId, int $itemId) { $sql = 'update items_users set uid = ?, lastUPD = unix_timestamp() where (id = ? or inGroup = ?) and uid = 0'; Db::sql($sql, [$userId, $itemId, $itemId]); } $items = Db::getRow('select * from items_auc where time_end = 0 and time < unix_timestamp() - ? order by user_buy', [TIME_LAST]); foreach ($items as $item) { if ($item['x'] > 0) { $item['name'] .= ' (x' . $item['x'] . ')'; } $userLogin = Db::getValue('select login from users where id = ?', [$item['uid']]); if ($item['user_buy'] && Db::getValue('select count(*) from users where id = ?', [$item['user_buy']])) { changeOwner($item['user_buy'], $item['item_id']); sendToChat(sprintf(AUC_WIN, $item['name'], $item['price']), $item['user_buy'], AUC); if ($userLogin) { sendToChat(sprintf(AUC_SELL, $item['name'], $item['price']), $userLogin, AUC); Db::sql('insert into items_users (`delete`, item_id, 1price, uid, lastUPD, `data`) values (0, 1220, ?, ?, unix_timestamp(), ?)', [$item['price'], '-51' . $item['uid'], '']); } } elseif ($userLogin) { changeOwner($item['uid'], $item['item_id']); sendToChat(sprintf(AUC_NOT_SELL, $item['name']), $userLogin, AUC); } Db::sql('update items_auc set time_end = unix_timestamp() where id = ?', [$item['id']]); }