refactor
This commit is contained in:
@@ -55,10 +55,10 @@ class ItemsModel
|
||||
* @param int $coldel количество предметов.
|
||||
* @return void
|
||||
*/
|
||||
public static function deleteItemsById(int $id, int $coldel = 1)
|
||||
public static function deleteItemsById(int $id, int $coldel = 1): void
|
||||
{
|
||||
Db::sql(
|
||||
'update items_users set `delete` = unix_timestamp()
|
||||
'delete from items_users
|
||||
where id in (select id from items_users where item_id = ? and uid = ? and (`delete` = 0 or `delete` = 1000) order by inGroup desc limit ?)',
|
||||
[$id, User::start()->info['id'], $coldel]
|
||||
);
|
||||
@@ -78,6 +78,83 @@ class ItemsModel
|
||||
];
|
||||
}
|
||||
|
||||
/** Выбор предмета в инвентаре.
|
||||
* @param int $itemId
|
||||
* @param int $ownerId
|
||||
* @return array
|
||||
*/
|
||||
public static function getOwnedItemById(int $itemId, int $ownerId): array
|
||||
{
|
||||
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id
|
||||
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
|
||||
}
|
||||
|
||||
public static function delete(int $id): void
|
||||
{
|
||||
Db::sql('delete from items_users where id = ?', [$id]);
|
||||
}
|
||||
|
||||
public static function getDressedEkrTotalPrice($uid)
|
||||
{
|
||||
return Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
|
||||
}
|
||||
|
||||
public static function getWearedItems(int $userId): array
|
||||
{
|
||||
return Db::getRows('select * from items_users where inOdet > 0 and uid = ?', [$userId]);
|
||||
}
|
||||
|
||||
/** Порча предмета
|
||||
* @param $it
|
||||
* @param $tp
|
||||
* @param $uid
|
||||
* @param $id2
|
||||
* @param $type
|
||||
* @param $name
|
||||
* @return void
|
||||
*/
|
||||
public static function itemDecay($it, $tp, $uid, $id2, $type, $name): void
|
||||
{
|
||||
if ($it == 0) {
|
||||
return;
|
||||
}
|
||||
if ($id2 == 4708) {
|
||||
$tp = 1;
|
||||
}
|
||||
|
||||
$sql = 'delete from items_users where id = ?';
|
||||
$sql2 = 'update items_users set inGroup = 0, timeOver = unix_timestamp() where inGroup = ?';
|
||||
$args = [$it];
|
||||
if ($uid != 0) {
|
||||
$sql .= 'and uid = ?';
|
||||
$sql2 .= 'and uid = ?';
|
||||
$args[] = $uid;
|
||||
}
|
||||
Db::sql($sql, $args);
|
||||
Db::sql($sql2, $args);
|
||||
|
||||
Delo::add(2, 'system.inventory', $uid, "Предмет <b>$name</b> [id:$it] был испорчен.");
|
||||
|
||||
if ($tp == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Добавляем испорченый предмет в инвентарь, в зависимости от типа
|
||||
|
||||
if ($id2 > 0) {
|
||||
$moddata = '|noodet=1';
|
||||
if ($id2 == 4708) {
|
||||
$moddata = '|notransfer=1|nosale=1';
|
||||
}
|
||||
ItemsModel::addItem($id2, $uid, $moddata);
|
||||
} elseif ($type == 30) {
|
||||
//испорченный эликсир
|
||||
$id2 = 4036;
|
||||
$moddata = "|renameadd=$name|noodet=1";
|
||||
ItemsModel::addItem($id2, $uid, $moddata);
|
||||
}
|
||||
}
|
||||
|
||||
public static function addItem($id, $uid, $md = null, $dn = null, $mxiznos = null, $nosudba = null, $plavka = null)
|
||||
{
|
||||
$user = User::start();
|
||||
@@ -134,30 +211,4 @@ class ItemsModel
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
||||
/** Выбор предмета в инвентаре.
|
||||
* @param int $itemId
|
||||
* @param int $ownerId
|
||||
* @return array
|
||||
*/
|
||||
public static function getOwnedItemById(int $itemId, int $ownerId): array
|
||||
{
|
||||
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id
|
||||
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
|
||||
}
|
||||
|
||||
public static function delete(int $id)
|
||||
{
|
||||
Db::sql('delete from items_users where id = ?', [$id]);
|
||||
}
|
||||
|
||||
public static function getDressedEkrTotalPrice($uid)
|
||||
{
|
||||
return Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
|
||||
}
|
||||
|
||||
public static function getWearedItems(int $userId): array
|
||||
{
|
||||
return Db::getRows('select * from items_users where inOdet > 0 and uid = ?', [$userId]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user