Files
anpdf/app/routes/client.php

183 lines
4.4 KiB
PHP
Raw Normal View History

2020-04-26 19:54:50 +03:00
<?php
2020-05-08 13:22:22 +03:00
function addclient(){
2020-04-26 19:54:50 +03:00
$buys = db_get("SELECT `buy_id`, `buy_email`, `date_start` FROM `anbuy`");
foreach($buys as $buy){
if ($buy['date_start'] == '0000-00-00 00:00:00')
$clientdate = date('Y-m-d G:i:s');
else
$clientdate = $buy['date_start'];
$clientmail = strtolower(trim($buy['buy_email']));
$clienthash = md5($clientmail);
$client = db_get("SELECT `client_id`, `clientcard`, `clientdate` FROM `clients` WHERE `clientmail` = '$clientmail' LIMIT 1");
if (isset($client['client_id'])){
if ($client['clientdate'] == '0000-00-00 00:00:00'){
$updsql = "UPDATE `clients` SET `clientdate` = '$clientdate' WHERE `client_id` = '{$client['client_id']}'";
db_get($updsql, 'writer');
echo "$updsql \n";
}
if ($client['clienthash'] == '' ){
$updsql = "UPDATE `clients` SET `clienthash` = '$clienthash' WHERE `client_id` = '{$client['client_id']}'";
db_get($updsql, 'writer');
echo "$updsql \n";
}
2020-04-26 21:40:56 +03:00
if ($buy['client_id'] == 0){
$client_id = $buy['client_id'];
$updsql = "UPDATE `clients` SET `client_id` = '$clienthash' WHERE `client_id` = '{$client['client_id']}'";
}
2020-04-26 19:54:50 +03:00
}
else {
$inssql = "INSERT INTO `clients` (clientmail, clientdate, clienthash) VALUES ('$clientmail', '$clientdate', '$clienthash')";
db_get($inssql, 'writer');
echo "$inssql \n";
}
}
}
2020-05-08 13:22:22 +03:00
function addclientid(){
2020-04-26 21:40:56 +03:00
$buys = db_get("SELECT `buy_id`, `buy_email` FROM `anbuy` WHERE `client_id` = 0");
foreach ($buys as $buy){
$clientmail = strtolower(trim($buy['buy_email']));
$client = db_get("SELECT `client_id` FROM `clients` WHERE `clientmail` = '$clientmail' LIMIT 1");
if (isset($client['client_id'])){
$updsql = "UPDATE `anbuy` SET `client_id` = '{$client['client_id']}' WHERE `buy_id` = '{$buy['buy_id']}'";
echo "$updsql\n";
db_get($updsql);
}
}
}
2020-04-26 19:54:50 +03:00
// номер клубной карты
function addcard($id, $date) {
$year = substr($date, 0, 4);
$number = str_pad($id, 9, '0', STR_PAD_LEFT);
return "$year$number";
2020-04-26 21:40:56 +03:00
}
2020-04-28 18:41:37 +03:00
2020-05-16 14:53:38 +03:00
function mybooks_kuri($category = 'gazeta', $filter = 'all', $page = 1){
2020-04-28 18:41:37 +03:00
2020-05-18 18:07:43 +03:00
echo 'функция:'.__FUNCTION__;
2020-05-12 21:15:26 +03:00
$login = check_login_kuri();
2020-05-12 22:56:44 +03:00
if (!isset($login['client_id'])){
header('Location: '.SITE.'login');
exit;
2020-05-12 21:15:26 +03:00
}
2020-05-16 14:53:38 +03:00
if ($category == 'gazeta')
$category_id = 1;
elseif ($category == 'books')
$category_id = 3;
2020-05-12 21:15:26 +03:00
2020-05-08 13:22:22 +03:00
$limit = 25;
2020-05-13 00:23:18 +03:00
$client = api_client_kuri($login['clienthash']);
2020-05-16 14:53:38 +03:00
$baseurl = SITE.'mybooks/'.$category.'/'.$filter.'/';
2020-04-28 18:41:37 +03:00
if (!$client) {
echo 'Пользователь не найден';
return;
}
2020-05-13 00:23:18 +03:00
2020-05-16 14:53:38 +03:00
$items = clientbuys_kuri($client['client_id'], $page, $category_id, $client['clientgroup_id'], $filter);
2020-05-08 13:22:22 +03:00
$count = $items['count'];
2020-05-03 09:56:52 +03:00
2020-05-08 13:22:22 +03:00
if ($count > $limit){
$pages = ceil($count / $limit);
2020-05-03 09:56:52 +03:00
}
2020-05-08 13:22:22 +03:00
if ($page > 1) {
$title = "Моя библиотека - страница $page";
$prevpage = $page - 1 ;
$prevurl = $baseurl.$prevpage;
}
2020-05-03 09:56:52 +03:00
else {
2020-05-08 13:22:22 +03:00
$title = "Моя библиотека";
}
2020-04-28 18:41:37 +03:00
2020-05-08 13:22:22 +03:00
if ($pages > $page){
$nextpage = $page + 1;
$nexturl = $baseurl.$nextpage;
$endurl = $baseurl.$pages;
}
$tempcontent = VIEWPATH.'allbooks.phtml';
include VIEWPATH.'layout.phtml';
2020-04-29 15:01:25 +03:00
2020-04-28 18:41:37 +03:00
}
2020-04-29 15:01:25 +03:00
2020-05-16 02:30:13 +03:00
//все покупки
2020-05-16 09:44:46 +03:00
function payments_kuri($filter = 1 ){
2020-05-16 02:30:13 +03:00
$login = check_login_kuri();
if (!isset($login['client_id'])){
header('Location: '.SITE.'login');
exit;
}
$paysql = "
SELECT
2020-05-16 12:14:37 +03:00
buy_id, date, anbuy.price AS price, buy_status, pricename, category_id, pricehash
2020-05-16 02:30:13 +03:00
FROM
anbuy
LEFT JOIN price ON
anbuy.number_id = price.price_id
WHERE
2020-05-16 09:44:46 +03:00
client_id = {$login['client_id']}
AND
buy_status = $filter
2020-05-16 02:30:13 +03:00
ORDER BY
buy_id DESC
";
$payments = db_get($paysql);
$title = 'Мои покупки';
$tempcontent = VIEWPATH.'payments.phtml';
include VIEWPATH.'layout.phtml';
}