Файл: app/admin/payments.php
Строк: 84
<?php
if (!$user->isAuth() or $user->get()->role < 1) {
redirect('/');
exit;
}
$method = [
'Не выбран',
'qiwi'=>'QIWI Wallet',
'yandex'=>'Яндекс Деньги',
'mobile'=>'Со счета мобильного',
'card'=>'VISA/MasterCard/Мир',
'balans'=>'С баланса USPAY.RU',
'payeer'=>'Payeer',
'bitcoin'=>'Bitcoin',
'litecoin'=>'Litecoin',
'dash'=>'DASH',
'vkpay'=>'VK Pay'
];
if(isset($_GET['pay'])){
$pay = $db->prepare('select * from `payments` where `id` = ? and `status` < ?');
$pay -> execute([Clean :: int($_GET['pay']),2]);
$pay = $pay -> fetch(PDO :: FETCH_ASSOC);
if(!isset($pay['id'])){
Notif :: error('Платеж не найден','/admin/payments');
exit;
}
$shop = $db->prepare('select * from `shop` where `id` = ?');
$shop -> execute([$pay['shop']]);
$shop = $shop -> fetch(PDO :: FETCH_ASSOC);
$method = $db->prepare('SELECT `mobile` FROM `method` WHERE `id` = ?');
$method -> execute([1]);
$method = $method -> fetch(PDO :: FETCH_ASSOC);
$pr = $method['mobile']/100;
if($shop['method'] == 2) $pay['summa'] = $pay['summa']-$pay['summa']*$pr;
$money = $db->prepare('update `shop` set `money` = `money` + ? where `id` = ?');
$money -> execute([$pay['summa'],$pay['shop']]);
$up = $db->prepare('UPDATE `payments` SET `status` = ? WHERE `id` = ?');
$up -> execute([2,$pay['id']]);
notifSend($shop['user'],
'Новая оплата на кассе «'.$shop['name'].'» '.PHP_EOL.'
Сумма: '.$pay['summa'].' RUB '.PHP_EOL.'
Способ оплаты: '.$method[$pay['method']].' '.PHP_EOL.'
Дата: '.date('d.m.Y H:i'));
Notif :: message('Платеж успешно зачислен','/admin/payments');
exit;
}
$all = $db->prepare('SELECT * FROM `payments` ORDER BY `id` DESC');
$all -> execute();
$all = $all -> fetchAll();
$peger = new ArrayPaginator('/admin/payments',20);
$items = $peger->getItems($all);
$status = ['Не оплачен','Не оплачен','В обработке','Оплачен'];
$month = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `month` = ?');
$month -> execute([0,3,date('n')]);
$month = $month ->fetch(PDO :: FETCH_ASSOC);
$month_last = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `month` = ?');
$month_last -> execute([0,3,date('n',time()-86400*30)]);
$month_last = $month_last ->fetch(PDO :: FETCH_ASSOC);
$year = $db->prepare('SELECT SUM(`summa`) as sum FROM `payments` WHERE `test` = ? and `status` = ? and `time` > ?');
$year -> execute([0,3,time()-86400*365]);
$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` ORDER BY `id` DESC');
$pay_count -> execute();
$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` = ?');
$amount -> execute([0,3,$date]);
$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('admin.payments',
['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
]
);