Файл: app/shop/history.php
Строк: 72
<?php
if (!$user->isAuth()) {
redirect('/');
exit;
}
$id = abs(intval($_GET['id']));
$shop = $db->prepare('SELECT * FROM `shop` WHERE `id` = ? and `user` = ?');
$shop -> execute([$id,$user->get()->user_id]);
$shop = $shop -> fetch(PDO :: FETCH_ASSOC);
if(!isset($shop['id'])){
header('Location: /');
exit;
}
$status = 0;
if(isset($_GET['pay'])) $status = 2;
$all = $db->prepare('SELECT * FROM `payments` WHERE `shop` = ? and `status` >= ? ORDER BY `id` DESC');
$all -> execute([$shop['id'],$status]);
$all = $all -> fetchAll();
$peger = new ArrayPaginator('/shop/history?id='.$shop['id'],20);
$items = $peger->getItems($all);
$method = [
'Не выбран',
'qiwi'=>'QIWI Wallet',
'yandex'=>'Яндекс Деньги',
'mobile'=>'Со счета мобильного',
'card'=>'VISA/MasterCard/Мир',
'balans'=>'С баланса USPAY.RU',
'payeer'=>'Payeer',
'bitcoin'=>'Bitcoin',
'litecoin'=>'Litecoin',
'dash'=>'DASH',
'vkpay'=>'VK Pay'
];
$status = ['Не оплачен','Не оплачен','В обработке','Оплачен'];
$month = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `month` = ? and `shop` = ?');
$month -> execute([0,3,date('n'),$shop['id']]);
$month = $month ->fetch(PDO :: FETCH_ASSOC);
$month_last = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `month` = ? and `shop` = ?');
$month_last -> execute([0,3,date('n',time()-86400*30),$shop['id']]);
$month_last = $month_last ->fetch(PDO :: FETCH_ASSOC);
$year = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `time` > ? and `shop` = ?');
$year -> execute([0,3,time()-86400*365,$shop['id']]);
$year = $year ->fetch(PDO :: FETCH_ASSOC);
if(empty($month['sum'])) $month['sum'] = 0;
if(empty($month_last['sum'])) $month_last['sum'] = 0;
$pay_count = $db->prepare('SELECT * FROM `payments` WHERE `shop` = ? ORDER BY `id` DESC');
$pay_count -> execute([$shop['id']]);
$pay_count = $pay_count -> rowCount();
$array = ['','Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'];
function sum_pay($date,$shop){
global $db;
$amount = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `date` = ? and `shop` = ?');
$amount -> execute([0,3,$date,$shop]);
$amount = $amount ->fetch(PDO :: FETCH_ASSOC);
if(empty($amount['sum'])) $amount['sum'] = 0;
return $amount['sum'];
}
function desc_pay($desc){
if(empty($desc)) $desc = 'Отсутствует';
return $desc;
}
echo $template->render('shop.history',
['peger' => $peger,
'items' => $items,
'method' => $method,
'year' => $year,
'status' => $status,
'pay_all' => $pay_all,
'pay_count' => $pay_count,
'month' => $month['sum'],
'month_last' => $month_last['sum'],
'array' => $array,
'shop' => $shop
]
);