1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

codestyle fix

This commit is contained in:
Sergey Chazov 2020-10-30 11:38:41 +03:00
parent 14f596f565
commit adeb454ef3
5 changed files with 77 additions and 178 deletions

View file

@ -25,6 +25,7 @@ use Exception;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Repository\PaySystemActionRepository;
use Intaro\RetailCrm\Service\UserAccountService;
use Intaro\RetailCrm\Service\UserVerificationService;
use Bitrix\Sale\Order as BitrixOrder;
@ -34,7 +35,7 @@ use Bitrix\Sale\Order as BitrixOrder;
*/
class Order extends Controller
{
/** @var UserVerificationService */
/** @var UserAccountService */
private $service;
/**
@ -44,7 +45,7 @@ class Order extends Controller
*/
public function __construct(Request $request = null)
{
$this->service = ServiceLocator::get(UserVerificationService::class);
$this->service = ServiceLocator::get(UserAccountService::class);
parent::__construct($request);
}

View file

@ -16,6 +16,7 @@ use Bitrix\Main\Engine\ActionFilter\HttpMethod;
use Bitrix\Main\Engine\Controller;
use Bitrix\Main\Request;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Service\UserAccountService;
use Intaro\RetailCrm\Service\UserVerificationService;
/**
@ -27,7 +28,7 @@ class SmsVerification extends Controller
/** @var int */
const DEFAULT_CODE_LENGHT = 4;
/** @var UserVerificationService */
/** @var UserAccountService */
private $service;
/**
@ -37,7 +38,7 @@ class SmsVerification extends Controller
*/
public function __construct(Request $request = null)
{
$this->service = ServiceLocator::get(UserVerificationService::class);
$this->service = ServiceLocator::get(UserAccountService::class);
parent::__construct($request);
}

View file

@ -112,7 +112,7 @@ class LoyaltyService
public function calculateBonus(array $basketItems, int $discountPrice, int $discountPercent)
{
global $USER;
$request = new LoyaltyCalculateRequest();
$request->order = new SerializedOrder();
$request->order->customer = new SerializedRelationCustomer();
@ -144,14 +144,14 @@ class LoyaltyService
}
$product->initialPrice = $item['PRICE'];
$product->offer = new SerializedOrderProductOffer();
$product->offer = new SerializedOrderProductOffer();
$product->offer->externalId = $item['ID'];
$product->offer->id = $item['ID'];
$product->offer->xmlId = $item['XML_ID'];
$product->quantity = $item['QUANTITY'];
try {
$price = GroupTable::query()
$price = GroupTable::query()
->setSelect(['NAME'])
->where(
[
@ -159,7 +159,7 @@ class LoyaltyService
]
)
->fetch();
$product->priceType = new PriceType();
$product->priceType = new PriceType();
$product->priceType->code = $price['NAME'];
} catch (ObjectPropertyException | ArgumentException | SystemException $e) {
AddMessage2Log('GroupTable query error: ' . $e->getMessage());
@ -177,6 +177,7 @@ class LoyaltyService
}
//TODO доделать метод проверки регистрации в ПЛ
/**
* @return array
*/
@ -268,13 +269,13 @@ class LoyaltyService
if (empty($fields)) {
$phone = $userFields['PERSONAL_PHONE'] ?? '';
$card = $userFields['UF_CARD_NUM_INTARO'] ?? '';
$customerId = (string) $userFields['ID'];
$customerId = (string)$userFields['ID'];
$customFields = $userFields['UF_CSTM_FLDS_INTARO'] ?? [];
$service = new UserAccountService();
$createResponse = $service->createLoyaltyAccount($phone, $card, $customerId, $customFields);
$service->activateLpUserInBitrix($createResponse, $userFields['ID']);
if ($createResponse !== null
&& $createResponse->success === false
&& isset($createResponse->errorMsg)
@ -285,18 +286,18 @@ class LoyaltyService
if (isset($createResponse->errors) && is_array($createResponse->errors)) {
foreach ($createResponse->errors as $error) {
$errorDetails .= $error.' ';
$errorDetails .= $error . ' ';
}
}
AddMessage2Log(GetMessage('REGISTER_ERROR') . ' ('.$createResponse->errorMsg.' '. $errorDetails .')');
AddMessage2Log(GetMessage('REGISTER_ERROR') . ' (' . $createResponse->errorMsg . ' ' . $errorDetails . ')');
$regInLp['msg'] = GetMessage('REGISTER_ERROR') . ' ('.$createResponse->errorMsg.' '. $errorDetails .')';
}elseif($createResponse->success === true){
$regInLp['msg'] = GetMessage('REGISTER_ERROR') . ' (' . $createResponse->errorMsg . ' ' . $errorDetails . ')';
} elseif ($createResponse->success === true) {
//Повторная регистрация оказалась удачной
header("Refresh: 0");
}
}else{
} else {
$regInLp['msg'] = GetMessage('COMPLETE_YOUR_REGISTRATION');
$regInLp['form'] = [
'button' => [
@ -327,52 +328,52 @@ class LoyaltyService
*/
public function applyBonusesInOrder(Event $event): void
{
/**@var \Bitrix\Sale\Order $order */
$order = $event->getParameter("ENTITY");
$orderId = $order->getId();
$bonusCount = (int)$_POST['bonus-input'];
$response = $this->sendBonusPayment($orderId, $bonusCount);
/**@var \Bitrix\Sale\Order $order */
$order = $event->getParameter("ENTITY");
$orderId = $order->getId();
$bonusCount = (int)$_POST['bonus-input'];
$response = $this->sendBonusPayment($orderId, $bonusCount);
if ($response->success) {
try {
$bonusPaySystem = PaySystemActionRepository::getFirstByWhere(['ID'], [['ACTION_FILE', '=', 'retailcrmbonus']]);
$paymentCollection = $order->getPaymentCollection();
if ($response->success) {
try {
$bonusPaySystem = PaySystemActionRepository::getFirstByWhere(['ID'], [['ACTION_FILE', '=', 'retailcrmbonus']]);
$paymentCollection = $order->getPaymentCollection();
if ($bonusPaySystem !== null) {
if (count($paymentCollection) === 1) {
/** @var \Bitrix\Sale\Payment $payment */
foreach ($paymentCollection as $payment){
$oldSum = $payment->getField('SUM');
if ($bonusPaySystem !== null) {
if (count($paymentCollection) === 1) {
/** @var \Bitrix\Sale\Payment $payment */
foreach ($paymentCollection as $payment) {
$oldSum = $payment->getField('SUM');
$payment->setField('SUM', $oldSum - $bonusCount);
break;
}
$payment->setField('SUM', $oldSum - $bonusCount);
break;
}
$service = Manager::getObjectById($bonusPaySystem->getId());
$newPayment = $paymentCollection->createItem($service);
$newPayment->setField('SUM', $bonusCount);
//если верификация необходима, но не пройдена
if (isset($response->verification, $response->verification->checkId)
&& !isset($response->verification->verifiedAt)
) {
$newPayment->setPaid('N');
$newPayment->setField('COMMENTS', $response->verification->checkId);
}
//если верификация не нужна
if (!isset($response->verification)) {
$newPayment->setPaid('Y');
}
$order->save();
}
} catch (ObjectPropertyException | ArgumentException | SystemException | Exception $e) {
AddMessage2Log('ERROR PaySystemActionRepository: ' . $e->getMessage());
$service = Manager::getObjectById($bonusPaySystem->getId());
$newPayment = $paymentCollection->createItem($service);
$newPayment->setField('SUM', $bonusCount);
//если верификация необходима, но не пройдена
if (isset($response->verification, $response->verification->checkId)
&& !isset($response->verification->verifiedAt)
) {
$newPayment->setPaid('N');
$newPayment->setField('COMMENTS', $response->verification->checkId);
}
//если верификация не нужна
if (!isset($response->verification)) {
$newPayment->setPaid('Y');
}
$order->save();
}
} catch (ObjectPropertyException | ArgumentException | SystemException | Exception $e) {
AddMessage2Log('ERROR PaySystemActionRepository: ' . $e->getMessage());
}
}
}
/**

View file

@ -19,6 +19,7 @@ use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateReque
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountActivateResponse;
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
use Intaro\RetailCrm\Model\Api\SerializedCreateLoyaltyAccount;
use Intaro\RetailCrm\Model\Api\SmsVerificationConfirm;
@ -57,23 +58,6 @@ class UserAccountService
return $this->client->checkStatusPlVerification($request);
}
/**
* Подтверждает верификацию
*
* @param string $code Проверочный код
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
*/
public function confirmVerification(string $code, string $checkId)
{
$request = new SmsVerificationConfirmRequest();
$request->verification = new SmsVerificationConfirm();
$request->verification->setCode($code);
$request->verification->setCheckId($checkId);
return $this->client->confirmLpVerificationBySMS($request);
}
/**
* Проверяем статус регистрации пользователя в ПЛ
*
@ -94,6 +78,7 @@ class UserAccountService
{
$activateRequest = new LoyaltyAccountActivateRequest();
$activateRequest->loyaltyId = $loyaltyId;
return $this->client->activateLoyaltyAccount($activateRequest);
}
@ -104,10 +89,10 @@ class UserAccountService
* @param array $customFields
* @return \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null
*/
public function createLoyaltyAccount(string $phone, string $card, string $externalId, array $customFields=[]): ?LoyaltyAccountCreateResponse
public function createLoyaltyAccount(string $phone, string $card, string $externalId, array $customFields = []): ?LoyaltyAccountCreateResponse
{
$credentials = $this->client->getCredentials();
$createRequest = new LoyaltyAccountCreateRequest();
$createRequest->site = $credentials->sitesAvailable[0];
$createRequest->loyaltyAccount = new SerializedCreateLoyaltyAccount();
@ -115,7 +100,7 @@ class UserAccountService
$createRequest->loyaltyAccount->cardNumber = $card ?? '';
$createRequest->loyaltyAccount->customer->externalId = $externalId;
$createRequest->loyaltyAccount->customFields = $customFields ?? [];
return $this->client->createLoyaltyAccount($createRequest);
}
@ -142,28 +127,33 @@ class UserAccountService
&& $createResponse->loyaltyAccount->active
) {
global $USER_FIELD_MANAGER;
$USER_FIELD_MANAGER->Update('USER', $userId, [
'UF_EXT_REG_PL_INTARO' => 'Y',
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
]);
}
if (isset($createResponse->errorMsg)) {
AddMessage2Log($createResponse->errorMsg);
}
}
/**
* @throws \Exception
* Подтверждает верификацию
*
* @param string $code Проверочный код
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
*/
private function checkAuth()
public function confirmVerification(string $code, string $checkId): ?SmsVerificationConfirmResponse
{
global $USER;
$user = $USER;
$request = new SmsVerificationConfirmRequest();
$request->verification = new SmsVerificationConfirm();
$request->verification->code = $code;
$request->verification->checkId = $checkId;
if (!$user->IsAuthorized()) {
throw new RuntimeException(self::NOT_AUTHORIZE);
}
return $this->client->confirmLpVerificationBySMS($request);
}
}

View file

@ -1,94 +0,0 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Service
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Service;
use Exception;
use Intaro\RetailCrm\Component\Factory\ClientFactory;
use Intaro\RetailCrm\Model\Api\Request\SmsVerification\SmsVerificationConfirmRequest;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse;
use Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusRequest;
use Intaro\RetailCrm\Model\Api\SmsVerificationConfirm;
/**
* Class UserVerificationService
*/
class UserVerificationService
{
const NOT_AUTHORIZE = 'Пользователь не авторизован';
const DEFAULT_CODE_LENGHT = 4;
/**
* @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter
*/
private $client;
public function __construct()
{
$this->client = ClientFactory::createClientAdapter();
}
/**
* Получает статус текущего состояния верификации
*
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationStatusResponse|null
*/
public function getSmsStatus(string $checkId)
{
$request = new SmsVerificationStatusRequest();
$request->checkId = $checkId;
return $this->client->checkStatusPlVerification($request);
}
/**
* Подтверждает верификацию
*
* @param string $code Проверочный код
* @param string $checkId Идентификатор проверки кода
* @return \Intaro\RetailCrm\Model\Api\Response\SmsVerification\SmsVerificationConfirmResponse|null
*/
public function confirmVerification(string $code, string $checkId): ?SmsVerificationConfirmResponse
{
$request = new SmsVerificationConfirmRequest();
$request->verification = new SmsVerificationConfirm();
$request->verification->setCode($code);
$request->verification->setCheckId($checkId);
return $this->client->confirmLpVerificationBySMS($request);
}
/**
* Проверяем статус регистрации пользователя в ПЛ
*
* @param int $userId
* @return bool
*/
public function checkPlRegistrationStatus(int $userId)
{
//TODO когда метод будет реализован в АПИ, нужно будет написать реализацию
return $userId;
}
/**
* @throws \Exception
*/
private function checkAuth()
{
global $USER;
$user = $USER;
if (!$user->IsAuthorized()) {
throw new Exception(self::NOT_AUTHORIZE);
}
}
}