game/cron/auction.php

54 lines
2.6 KiB
PHP

<?php
/**
* CRON Êîìèññèîííîãî ìàãàçèíà
* Åñëè ïðåäìåò âèñèò óæå 2 è áîëåå íåäåëü, ïðîäàâàòü ïðåäìåò çà 50% îò åãî ñòîèìîñòè ñ ó÷åòîì èçíîñà.
* Äåíüãè îòñûëàþòñÿ íà ïî÷òó.
*
* Ïðèìåðíî âîò òàê äîëæåí âûãëÿäåòü íîðìàëüíûé êðîí. Ìåíüøå ëåâûõ çàâèñèìîñòåé, íåò ïîäòÿãèâàíèþ ïîëîâèíû äâèæêà.
* Âñ¸ åù¸ íå èäåàëüíî, íî óæå íåïëîõî.
* @author Ivor Barhansky <me@lopar.space>
*/
use Insallah\Db;
const GAME = true;
const TIME_LAST = 86400; // 1 day
const AUC = '<span style="color: #009966;">Ôèëèàë Àóêöèîíà</span>';
const AUC_WIN = 'Âû âûèãðàëè òîðãè. Ïðåäìåò "%s" çà <b>%s êð.</b> áûë äîáàâëåí ê âàì â èíâåíòàðü.';
const AUC_SELL = 'Ïðåäìåò "%s" áûë ïðîäàí íà òîðãàõ, <b>%s</b> êð. çà òîâàð îòïðàâëåíû âàì ïî ïî÷òå.';
const AUC_SELL_LOG = 'Ôèëèàë Àóêöèîíà: Ïðåäìåò "%s" áûë ïðîäàí çà <b>%s êð</b>.';
const AUC_NOT_SELL = 'Ïðåäìåò "%s" íå áûë ïðîäàí, îí âîçâðàùåí âàì â èíâåíòàðü.';
require_once '_incl_data/class/Insallah/Core/Db.php';
$query = [ //all queries
'insert into chat (new, login, `to`, text, time, type) values (1, ?, ?, ?, unix_timestamp(), 6)',
'select * from items_auc where time_end = 0 and time < unix_timestamp() - ? order by user_buy',
'select login from users where id = ?',
'select count(*) from users where id = ?',
'update items_users set uid = ?, lastUPD = unix_timestamp() where (id = ? or inGroup = ?) and uid = 0',
'insert into items_users (`delete`, item_id, 1price, uid, lastUPD, `data`) values (0, 1220, ?, ?, unix_timestamp(), ?)',
'insert into post (uid, sender_id, time, money, text) values (?, 0, unix_timestamp(), ?, ?)',
'update items_auc set time_end = unix_timestamp() where id = ?',
];
$sp = Db::getRow($query[1], [TIME_LAST]);
foreach ($sp as $pl) {
if ($pl['x'] > 0) {
$pl['name'] .= ' (x' . $pl['x'] . ')';
}
$userLogin = Db::getValue($query[2], [$pl['uid']]);
if ($pl['user_buy'] && Db::getValue($query[3], [$pl['user_buy']])) {
Db::sql($query[4], [$pl['user_buy'], $pl['item_id'], $pl['item_id']]);
Db::sql($query[0], [AUC, $pl['user_buy'], sprintf(AUC_WIN, $pl['name'], $pl['price'])]);
if ($userLogin) {
Db::sql($query[0], [AUC, $userLogin, sprintf(AUC_SELL, $pl['name'], $pl['price'])]);
Db::sql($query[5], [$pl['price'], '-51' . $pl['uid'], '']);
Db::sql($query[6], [$pl['uid'], $pl['price'], sprintf(AUC_SELL_LOG, $pl['name'], $pl['price'])]);
}
} elseif ($userLogin) {
Db::sql($query[4], [$pl['uid'], $pl['item_id'], $pl['item_id']]);
Db::sql($query[0], [AUC, $userLogin, sprintf(AUC_NOT_SELL, $pl['name'])]);
}
Db::sql($query[7], [$pl['id']]);
}