Files
AtomicOld/simpla/OrdersAdmin.php
2026-02-14 19:34:54 +03:00

115 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?PHP
require_once('api/Simpla.php');
########################################
class OrdersAdmin extends Simpla
{
public function fetch()
{
$filter = array();
$filter['page'] = max(1, $this->request->get('page', 'integer'));
$filter['limit'] = 40;
// Поиск
$keyword = $this->request->get('keyword', 'string');
if(!empty($keyword))
{
$filter['keyword'] = $keyword;
$this->design->assign('keyword', $keyword);
}
// Фильтр по метке
$label = $this->orders->get_label($this->request->get('label'));
if(!empty($label))
{
$filter['label'] = $label->id;
$this->design->assign('label', $label);
}
// Обработка действий
if($this->request->method('post'))
{
// Действия с выбранными
$ids = $this->request->post('check');
if(is_array($ids))
switch($this->request->post('action'))
{
case 'delete':
{
foreach($ids as $id)
{
$o = $this->orders->get_order(intval($id));
if($o->status<3)
{
$this->orders->update_order($id, array('status'=>3));
$this->orders->open($id);
}
else
$this->orders->delete_order($id);
}
break;
}
case(preg_match('/^set_label_([0-9]+)/', $this->request->post('action'), $a) ? true : false):
{
$l_id = intval($a[1]);
if($l_id>0)
foreach($ids as $id)
{
$this->orders->add_order_labels($id, $l_id);
}
break;
}
case(preg_match('/^unset_label_([0-9]+)/', $this->request->post('action'), $a) ? true : false):
{
$l_id = intval($a[1]);
if($l_id>0)
foreach($ids as $id)
{
$this->orders->delete_order_labels($id, $l_id);
}
break;
}
}
}
if(empty($keyword))
{
$status = $this->request->get('status', 'integer');
$filter['status'] = $status;
$this->design->assign('status', $status);
}
$orders_count = $this->orders->count_orders($filter);
// Показать все страницы сразу
if($this->request->get('page') == 'all')
$filter['limit'] = $orders_count;
// Отображение
$orders = array();
foreach($this->orders->get_orders($filter) as $o)
$orders[$o->id] = $o;
// Метки заказов
$orders_labels = array();
foreach($this->orders->get_order_labels(array_keys($orders)) as $ol)
$orders[$ol->order_id]->labels[] = $ol;
$this->design->assign('pages_count', ceil($orders_count/$filter['limit']));
$this->design->assign('current_page', $filter['page']);
$this->design->assign('orders_count', $orders_count);
$this->design->assign('orders', $orders);
// Метки заказов
$labels = $this->orders->get_labels();
$this->design->assign('labels', $labels);
return $this->design->fetch('orders.tpl');
}
}