new version main page

This commit is contained in:
Your Name
2021-05-24 01:13:43 +03:00
parent 2f2c1489a2
commit 766e572752
18 changed files with 434 additions and 108 deletions

View File

@@ -105,7 +105,36 @@ function api_restore_hash($hash){
}
# подписчик или нет
function client_status_sub($client_id, $client_group = 3){
if ($client_group == 1 or $client_group == 2){
return True;
}
$findsub = db_get("SELECT number_id FROM `anbuy` WHERE `client_id` = '$client_id' AND `number_id` = '486' AND `buy_status` = '1' LIMIT 1");
if (isset($findsub['number_id'])){
return True;
}
}
# куплена книжка или нет
function client_status_book($book_id, $client_id){
$book_sql = "SELECT buy_id FROM anbuy WHERE number_id = $book_id AND client_id = $client_id AND buy_status = 1";
$book = db_get($book_sql);
if (isset($book['buy_id'])){
return True;
}
return False;
}

View File

@@ -3,9 +3,19 @@
*
*/
function bookid_kuri($hash) {
function bookid_kuri($slug) {
$query = "SELECT `price_id`, `pricename`, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1";
$query = "
SELECT
`price_id`, `pricename`, `categoryname`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `sub`
FROM
`price`
LEFT JOIN `pricecategory`
ON price.category_id = pricecategory.category_id
WHERE
`priceslug` = '$slug'
LIMIT 1
";
$book = dbl_get($query);
@@ -30,9 +40,9 @@ function bookid_kuri($hash) {
/**
* вернуть товары магазина (все или по фильтру)
*/
function api_books_kuri($category = 'all', $page = 1){
function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){
$limit = 25;
$limit = 24;
if ($page > 1){
$offset = $limit * ($page - 1);
@@ -41,7 +51,7 @@ function api_books_kuri($category = 'all', $page = 1){
else {
$offset_str = '';
}
if ($category == 'all'){
$where = '';
}
@@ -58,9 +68,98 @@ function api_books_kuri($category = 'all', $page = 1){
}
$sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str";
$db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` $where LIMIT 1;");
return db_get($sql_books);
if (isset($db_count['error']))
return False;
if (isset($db_count['count']))
$count = $db_count['count'];
$sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str";
$books = db_get($sql_books);
if (!isset($books['error'])) {
if ($count > $limit){
$pages = ceil($count / $limit);
}
else{
$pages = 1;
}
$result['books'] = $books;
$result['count'] = $count;
$result['pages'] = $pages;
$result['page'] = $page;
}
return $result;
}
/**
все категории
*/
function api_cats(){
$cats = db_get(
"SELECT * FROM pricecategory WHERE visibled = 1"
);
if (isset($cats['error']))
return False;
$result = [];
foreach ($cats as $cat){
$result[$cat['categoryslug']] = $cat;
}
return $result;
}
function book_slug($book){
$return = '';
if ($book['category_id'] == 1){
$name = $book['pricename'];
$start = strpos($name, '(');
$end = strpos($name, ')');
$end = $end -1;
$number = substr($book['pricename'], $start + 1, $end - $start);
$result = "argumenty-nedeli-$number";
}
else {
$result = transliturl($book['pricename']);
}
return $result;
}
function add_book_slug(){
$books = db_get(
"SELECT * FROM price;"
);
foreach ($books as $book){
$slug = book_slug($book);
$sql = "UPDATE `price` SET `priceslug` = '$slug' WHERE price_id = ".$book['price_id'].';';
echo "$sql<br>";
}
}