А
Size: a a a
🎱
А
🎱
А
IS
А
А
🎱
А
🎱
А
А
А
config/web.php
'components' => [
'urlManager' => [
//некоторые параметры
'rules' => [
'profile_15' => 'admin/controller/action',
]
]
],
'modules' => [
'admin' => [
'class' => module\admin\Module::class,
'layout' => 'main',//тут можно свои CSS,JS и т.д. будет независимым от других щаблонов
],
]
,Д
🎱
Д
Д
TS
class TradeMontlyReport extends BaseReport
{
protected function itemsQuery($data){
$query = static::
find()
->select([
"cc.catalog_id as catalog_id",
"c.id as buyer_id",
"p.id AS product_id",
"date_trunc('day', s.created) as date",
"CASE WHEN p.id IS NOT NULL THEN
jsonb_build_object('id', p.id, 'type_id', p.type_id, 'options',p.options)
END AS product",
"CASE WHEN c.id IS NOT NULL THEN
jsonb_build_object('id', c.id, 'options',c.options)
END AS buyer",
"CASE WHEN cc.catalog_id IS NOT NULL THEN
jsonb_build_object('id', cc.catalog_id, 'name', cat.name, 'options', cat.options)
END AS catalog",
"COALESCE(jsonb_agg(DISTINCT p.id), '[]') as products",
"COALESCE(jsonb_agg(DISTINCT c.id), '[]') as buyers",
"COALESCE(jsonb_agg(DISTINCT cc.catalog_id), '[]') as catalogs",
"count(DISTINCT si.id) as itemCnt",
"count(DISTINCT s.id) as saleCnt",
"count(DISTINCT p.id) as productCnt",
"count(DISTINCT c.id) as buyerCnt",
"count(DISTINCT cc.catalog_id) as catalogCnt",
"count(DISTINCT date_trunc('day', s.created)) as dayCnt",
"common.sum_distinct(
CAST((si.price #>> '{value}') AS numeric) *
CAST((si.quantity #>> '{value}') AS numeric) *
CASE WHEN CAST(si.options #>> '{deliveries}' AS numeric) > 0
THEN CAST(si.options #>> '{deliveries}' AS numeric)
ELSE 1
END,
si.id) sum",
"grouping(date_trunc('day', s.created), catalog_id, p.id, c.id) as grouping",
])
->from('sale_item AS si')
->leftJoin('sale AS s', 's.id=si.sale_id AND s.status_id >= 32 AND s.status_id < 255')
->leftJoin('client AS c', 'c.id=s.buyer_id')
->leftJoin('product AS p', 'p.id=si.product_id')
->leftJoin('product_category_mapping AS pcm', 'pcm.product_id=p.id AND pcm.disabled=false')
->leftJoin('catalog_category AS cc', 'cc.id=pcm.category_id')
->leftJoin('catalog as cat', 'cat.id=cc.catalog_id')
->where(['IS NOT', 's.id', null,])
->andWhere(['s.deleted' => false,])
->andWhere(['si.deleted' => false])
->andWhere(['BETWEEN', 'si.created', $this->report->options['from'], $this->report->options['to']])
->groupBy('GROUPING SETS (
(),
(date),
({{c}}.[[id]], {{c}}.[[options]]),
({{p}}.[[id]], {{p}}.[[type_id]], {{p}}.[[options]]),
(catalog_id, {{cat}}.[[name]], {{cat}}.[[options]])
)');
return $query;
}
TS
public function getData($data)
{
$query = static::
find()
->select([
new Expression("'".Report::
TYPE_TRADE_MONTLY."' AS type"),
new Expression("'".$this->report->options['from']."' AS from"),
new Expression("'".$this->report->options['to']."' AS to"),
"jsonb_build_object(
'total', MAX(sum) FILTER ( WHERE grouping = 15 ),
'days', MAX(\"dayCnt\") FILTER ( WHERE grouping = 15 ),
'items', MAX(\"itemCnt\") FILTER ( WHERE grouping = 15 ),
'sales', MAX(\"saleCnt\") FILTER ( WHERE grouping = 15 ),
'products', MAX(\"productCnt\") FILTER ( WHERE grouping = 15 ),
'buyers', MAX(\"buyerCnt\") FILTER ( WHERE grouping = 15 ),
'catalogs', MAX(\"catalogCnt\") FILTER ( WHERE grouping = 15 )
) as summary",
"jsonb_agg(jsonb_build_object(
'date', date,
'total', sum,
'itemCnt', \"itemCnt\",
'saleCnt', \"saleCnt\",
'productCnt', \"productCnt\",
'products', products,
'buyerCnt', \"buyerCnt\",
'buyers', buyers,
'catalogCnt', \"catalogCnt\",
'catalogs', catalogs
) ORDER BY date) FILTER ( WHERE grouping = 7) AS days",
"jsonb_agg(jsonb_build_object(
'catalog', catalog,
'total', sum,
'dayCnt', \"dayCnt\",
'itemCnt', \"itemCnt\",
'saleCnt', \"saleCnt\",
'productCnt', \"productCnt\",
'products', products,
'buyerCnt', \"buyerCnt\",
'buyers', buyers
) ORDER BY sum DESC, catalog_id) FILTER ( WHERE grouping = 11) AS catalogs",
"jsonb_agg(jsonb_build_object(
'product', product,
'total', sum,
'dayCnt', \"dayCnt\",
'itemCnt', \"itemCnt\",
'saleCnt', \"saleCnt\",
'buyerCnt', \"buyerCnt\",
'buyers', buyers,
'catalogCnt', \"catalogCnt\",
'catalogs', catalogs
) ORDER BY sum DESC, product_id) FILTER ( WHERE grouping = 13) AS products",
"jsonb_agg(jsonb_build_object(
'buyer', buyer,
'total', sum,
'dayCnt', \"dayCnt\",
'itemCnt', \"itemCnt\",
'saleCnt', \"saleCnt\",
'productCnt', \"productCnt\",
'products', products,
'catalogCnt', \"catalogCnt\",
'catalogs', catalogs
) ORDER BY sum DESC, buyer_id) FILTER ( WHERE grouping = 14) AS buyers",
])->from(['t' => static::
itemsQuery($data)]);
return $this->asJson($query);
}
}