Witam,
Potrzebuje osoby która mi przerobi plik sklepu by ghost (raczej nie ma z tym dużo roboty).
Chodzi mi aby podczas dodawania nowej usługi, nie było wymagane wypełnianie amxbansa, serwera. Po prostu żebym mógł dodać nową usługę, bez wypełniania serwera i amxbansa.
Tutaj daje kod odpowiadający za to:
/** * Dodaje nową usułgę... * * @param array * * @access static * @return array */ static public function add($data) { if(!Service::allRequired($data)) { return array(0, 'Musisz podać wszystkie pola'); } $query = Core::db()->prepare('INSERT INTO `services_` VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)'); $query->execute(array( $data['name'], $data['desc'], $data['flags'], (float)$data['cost_per_day'], (int)$data['min_day'], (int)$data['max_day'], $data['amxbans_id'], $data['server_id'], $data['allowed_group'], )); if($query->rowCount()) { return array(1, 'Usułga została dodana'); } return array(0, 'Nie udało się dodać usuługi...'); }
A tutaj daję pełny kod:
<?php defined('SYSPATH') or die('No direct script access.'); abstract class Service { /** * Zwraca liste usług * * * @access static * @return array */ static public function getAll() { return Core::db()->query('SELECT * FROM `services_` order by `id` DESC')->fetchAll(); } /** * Usuwa usługe... * * * @access static * @return array */ static public function delete($id) { // Usuwanie odpowiednich flag użytkowniką którzy kupi tą usługę // Zmienianie wygaśnięcia na 0 aby flagi później zostały usunięte... $stmt = Core::db()->prepare('UPDATE `services_buy_cache_` SET `expired` = 0 where `service_id` = ?'); $stmt -> execute(array($id)); // Usuwanie wszystkich flag(tej usługi) użytkowniką którzy kupili tą usługę Service::refreshBuyCache(); // Usuwanie wszystkich rekordów powiązanych z tą usługą $stmt = Core::db()->prepare('DELETE FROM `services_buy_cache_` where `service_id` = ?'); $stmt -> execute(array($id)); // Wykonajmy finalne zapytanie $res = Core::db()->prepare('DELETE FROM `services_` where `id` = ?'); $res -> execute(array($id)); $res = $res->rowCount(); // Zwróćmy wynik return array($res, $res ? 'Usługa jak i wszystki flagi każdego użytkownika z nią powiązane zostały usunięte' : 'Taka usługa już nie istnieje'); } /** * Zwraca wybrną usułgę... * * @param integer * * @access static * @return array */ static public function get($id) { $stmt = Core::db()->prepare('SELECT * FROM `services_` where `id` = ? LIMIT 1'); $stmt->execute(array($id)); return $stmt->fetch(); } /** * Dodaje nową usułgę... * * @param array * * @access static * @return array */ static public function add($data) { if(!Service::allRequired($data)) { return array(0, 'Musisz podać wszystkie pola'); } $query = Core::db()->prepare('INSERT INTO `services_` VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)'); $query->execute(array( $data['name'], $data['desc'], $data['flags'], (float)$data['cost_per_day'], (int)$data['min_day'], (int)$data['max_day'], $data['amxbans_id'], $data['server_id'], $data['allowed_group'], )); if($query->rowCount()) { return array(1, 'Usułga została dodana'); } return array(0, 'Nie udało się dodać usuługi...'); } /** * Edytuje.... * * @param array * * @access static * @return array */ static public function edit($data) { if(!Service::allRequired($data)) { return array(0, 'Musisz podać wszystkie pola'); } $query = Core::db()->prepare( 'UPDATE `services_` SET `name`=?, `desc`=?, `flags`=?, `cost_per_day`=?, `min_day`=?, `max_day`=?, `amxbans_id`=?, `server_id`=?, `allowed_group`=? ' . 'where `id`=?' ); $query->execute(array( $data['name'], $data['desc'], $data['flags'], (float)$data['cost_per_day'], (int)$data['min_day'], (int)$data['max_day'], $data['amxbans_id'], $data['server_id'], $data['allowed_group'], $data['id'] )); if($query->rowCount()) { return array(1, 'Usułga została zmodyfikowana'); } return array(0, 'Prawdopodobnie usuła nie istnieje lub żadne dane nie zostały zmodyfikowane...'); } /** * Zwraca czy wszystkie wymagane pola znajdują się w $data * * @param array * * @access static * @return bool */ static public function allRequired($data) { $required = array( 'name', 'desc', 'flags', 'amxbans_id', 'server_id', 'cost_per_day', 'allowed_group', 'max_day', 'min_day' ); foreach($required as $name) { if(!isset($data[$name]) or empty($data[$name])) { return false; } } return true; } /** * Dodaje usługę do zakupionych, następne kupienie jest równoznaczne z jej przedłużeniem... * + Funkcja dodaje głównie rekord po to żeby po zakończeniu owej usługi zostały usunięte tylko zakupione flagi * * @param integer id użytkownika * @param integer id usługi * @param integer id użytkownika w amxbansie * @param integer na ile dni została kupiona usługa... * * @access static */ static public function insertBuy($member_id, $service_id, $amxbans_member_id, $days) { // Pobierzmy usługę $service = Service::get($service_id); // Zaktualizujmy zarobek usługi $stmt = Core::db()->prepare('UPDATE `services_` SET `full_cash`=`full_cash` + ? where `id` = ?') ->execute(array(round($days*$service['cost_per_day'], 2), $service_id)); $query = 'SELECT * FROM `services_buy_cache_` WHERE `member_id` = ? AND `service_id` = ? AND `amxbans_member_id` = ?'; $stmt = Core::db()->prepare($query); $stmt->execute(array($member_id, $service_id, $amxbans_member_id)); $time = time(); if(!$stmt->rowCount()) { $expired = ($time + (Date::DAY * $days)) - Date::HOUR; $stmt = Core::db()->prepare('INSERT INTO `services_buy_cache_` VALUES(NULL, ?, ?, ?, ?, ?, 1)'); $stmt->execute(array($member_id, $service_id, $amxbans_member_id, $time, $expired)); } else { $fetch = $stmt->fetch(); $current_expired = $fetch['expired']; $expired = ($current_expired < $time ? $time : $current_expired) + (Date::DAY * $days); $status = $expired > $time ? 1 : 0; $stmt = Core::db()->prepare('UPDATE `services_buy_cache_` SET `expired` = ?, `status` = ? where `member_id` = ? AND `service_id` = ? AND `amxbans_member_id` = ?'); $stmt->execute(array($expired, $status, $member_id, $service_id, $amxbans_member_id)); // Naprawa bugu odnośnie nie przedłużania usług w amxbansie, // już przedłuża :) $amxbans = new AmxBans(); $amxbans = $amxbans->connect($amxbans->getAmxBans($service['amxbans_id'])); if($amxbans) { $amxbans->extend($amxbans_member_id, $expired, $service['flags']); } } } /** * Sprawdza czy czas usuługi(wszystkie usługi w bazie danych) już minął czy nie, jeśli tak to usuwa flagi... * Jeśli jest dużo zakupionych usług, może to chwile potrwać, max pare sekund :) * * @access static * @return string */ static public function refreshBuyCache() { $stmt = Core::db()->query('SELECT c.*, s.`amxbans_id`, s.`flags` FROM `services_buy_cache_` c LEFT JOIN `services_` s ON s.`id` = c.`service_id` AND c.`status`=1'); $all = $stmt->fetchAll(); $time = time(); $amxbans_handle = new AmxBans(); $remove = 0; $stmt = Core::db()->prepare('UPDATE `services_buy_cache_` SET `status` = 0 where `member_id` = ? AND `amxbans_member_id` = ? AND `service_id` = ?'); foreach($all as $data) { if(!$data['amxbans_id']) { continue; } $amxbans = $amxbans_handle->getAmxBans($data['amxbans_id']); $amxbans = $amxbans_handle->connect($amxbans); if(!$amxbans) { continue; } if($data['expired'] <= $time) { $amxbans->usunFlagi($data['amxbans_member_id'], $data['flags']); $stmt->execute(array($data['member_id'], $data['amxbans_member_id'], $data['service_id'])); $remove++; } } return $remove; } /** * Update dla buycache * * @param integer * @param string * @param string * * @access static * @return integer */ static public function updateFromBuyCache($id, $key, $value) { $stmt = Core::db()->prepare('UPDATE `services_buy_cache_` SET `'.$key.'` = ? where `id` = ?'); $stmt->execute(array($value, $id)); return $stmt->rowCount(); } /** * Zwraca listę zakupionych usług... * * @access static * @return array */ static public function getFromBuyCache($id = 0) { if($id > 0) { $stmt = Core::db()->prepare('SELECT c.*, s.`name`, s.`amxbans_id`, s.`flags`, s.`min_day`, s.`max_day`, s.`cost_per_day` FROM `services_buy_cache_` c LEFT JOIN `services_` s ON s.`id` = c.`service_id` where c.`id` = ? order by c.`id` DESC'); $stmt->execute(array($id)); return $stmt->fetch(); } else { return Core::db()->query('SELECT c.*, s.`name` FROM `services_buy_cache_` c LEFT JOIN `services_` s ON s.`id` = c.`service_id` order by c.`id` DESC')->fetchAll(); } } /** * Zwraca listę/ilość zakupionych usług przez x użytkownika * * @param integer * @param string * * @access static * @return intger|array */ static public function getMemberFromBuyCache($member_id, $type='list', $active = NULL) { // Przygotujmy odpowiednie zapytanie switch(strtolower($type)) { default: case 'list': $stmt = Core::db()->prepare('SELECT * FROM `services_buy_cache_` where `member_id` = ? order by `id` DESC'); break; case 'count': if($active === NULL) { $stmt = Core::db()->prepare('SELECT COUNT(`id`) AS `count` FROM `services_buy_cache_` where `member_id` = ?'); } else { $stmt = Core::db()->prepare('SELECT COUNT(`id`) AS `count` FROM `services_buy_cache_` where `member_id` = ? AND `status` = 1'); } break; } // Wyślijmy zapytanie $stmt -> execute(array($member_id)); // Jeśli chcemy pobrać ilość if($type == 'count') { // zwróćmy ilość $data = $stmt->fetch(); return $data['count']; } // Zwróćmy wszystki rekordy return $stmt->fetchAll(); } }
Za pomoc daję +