Логика показа информации по истории транзакции заказа

parent f40b0399
...@@ -36,6 +36,7 @@ return [ ...@@ -36,6 +36,7 @@ return [
->allow(Roles::ROLE_USER, 'user.cabinet.cats', null, new \App\Acl\Assertion\UserActive()) ->allow(Roles::ROLE_USER, 'user.cabinet.cats', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.cabinet.profile', null, new \App\Acl\Assertion\UserActive()) ->allow(Roles::ROLE_USER, 'user.cabinet.profile', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.cabinet.viewid', null, new \App\Acl\Assertion\UserActive()) ->allow(Roles::ROLE_USER, 'user.cabinet.viewid', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.cabinet.orderid', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'install.counter', null, new \App\Acl\Assertion\UserActive()) ->allow(Roles::ROLE_USER, 'install.counter', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'download.counter', null, new \App\Acl\Assertion\UserActive()) ->allow(Roles::ROLE_USER, 'download.counter', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_GUEST, 'email.counter') ->allow(Roles::ROLE_GUEST, 'email.counter')
......
...@@ -345,6 +345,23 @@ return [ ...@@ -345,6 +345,23 @@ return [
] ]
], ],
], ],
[
'name' => 'user.cabinet.orderid',
'path' => '/[:lang/]cabinet/orderid/:feedid/:id',
'middleware' => App\Action\User\ViewId::class,
'allowed_methods' => ['GET', 'POST'],
'options' => [
'constraints' => [
'lang' => '[a-z]{2,3}',
'feedid' => '\w+',
'id' => '\w+',
],
'defaults' => [
'lang' => \App\Model\Locales::DEFAULT_LANG,
'action' => App\Action\User\ViewId::ACTION_STAT_ORDER,
]
],
],
[ [
'name' => 'user.cabinet.profile', 'name' => 'user.cabinet.profile',
'path' => '/[:lang/]cabinet/profile/', 'path' => '/[:lang/]cabinet/profile/',
......
...@@ -33,6 +33,11 @@ $(document).ready(function(){ ...@@ -33,6 +33,11 @@ $(document).ready(function(){
' <span><%=data.date %></span><br /> \n' + ' <span><%=data.date %></span><br /> \n' +
''); '');
// Шаблон ячейки OrderID
var templateOrderIDContent = _.template('\n'+
' <a class="orderid-link" href="orderid/<%=data.feedId %>/<%=data.orderId %>" target="_blank"><%=data.orderId %></a> \n' +
'');
// Шаблон ячейки ViewID // Шаблон ячейки ViewID
var templateViewIDContent = _.template('\n'+ var templateViewIDContent = _.template('\n'+
' <a class="viewid-link" href="viewid/<%=data.feedId %>/<%=data.viewId %>" target="_blank"><%=data.viewId %></a> \n' + ' <a class="viewid-link" href="viewid/<%=data.feedId %>/<%=data.viewId %>" target="_blank"><%=data.viewId %></a> \n' +
...@@ -140,7 +145,15 @@ $(document).ready(function(){ ...@@ -140,7 +145,15 @@ $(document).ready(function(){
// Отрисовка таблицы: // Отрисовка таблицы:
dataTableForSort.forEach(function(item){ dataTableForSort.forEach(function(item){
$row = $('<tr>'); $row = $('<tr>');
if (dataLineChartStat.report == 'transactions') {
$row.append($('<td>').append(templateOrderIDContent({
data: {feedId: item['ViewID'][0], orderId: item['period']}
})));
} else {
$row.append($('<td>').html(item['period'])); $row.append($('<td>').html(item['period']));
}
activeLines.forEach(function(line){ activeLines.forEach(function(line){
if (line == 'Basket') { if (line == 'Basket') {
var dataBasket = item[line]; var dataBasket = item[line];
......
...@@ -46,16 +46,24 @@ use Zend\Diactoros\Response\RedirectResponse; ...@@ -46,16 +46,24 @@ use Zend\Diactoros\Response\RedirectResponse;
class ViewId extends Common class ViewId extends Common
{ {
const ACTION_STAT = 'stat'; const ACTION_STAT = 'stat';
const ACTION_STAT_ORDER = 'stat_order';
const STAT_CATS = array( const STAT_CATS = array(
'StartTime' => 'StartTime', 'StartTime' => 'StartTime',
'EndTime' => 'EndTime', 'EndTime' => 'EndTime',
'IP' => 'IP', 'IP' => 'IP',
'Basket' => 'Состав корзины', 'Basket' => 'Состав корзины',
'Pages' => 'Pages', 'Pages' => 'Pages',
//'TransactionID' => 'TransactionID',
'ForeignID' => 'ForeignID', 'ForeignID' => 'ForeignID',
'OrderSum' => 'OrderSum', 'OrderSum' => 'OrderSum',
); );
const STAT_CATS_ORDER = array(
'Timestamp' => 'DateTime',
'IP' => 'IP',
'VisitorID' => 'UserID',
'ViewID' => 'ViewID',
'OrderIP' => 'OrderIP',
'URL' => 'URL',
);
/** /**
* @param ServerRequestInterface $request * @param ServerRequestInterface $request
...@@ -86,16 +94,51 @@ class ViewId extends Common ...@@ -86,16 +94,51 @@ class ViewId extends Common
$response = new JsonResponse($data); $response = new JsonResponse($data);
} }
return $response; return $response;
}
elseif($request->getAttribute('action') == self::ACTION_STAT_ORDER) {
} else { try {
/*
$feed_id = $request->getAttribute('feedid'); $feed_id = $request->getAttribute('feedid');
$view_id = $request->getAttribute('id'); $order_id = $request->getAttribute('id');
$viewIdStats = $stats->getViewIdStatData($feed_id, $view_id); /** @var UserService $auth */
return new JsonResponse($viewIdStats); $auth = $this->container->get(UserService::class);
*/ $userId = $auth->getIdentity()->getId();
/** @var \App\Model\Feeds $feedsModel */
$feedsModel = $this->container->get(Feeds::class);
$feed_item = $feedsModel->findById($feed_id);
if ($feed_item) {
if ($feed_item->getClientid() == $userId){
// Статистика-история по клику:
$orderIdStats = $stats->getOrderIdStatData($feed_id, $order_id);
$data['viewIdStats'] = $orderIdStats;
$data['cats'] = self::STAT_CATS_ORDER;
} else {
$data['error'] = _t('Извините, данный фид закреплен за другим пользователем');
}
} else {
$data['error'] = _t('Извините, фид не найден');
}
} catch(\Exception $e) {
$data['error'] = _t('Извините, история визитов по заказу временно не работает');
}
$data = array_merge($data, [
'lang' => $request->getAttribute('layoutInfo')->getLang(),
'layoutInfo' => $request->getAttribute('layoutInfo'),
]);
return new HtmlResponse($this->template->render('app::user/cabinet-feed-click-history', $data));
} else {
try { try {
......
...@@ -312,7 +312,38 @@ class Statistics ...@@ -312,7 +312,38 @@ class Statistics
return $stats; return $stats;
} }
// Данные по статистике по заказу фида
public function getOrderIdStatData($feed_id, $order_id)
{
$dataRequest = array(
'method' => 'feed_order_history',
'data' => array(
'feed_id' => (int) $feed_id,
'order_id' => $order_id
)
);
//return $dataRequest;
//$stats = $this->apiRequest($dataRequest);
//return $stats;
try {
$stats = $this->apiRequest($dataRequest);
} catch (\Exception $e) {
$stats['status'] = 'Error';
}
// В запросе ошибка или отсутствуют данные для статистики:
if ($stats['status'] == 'Error') {
return $stats;
}
if ($stats['data'] == []) {
return null;
}
$stats = $stats['data'];
return $stats;
}
// Запрос к API: // Запрос к API:
private function apiRequest($data) private function apiRequest($data)
......
...@@ -99,7 +99,7 @@ if (!$error) { ...@@ -99,7 +99,7 @@ if (!$error) {
<?php foreach($cats as $name => $title): ?> <?php foreach($cats as $name => $title): ?>
<td class="<?= $name ?>" data-id="<?= $name ?>"> <td class="<?= $name ?>" data-id="<?= $name ?>">
<?php if($name == 'StartTime' || $name == 'EndTime'): ?> <?php if($name == 'StartTime' || $name == 'EndTime' || $name == 'Timestamp'): ?>
<?php <?php
$date_time = explode(" ", $view_id[$name]); $date_time = explode(" ", $view_id[$name]);
?> ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment