ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © JR All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace JR\ReportIntegration\Model;
|
||||
|
||||
use \JR\ReportIntegration\Api\Service\RequestServiceInterface;
|
||||
use \JR\ReportIntegration\Api\Model\SetSalesManagementInterface;
|
||||
use \Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
|
||||
class SetSalesManagement implements SetSalesManagementInterface
|
||||
{
|
||||
/**
|
||||
* @var RequestServiceInterface
|
||||
*/
|
||||
private $requestService;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
private $customerRepository;
|
||||
|
||||
/**
|
||||
* @param RequestServiceInterface
|
||||
* @param CustomerRepositoryInterface
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
RequestServiceInterface $requestService,
|
||||
CustomerRepositoryInterface $customerRepository
|
||||
) {
|
||||
$this->requestService = $requestService;
|
||||
$this->customerRepository = $customerRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function postSetSales($email, $secret, $id, $sales_rep)
|
||||
{
|
||||
return $this->requestService->post(
|
||||
$email,
|
||||
$secret,
|
||||
[$this, 'setSales'],
|
||||
['id' => $id, 'sales_rep' => $sales_rep]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSales($id, $sales_rep)
|
||||
{
|
||||
$result = [];
|
||||
try {
|
||||
$customer = $this->customerRepository->getById($id);
|
||||
$customer->setCustomAttribute('sales_rep', $sales_rep);
|
||||
if ($sales_rep == '' && $customer->getGroupId() == 2) {
|
||||
$customer->setGroupId(1);
|
||||
}
|
||||
$this->customerRepository->save($customer);
|
||||
$result[] = array('account' => $customer->getEmail(), 'error' => NULL);
|
||||
} catch (\Exception $e) {
|
||||
$result[] = array('account' => isset($customer) ? $customer->getEmail() : $id, 'error' => $e->getMessage());
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user