ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\Detail;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\DetailLoaderInterface;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetailCollectionFactory;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail;
class FullDetailLoader implements DetailLoaderInterface
{
/**
* @var VisitHistoryDetailCollectionFactory
*/
private $detailCollectionFactory;
public function __construct(VisitHistoryDetailCollectionFactory $detailCollectionFactory)
{
$this->detailCollectionFactory = $detailCollectionFactory;
}
public function loadDetails(int $visitHistoryId): array
{
$collection = $this->detailCollectionFactory->create();
$collection->addFieldToFilter(VisitHistoryDetail::VISIT_ID, $visitHistoryId);
return $collection->getItems();
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\Detail;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\DetailLoaderInterface;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetailCollectionFactory;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail;
class LastDetailLoader implements DetailLoaderInterface
{
/**
* @var VisitHistoryDetailCollectionFactory
*/
private $detailCollectionFactory;
public function __construct(VisitHistoryDetailCollectionFactory $detailCollectionFactory)
{
$this->detailCollectionFactory = $detailCollectionFactory;
}
public function loadDetails(int $visitHistoryId): array
{
$collection = $this->detailCollectionFactory->create();
$collection->addFieldToFilter(VisitHistoryDetail::VISIT_ID, $visitHistoryId);
$collection->setOrder($collection->getIdFieldName(), $collection::SORT_ORDER_DESC);
$collection->setPageSize(1);
return $collection->getItems();
}
}
@@ -0,0 +1,21 @@
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface;
interface DetailLoaderInterface
{
/**
* Load associated VisitHistoryDetails via VisitHistory ID.
*
* @param int $visitHistoryId
* @return VisitHistoryDetailInterface[]
*/
public function loadDetails(int $visitHistoryId): array;
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterfaceFactory;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryFinderInterface;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
use Amasty\AdminActionsLog\Model\CriteriaApplierTrait;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\CollectionFactory;
use Magento\Framework\Api\SearchCriteriaInterface;
class Finder implements VisitHistoryEntryFinderInterface
{
use CriteriaApplierTrait;
/**
* @var CollectionFactory
*/
private $collectionFactory;
/**
* @var VisitHistoryEntryRepositoryInterface
*/
private $historyEntryRepository;
/**
* @var VisitHistoryEntrySearchResultsInterfaceFactory
*/
private $searchResultsFactory;
public function __construct(
CollectionFactory $collectionFactory,
VisitHistoryEntryRepositoryInterface $historyEntryRepository,
VisitHistoryEntrySearchResultsInterfaceFactory $searchResultsFactory
) {
$this->collectionFactory = $collectionFactory;
$this->historyEntryRepository = $historyEntryRepository;
$this->searchResultsFactory = $searchResultsFactory;
}
public function getList(SearchCriteriaInterface $searchCriteria): VisitHistoryEntrySearchResultsInterface
{
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
$visitHistoryCollection = $this->collectionFactory->create();
$this->applyCriteria($searchCriteria, $visitHistoryCollection);
$searchResults->setTotalCount($visitHistoryCollection->getSize());
$historyItems = array_map(function (VisitHistoryEntryInterface $visitHistory) {
return $this->historyEntryRepository->getById($visitHistory->getId());
}, $visitHistoryCollection->getItems());
$searchResults->setItems($historyItems);
return $searchResults;
}
}
@@ -0,0 +1,185 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterfaceFactory;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetail as VisitHistoryDetailResource;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail as VisitHistoryDetailModel;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryEntry as VisitHistoryEntryModel;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Stdlib\DateTime\DateTime;
class Repository implements VisitHistoryEntryRepositoryInterface
{
/**
* @var VisitHistoryEntryInterfaceFactory
*/
private $visitHistoryEntryFactory;
/**
* @var ResourceModel\VisitHistoryEntry
*/
private $visitHistoryEntryResource;
/**
* @var ResourceModel\CollectionFactory
*/
private $visitHistoryEntryCollectionFactory;
/**
* @var VisitHistoryDetailResource
*/
private $visitHistoryDetailResource;
/**
* @var DetailLoaderInterface
*/
private $detailLoader;
/**
* @var DateTime
*/
private $dateTime;
/**
* @var array
*/
private $visitHistoryEntries = [];
/**
* @var array
*/
private $visitHistoryEntriesBySessionId = [];
public function __construct(
VisitHistoryEntryInterfaceFactory $visitHistoryEntryFactory,
ResourceModel\VisitHistoryEntry $visitHistoryEntryResource,
ResourceModel\CollectionFactory $visitHistoryEntryCollectionFactory,
VisitHistoryDetailResource $visitHistoryDetailResource,
DetailLoaderInterface $detailLoader,
DateTime $dateTime
) {
$this->visitHistoryEntryFactory = $visitHistoryEntryFactory;
$this->visitHistoryEntryResource = $visitHistoryEntryResource;
$this->visitHistoryEntryCollectionFactory = $visitHistoryEntryCollectionFactory;
$this->visitHistoryDetailResource = $visitHistoryDetailResource;
$this->detailLoader = $detailLoader;
$this->dateTime = $dateTime;
}
public function getById(int $id): VisitHistoryEntryInterface
{
if (!isset($this->visitHistoryEntries[$id])) {
/** @var VisitHistoryEntryInterface $visitHistoryEntry */
$visitHistoryEntry = $this->visitHistoryEntryFactory->create();
$this->visitHistoryEntryResource->load($visitHistoryEntry, $id);
if (!$visitHistoryEntry->getId()) {
throw new NoSuchEntityException(__('Visit History Entry with specified ID "%1" not found.', $id));
}
$visitHistoryEntry->setVisitHistoryDetails($this->detailLoader->loadDetails($id));
$this->visitHistoryEntries[$id] = $visitHistoryEntry;
}
return $this->visitHistoryEntries[$id];
}
public function getBySessionId(string $sessionId): VisitHistoryEntryInterface
{
if (!isset($this->visitHistoryEntriesBySessionId[$sessionId])) {
$historyEntryId = $this->resolveHistoryIdBySessionId($sessionId);
$this->visitHistoryEntriesBySessionId[$sessionId] = $this->getById($historyEntryId);
}
return $this->visitHistoryEntriesBySessionId[$sessionId];
}
public function save(VisitHistoryEntryInterface $visitHistoryEntry): VisitHistoryEntryInterface
{
try {
if ($visitHistoryEntry->getId()) {
$visitHistoryEntry = $this->getById((int)$visitHistoryEntry->getId())
->addData($visitHistoryEntry->getData());
}
$this->visitHistoryEntryResource->save($visitHistoryEntry);
/** @var VisitHistoryDetailModel $visitHistoryDetail */
foreach ($visitHistoryEntry->getVisitHistoryDetails() as $visitHistoryDetail) {
$visitHistoryDetail->setVisitId((int)$visitHistoryEntry->getId());
$visitHistoryDetail->setSessionId((string)$visitHistoryEntry->getSessionId());
$this->visitHistoryDetailResource->save($visitHistoryDetail);
}
unset(
$this->visitHistoryEntries[$visitHistoryEntry->getId()],
$this->visitHistoryEntriesBySessionId[$visitHistoryEntry->getSessionId()]
);
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Unable to save the Visit History. Error: %1', $e->getMessage()));
}
return $visitHistoryEntry;
}
public function delete(VisitHistoryEntryInterface $visitHistoryEntry): bool
{
try {
$this->visitHistoryEntryResource->delete($visitHistoryEntry);
unset(
$this->visitHistoryEntries[$visitHistoryEntry->getId()],
$this->visitHistoryEntriesBySessionId[$visitHistoryEntry->getSessionId()]
);
} catch (\Exception $e) {
throw new CouldNotDeleteException(__('Unable to delete the Visit History. Error: %1', $e->getMessage()));
}
return true;
}
public function deleteById(int $id): bool
{
return $this->delete($this->getById($id));
}
public function clean(?int $period = null): void
{
$connection = $this->visitHistoryEntryResource->getConnection();
$tableName = $this->visitHistoryEntryResource->getMainTable();
if ($period === null) {
$connection->delete($tableName);
} else {
$time = '-' . $period . ' days';
$connection->delete(
$tableName,
[VisitHistoryEntryModel::SESSION_START . ' < ?' =>
$this->dateTime->gmtDate('Y-m-d H:i:s', $time)
]
);
}
}
private function resolveHistoryIdBySessionId(string $sessionId): int
{
$historyEntryCollection = $this->visitHistoryEntryCollectionFactory->create();
$historyEntryCollection->addFieldToFilter(VisitHistoryEntryModel::SESSION_ID, $sessionId);
$historyEntryCollection->setPageSize(1);
/** @var VisitHistoryDetailInterface $historyEntry */
$historyEntry = $historyEntryCollection->getFirstItem();
return (int)$historyEntry->getId();
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryEntry as VisitHistoryEntryResource;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryEntry as VisitHistoryEntryModel;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection
{
public function _construct()
{
$this->_init(VisitHistoryEntryModel::class, VisitHistoryEntryResource::class);
$this->_setIdFieldName($this->getResource()->getIdFieldName());
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail as VisitHistoryDetailModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class VisitHistoryDetail extends AbstractDb
{
public const TABLE_NAME = 'amasty_audit_visit_details';
protected function _construct()
{
$this->_init(self::TABLE_NAME, VisitHistoryDetailModel::ID);
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel\VisitHistoryDetail as VisitHistoryDetailResource;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryDetail as VisitHistoryDetailModel;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class VisitHistoryDetailCollection extends AbstractCollection
{
public function _construct()
{
$this->_init(VisitHistoryDetailModel::class, VisitHistoryDetailResource::class);
$this->_setIdFieldName($this->getResource()->getIdFieldName());
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry\ResourceModel;
use Amasty\AdminActionsLog\Model\VisitHistoryEntry\VisitHistoryEntry as VisitHistoryEntryModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class VisitHistoryEntry extends AbstractDb
{
public const TABLE_NAME = 'amasty_audit_visit_entry';
protected function _construct()
{
$this->_init(self::TABLE_NAME, VisitHistoryEntryModel::ID);
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryDetailInterface;
use Magento\Framework\Model\AbstractModel;
class VisitHistoryDetail extends AbstractModel implements VisitHistoryDetailInterface
{
public const ID = 'id';
public const VISIT_ID = 'visit_id';
public const PAGE_NAME = 'page_name';
public const PAGE_URL = 'page_url';
public const STAY_DURATION = 'stay_duration';
public const SESSION_ID = 'session_id';
public function _construct()
{
parent::_construct();
$this->_init(ResourceModel\VisitHistoryDetail::class);
$this->setIdFieldName(self::ID);
}
public function getVisitId(): ?int
{
return $this->hasData(self::VISIT_ID) ? (int)$this->_getData(self::VISIT_ID) : null;
}
public function setVisitId(int $visitId): VisitHistoryDetailInterface
{
$this->setData(self::VISIT_ID, $visitId);
return $this;
}
public function getPageName(): ?string
{
return $this->_getData(self::PAGE_NAME);
}
public function setPageName(string $pageName): VisitHistoryDetailInterface
{
$this->setData(self::PAGE_NAME, $pageName);
return $this;
}
public function getPageUrl(): ?string
{
return $this->_getData(self::PAGE_URL);
}
public function setPageUrl(string $pageUrl): VisitHistoryDetailInterface
{
$this->setData(self::PAGE_URL, $pageUrl);
return $this;
}
public function getStayDuration(): ?int
{
return $this->hasData(self::STAY_DURATION) ? (int)$this->_getData(self::STAY_DURATION) : null;
}
public function setStayDuration(int $stayDuration): VisitHistoryDetailInterface
{
$this->setData(self::STAY_DURATION, $stayDuration);
return $this;
}
public function getSessionId(): ?string
{
return $this->_getData(self::SESSION_ID);
}
public function setSessionId(string $sessionId): VisitHistoryDetailInterface
{
$this->setData(self::SESSION_ID, $sessionId);
return $this;
}
}
@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
use Magento\Framework\Model\AbstractModel;
class VisitHistoryEntry extends AbstractModel implements VisitHistoryEntryInterface
{
public const ID = 'id';
public const USERNAME = 'username';
public const FULL_NAME = 'full_name';
public const SESSION_START = 'session_start';
public const SESSION_END = 'session_end';
public const IP = 'ip';
public const LOCATION = 'location';
public const SESSION_ID = 'session_id';
public const VISIT_HISTORY_DETAILS = 'visit_history_details';
public function _construct()
{
parent::_construct();
$this->_init(ResourceModel\VisitHistoryEntry::class);
$this->setIdFieldName(self::ID);
}
public function getUsername(): ?string
{
return $this->_getData(self::USERNAME);
}
public function setUsername(string $username): VisitHistoryEntryInterface
{
$this->setData(self::USERNAME, $username);
return $this;
}
public function getFullName(): ?string
{
return $this->_getData(self::FULL_NAME);
}
public function setFullName(string $fullName): VisitHistoryEntryInterface
{
return $this->setData(self::FULL_NAME, $fullName);
}
public function getSessionStart(): ?string
{
return $this->_getData(self::SESSION_START);
}
public function setSessionStart(string $sessionStart): VisitHistoryEntryInterface
{
$this->setData(self::SESSION_START, $sessionStart);
return $this;
}
public function getSessionEnd(): ?string
{
return $this->_getData(self::SESSION_END);
}
public function setSessionEnd(string $sessionEnd): VisitHistoryEntryInterface
{
$this->setData(self::SESSION_END, $sessionEnd);
return $this;
}
public function getIp(): ?string
{
return $this->_getData(self::IP);
}
public function setIp(string $ip): VisitHistoryEntryInterface
{
$this->setData(self::IP, $ip);
return $this;
}
public function getLocation(): ?string
{
return $this->_getData(self::LOCATION);
}
public function setLocation(string $location): VisitHistoryEntryInterface
{
$this->setData(self::LOCATION, $location);
return $this;
}
public function getSessionId(): ?string
{
return $this->_getData(self::SESSION_ID);
}
public function setSessionId(string $sessionId): VisitHistoryEntryInterface
{
$this->setData(self::SESSION_ID, $sessionId);
return $this;
}
public function getVisitHistoryDetails(): array
{
return (array)$this->_getData(self::VISIT_HISTORY_DETAILS);
}
public function setVisitHistoryDetails(array $visitHistoryDetails): VisitHistoryEntryInterface
{
$this->setData(self::VISIT_HISTORY_DETAILS, $visitHistoryDetails);
return $this;
}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntrySearchResultsInterface;
use Magento\Framework\Api\SearchResults;
/**
* Service Data Object with Visit History Entry search results.
*/
class VisitHistoryEntrySearchResults extends SearchResults implements VisitHistoryEntrySearchResultsInterface
{
}
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Admin Actions Log for Magento 2
*/
namespace Amasty\AdminActionsLog\Model\VisitHistoryEntry;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterface;
use Amasty\AdminActionsLog\Api\Data\VisitHistoryEntryInterfaceFactory;
use Amasty\AdminActionsLog\Api\VisitHistoryEntryRepositoryInterface;
use Amasty\AdminActionsLog\Api\VisitHistoryManagerInterface;
use Amasty\AdminActionsLog\Model\Admin\SessionUserDataProvider;
use Magento\Framework\Stdlib\DateTime\DateTime;
class VisitHistoryManager implements VisitHistoryManagerInterface
{
/**
* @var SessionUserDataProvider
*/
private $sessionUserDataProvider;
/**
* @var VisitHistoryEntryInterfaceFactory
*/
private $visitHistoryEntryFactory;
/**
* @var VisitHistoryEntryRepositoryInterface
*/
private $visitHistoryEntryRepository;
/**
* @var DateTime
*/
private $dateTime;
public function __construct(
SessionUserDataProvider $sessionUserDataProvider,
VisitHistoryEntryInterfaceFactory $visitHistoryEntryFactory,
VisitHistoryEntryRepositoryInterface $visitHistoryEntryRepository,
DateTime $dateTime
) {
$this->sessionUserDataProvider = $sessionUserDataProvider;
$this->visitHistoryEntryFactory = $visitHistoryEntryFactory;
$this->visitHistoryEntryRepository = $visitHistoryEntryRepository;
$this->dateTime = $dateTime;
}
public function startVisit(): void
{
$userData = $this->sessionUserDataProvider->getUserPreparedData();
/** @var $visitHistoryEntryModel VisitHistoryEntryInterface */
$visitHistoryEntryModel = $this->visitHistoryEntryFactory->create(['data' => $userData]);
$visitHistoryEntryModel->setSessionStart($this->dateTime->date());
$this->visitHistoryEntryRepository->save($visitHistoryEntryModel);
}
public function endVisit(string $sessionId = null): void
{
$sessionId = $sessionId ?: $this->sessionUserDataProvider->getSessionId();
/** @var $visitHistoryEntryModel VisitHistoryEntryInterface */
$visitHistoryEntryModel = $this->visitHistoryEntryRepository->getBySessionId($sessionId);
$visitHistoryEntryModel->setSessionEnd($this->dateTime->date());
$this->visitHistoryEntryRepository->save($visitHistoryEntryModel);
}
public function clear(int $period = null): void
{
$this->visitHistoryEntryRepository->clean($period);
}
}