game/cron/comission.php

44 lines
2.5 KiB
PHP

<?php
/** Îïòèìèçèðîâàíî. Íî êàê-òî õåðîâàòî. Íàäî îòêàçàòüñÿ îò âûçîâà $u. È çàïðîñû êàêèå-òî âðàçíîáîé, íàäî ðàçáèðàòüñÿ.
* CRON Êîìèññèîííîãî ìàãàçèíà
* Åñëè ïðåäìåò âèñèò óæå 2 è áîëåå íåäåëü, ïðîäàâàòü ïðåäìåò çà 50% îò åãî ñòîèìîñòè ñ ó÷åòîì èçíîñà.
* Äåíüãè îòñûëàþòñÿ íà ïî÷òó.
* @var PDO $pdo
* @author Insallah
*/
const GAME = true;
const RETURN_GROUP = '"<span style="color: #C65F00;">Shop.capitalcity</span>": Âîçâðàò èç êîìèññèîííîãî ìàãàçèíà ïðåäìåò: [id="%s"/ Íàçâàíèå : "%s"/ Öåíà : "%s"/ Ãðóïåðîâàííî : "$s"].';
const RETURN_ONE = '"<span style="color: #C65F00;">Shop.capitalcity</span>": Âîçâðàò èç êîìèññèîííîãî ìàãàçèíà ïðåäìåò: [id="%s"/ Íàçâàíèå : "%s"/ Öåíà : "%s"].';
const SHOP_TYPE = 'Shop.comission';
setlocale(LC_CTYPE, "ru_RU.CP1251");
include('/home/newcom1/public_html/_incl_data/__config.php');
include('/home/newcom1/public_html/_incl_data/class/__db_connect.php');
$u = User::start();
$q = 'select items_main.id, uid, inGroup, item_id, price1, name from items_users left join items_main on items_main.id = item_id where inShop = 30 and `delete` = 0';
foreach ($pdo->query($q) as $row) {
if ($row['inGroup']) {
$col = $u->itemsX($row['id']);
if ($col > 1) {
$stmt = $pdo->prepare('update items_users set inShop = 0, 1price = ? where item_id = ? and inShop = 30 and uid = ? and inGroup = ? limit ' . $col);
if ($stmt->execute([$row['price1'], $row['item_id'], $row['uid'], $row['inGroup']])) {
$ld = $u->addDelo(1, $row['uid'],
sprintf(RETURN_GROUP, $row['item_id'], $row['name'], $row['price1'], $row['inGroup'] . '+1'),
time(), $u->info['city'], SHOP_TYPE, 0, 0);
}
} else {
$stmt = $pdo->prepare('update items_users set inShop = 0, 1price = ? where uid = ? and id = ? and inOdet = 0 and `delete` = 0 and inShop = 30');
if ($stmt->execute([$row['price1'], $row['uid'], $row['id']])) {
$ld = $u->addDelo(1, $row['uid'], sprintf(RETURN_ONE, $row['item_id'], $row['name'], $row['price1']),
time(), $u->info['city'], SHOP_TYPE, 0, 0);
}
}
} else {
$stmt = $pdo->prepare('update items_users set inShop = 0, 1price = ? where id = ? and inShop = 30');
if ($stmt->execute([$row['price1'], $row['id']])) {
$ld = $u->addDelo(1, $row['uid'], sprintf(RETURN_ONE, $row['item_id'], $row['name'], $row['price1']),
time(), $u->info['city'], SHOP_TYPE, 0, 0);
}
}
}