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
+395
View File
@@ -0,0 +1,395 @@
<?php
/**
* @package Plumrocket_Base
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
namespace Plumrocket\Base\Controller\Adminhtml;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\DateTime;
/**
* @deprecated - its better to avoid extending actions
*/
abstract class Actions extends \Magento\Backend\App\Action
{
/**
* @var string
*/
protected $_formSessionKey;
/**
* @var string
*/
protected $_modelClass;
/**
* @var string
*/
protected $_activeMenu;
/**
* @var string
*/
protected $_objectTitle;
/**
* @var string
*/
protected $_objectTitles;
/**
* @var string
*/
protected $_idKey = 'id';
/**
* @var string
*/
protected $_statusField;
/**
* @var \Magento\Rule\Model\AbstractModel
*/
protected $_model;
/**
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* Execute action
*
* @return void
*/
public function execute()
{
$_preparedActions = ['index', 'grid', 'new', 'edit', 'save', 'delete', 'massStatus'];
$_action = $this->getRequest()->getActionName();
if (in_array($_action, $_preparedActions)) {
$method = '_'.$_action.'Action';
$this->_beforeAction();
$this->$method();
$this->_afterAction();
}
}
/**
* Index action
*
* @return void
*/
protected function _indexAction()
{
if ($this->getRequest()->getParam('ajax')) {
$this->_forward('grid');
return;
}
$this->_view->loadLayout();
$this->_setActiveMenu($this->_activeMenu);
$title = __('Manage '.$this->_objectTitles);
$this->_view->getPage()->getConfig()->getTitle()->prepend($title);
$this->_addBreadcrumb($title, $title);
$this->_view->renderLayout();
}
/**
* Grid action
*
* @return void
*/
protected function _gridAction()
{
$this->_view->loadLayout(false);
$this->_view->renderLayout();
}
/**
* New action
*
* @return void
*/
protected function _newAction()
{
$this->_forward('edit');
}
/**
* Edit action
*
* @return void
*/
public function _editAction()
{
$model = $this->_getModel();
$this->_getRegistry()->register('current_model', $model);
$this->_view->loadLayout();
$this->_setActiveMenu($this->_activeMenu);
if ($model->getId()) {
$breadcrumbTitle = __('Edit '.$this->_objectTitle);
$breadcrumbLabel = $breadcrumbTitle;
} else {
$breadcrumbTitle = __('New '.$this->_objectTitle);
$breadcrumbLabel = __('Create '.$this->_objectTitle);
}
$this->_view->getPage()->getConfig()->getTitle()->prepend(__($this->_objectTitle));
$this->_view->getPage()->getConfig()->getTitle()->prepend(
$model->getId() ? $model->getName() : __('New '.$this->_objectTitle)
);
$this->_addBreadcrumb($breadcrumbLabel, $breadcrumbTitle);
// restore data
$values = $this->_getSession()->getData($this->_formSessionKey, true);
if ($values) {
$model->addData($values);
}
$this->_view->renderLayout();
}
/**
* Save action
*
* @return void
*/
public function _saveAction()
{
$request = $this->getRequest();
if (!$request->isPost()) {
$this->getResponse()->setRedirect($this->getUrl('*/*'));
}
$model = $this->_getModel();
try {
$date = $this->_objectManager->get(DateTime::class)->gmtDate();
$model->addData($request->getParams())
->setUpdatedAt($date);
if (!$model->getId()) {
$model->setCreatedAt($date);
}
$this->_beforeSave($model, $request);
$model->save();
$this->_afterSave($model, $request);
$this->messageManager->addSuccess(__($this->_objectTitle.' has been saved.'));
$this->_setFormData(false);
if ($request->getParam('back')) {
$this->_redirect('*/*/edit', [$this->_idKey => $model->getId()]);
} else {
$this->_redirect('*/*');
}
return;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError(nl2br($e->getMessage()));
$this->_setFormData();
} catch (\Exception $e) {
$this->messageManager->addException(
$e,
__('Something went wrong while saving this '.strtolower($this->_objectTitle).'.')
);
$this->_setFormData();
}
$this->_forward('new');
}
/**
* Before save logic
*
* @return void
*/
protected function _beforeSave($model, $request)
{
}
/**
* After save logic
*
* @return void
*/
protected function _afterSave($model, $request)
{
}
/**
* Before action execute
*
* @return void
*/
protected function _beforeAction()
{
}
/**
* After action execute
*
* @return void
*/
protected function _afterAction()
{
}
/**
* Delete action execute
*
* @return void
*/
protected function _deleteAction()
{
$ids = $this->getRequest()->getParam($this->_idKey);
if (!is_array($ids)) {
$ids = [$ids];
}
$error = false;
try {
foreach ($ids as $id) {
$this->_objectManager->create($this->_modelClass)->setId($id)->delete();
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$error = true;
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$error = true;
$this->messageManager->addExceptionMessage(
$e,
__('We can\'t delete '.strtolower($this->_objectTitle).' right now. '.$e->getMessage())
);
}
if (!$error) {
$this->messageManager->addSuccessMessage(
(count($ids) > 1)
? __($this->_objectTitles.' have been deleted.')
: __($this->_objectTitle.' has been deleted.')
);
}
$this->_redirect('*/*');
}
/**
* Mass status change action
*
* @return void
*/
protected function _massStatusAction()
{
$ids = $this->getRequest()->getParam($this->_idKey);
if (!is_array($ids)) {
$ids = [$ids];
}
$error = false;
try {
$status = $this->getRequest()->getParam('status');
if ($status === null) {
throw new \Exception(__('Parameter "Status" missing in request data.'));
}
foreach ($ids as $id) {
$this->_objectManager->create($this->_modelClass)
->load($id)
->setData($this->_statusField, $status)
->save();
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$error = true;
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$error = true;
$this->messageManager->addExceptionMessage(
$e,
__('We can\'t change status of '.strtolower($this->_objectTitle).' right now. '.$e->getMessage())
);
}
if (!$error) {
$this->messageManager->addSuccessMessage(
(count($ids) > 1)
? __($this->_objectTitles.' status have been changed.')
: __($this->_objectTitle.' status have been changed.')
);
}
$this->_redirect('*/*');
}
/**
* Set for mada
*
* @param array|null $data
*/
protected function _setFormData($data = null)
{
$this->_getSession()->setData(
$this->_formSessionKey,
$data ?? $this->getRequest()->getParams()
);
return $this;
}
/**
* Receive registry object
*
* @return \Magento\Framework\Registry
*/
protected function _getRegistry()
{
if ($this->_coreRegistry === null) {
$this->_coreRegistry = $this->_objectManager->get(Registry::class);
}
return $this->_coreRegistry;
}
/**
* Receive model object
*
* @return \Magento\Rule\Model\AbstractModel
*/
protected function _getModel($load = true)
{
if ($this->_model === null) {
$this->_model = $this->_objectManager->create($this->_modelClass);
$id = (int)$this->getRequest()->getParam($this->_idKey);
if ($id && $load) {
$this->_model->load($id);
}
}
return $this->_model;
}
/**
* @return bool
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed(static::ADMIN_RESOURCE);
}
}
@@ -0,0 +1,166 @@
<?php
/**
* @package Plumrocket_Base
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
namespace Plumrocket\Base\Controller\Adminhtml\Call;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Plumrocket\Base\Api\GetModuleVersionInterface;
use Plumrocket\Base\Model\External\Urls;
use Plumrocket\Base\Model\Utils\GetEnabledStoresUrls;
class Index extends Action
{
/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
private $resultJsonFactory;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private $configWriter;
/**
* @var \Magento\Framework\App\ProductMetadataInterface
*/
private $productMetadata;
/**
* @var \Plumrocket\Base\Api\GetModuleVersionInterface
*/
private $getModuleVersion;
/**
* @var \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls
*/
private $getEnabledStoresUrls;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Plumrocket\Base\Api\GetModuleVersionInterface $getModuleVersion
* @param \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls $getEnabledStoresUrls
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
WriterInterface $configWriter,
ProductMetadataInterface $productMetadata,
GetModuleVersionInterface $getModuleVersion,
GetEnabledStoresUrls $getEnabledStoresUrls
) {
parent::__construct($context);
$this->productMetadata = $productMetadata;
$this->resultJsonFactory = $resultJsonFactory;
$this->configWriter = $configWriter;
$this->getModuleVersion = $getModuleVersion;
$this->getEnabledStoresUrls = $getEnabledStoresUrls;
}
/**
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getPostValue();
$return = [];
if (isset($data['order_id'], $data['account_email'], $data['module'])) {
$moduleName = $data['module'];
$postData = [
'order' => $data['order_id'],
'email' => $data['account_email'],
'name_version' => $this->getModuleVersion->execute($moduleName),
'base_urls' => $this->getEnabledStoresUrls->execute(),
'name' => $moduleName,
'edition' => $this->productMetadata->getEdition(),
'platform' => 'm2',
'pixel' => 0,
'v' => 1,
];
$response = $this->call($postData);
$response = (array)json_decode($response);
if (!empty($response['hash'])) {
$this->configWriter->save(
$moduleName.'/module/data',
$response['hash'],
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
$return['hash'] = true;
} else {
$return['hash'] = false;
}
if (isset($response['data'])) {
$return['data'] = $response['data'];
}
if (!empty($response['errors'])) {
if (is_array($response['errors'])) {
$error = implode('<br />', $response['errors']);
} else {
$error = $response['errors'];
}
$return['error'] = $error;
}
}
$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData(json_encode($return));
}
/**
* @param $postData
* @return bool|string
*/
private function call($postData)
{
$url = 'https://' . Urls::MARKETPLACE_PINGBACK_URL;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
if (is_array($postData)) {
$postData = http_build_query($postData);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
/**
* @return bool
*/
public function _processUrlKeys()
{
return true;
}
/**
* Check Permission.
*
* @return bool
*/
protected function _isAllowed()
{
return true;
}
}
@@ -0,0 +1,58 @@
<?php
/**
* @package Plumrocket_Base
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license/ End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\Base\Controller\Adminhtml\Debug;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Plumrocket\Base\Model\Debug\Export as ExportDebugInfo;
/**
* @since 2.3.0
*/
class Download extends Action
{
/**
* @var ExportDebugInfo
*/
private $exportDebugInfo;
/**
* Download constructor.
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Plumrocket\Base\Model\Debug\Export $exportDebugInfo
*/
public function __construct(
Context $context,
ExportDebugInfo $exportDebugInfo
) {
parent::__construct($context);
$this->exportDebugInfo = $exportDebugInfo;
}
/**
* Execute export action.
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws \Exception
*/
public function execute() : ResultInterface
{
try {
$this->exportDebugInfo->execute();
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_RAW);
}
}