瀏覽代碼

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Fab 3 年之前
父節點
當前提交
5c17aeb51f
共有 9 個檔案被更改,包括 185 行新增33 行删除
  1. +25
    -18
      Builder/Credit/CreditHistoryBuilder.php
  2. +82
    -0
      Builder/Reduction/ReductionCreditBuilder.php
  3. +0
    -1
      CaracoleBundle
  4. +9
    -0
      Container/Merchant/MerchantContainer.php
  5. +4
    -1
      Factory/Reduction/ReductionCreditFactory.php
  6. +13
    -1
      Repository/Order/OrderProductStore.php
  7. +19
    -0
      Repository/Reduction/ReductionCreditRepositoryQuery.php
  8. +12
    -12
      Repository/Reduction/ReductionCreditStore.php
  9. +21
    -0
      Solver/Merchant/MerchantSolver.php

+ 25
- 18
Builder/Credit/CreditHistoryBuilder.php 查看文件

@@ -8,21 +8,29 @@ use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\User\UserMerchantStore;
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;
use Lc\CaracoleBundle\Solver\User\UserMerchantSolver;

class CreditHistoryBuilder
{
protected CreditHistoryFactory $creditHistoryFactory;
protected CreditHistorySolver $creditHistorySolver;
protected UserMerchantSolver $userMerchantSolver;
protected UserMerchantStore $userMerchantStore;
protected UserMerchantBuilder $userMerchantBuilder;

public function __construct(
CreditHistoryFactory $creditHistoryFactory,
CreditHistorySolver $creditHistorySolver,
UserMerchantStore $userMerchantStore,
UserMerchantBuilder $userMerchantBuilder
UserMerchantBuilder $userMerchantBuilder,
UserMerchantSolver $userMerchantSolver
) {
$this->creditHistoryFactory = $creditHistoryFactory;
$this->creditHistorySolver = $creditHistorySolver;
$this->userMerchantStore = $userMerchantStore;
$this->userMerchantBuilder = $userMerchantBuilder;
$this->userMerchantSolver = $userMerchantSolver;
}

public function create(
@@ -54,26 +62,25 @@ class CreditHistoryBuilder
// saveCreditHistory
public function save(CreditHistoryInterface $creditHistory): bool
{
if ($creditHistory) {
$userMerchant = $creditHistory->getUserMerchant();
$isCreditActive = $this->userMerchantStore->isCreditActive($userMerchant);
$amount = $this->creditHistorySolver->getAmountInherited($creditHistory);
$userMerchant = $creditHistory->getUserMerchant();
$isCreditActive = $this->userMerchantSolver->isCreditActive($userMerchant);

if ($isCreditActive) {
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) {
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited();
if ($isCreditActive) {
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) {
$userMerchantAmount = $userMerchant->getCredit() + $amount;
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount);
return true;
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) {
if ($this->userMerchantSolver->isCreditSufficientToPay(
$userMerchant,
$amount
)) {
$userMerchantAmount = $userMerchant->getCredit() - $amount;
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount);
return true;
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) {
if ($this->userMerchantStore->isCreditSufficientToPay(
$userMerchant,
$creditHistory->getAmountInherited()
)) {
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited();
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount);
return true;
} else {
return false;
}
} else {
return false;
}
}
}

+ 82
- 0
Builder/Reduction/ReductionCreditBuilder.php 查看文件

@@ -0,0 +1,82 @@
<?php

namespace Lc\CaracoleBundle\Builder\Reduction;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Factory\Reduction\ReductionCreditFactory;
use Lc\CaracoleBundle\Model\Config\TaxRateModel;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\CaracoleBundle\Solver\User\UserSolver;
use Lc\SovBundle\Notification\MailMailjetNotification;

class ReductionCreditBuilder
{
protected EntityManagerInterface $entityManager;
protected OrderProductStore $orderProductStore;
protected ReductionCreditFactory $reductionCreditFactory;
protected PriceSolver $priceSolver;
protected MailMailjetNotification $mailMailjetNotification;
protected UserSolver $userSolver;
protected SectionStore $sectionStore;

public function __construct(
EntityManagerInterface $entityManager,
OrderProductStore $orderProductStore,
ReductionCreditFactory $reductionCreditFactory,
PriceSolver $priceSolver,
MailMailjetNotification $mailMailjetNotification,
UserSolver $userSolver,
SectionStore $sectionStore
) {
$this->entityManager = $entityManager;
$this->orderProductStore = $orderProductStore;
$this->reductionCreditFactory = $reductionCreditFactory;
$this->priceSolver = $priceSolver;
$this->mailMailjetNotification = $mailMailjetNotification;
$this->userSolver = $userSolver;
$this->sectionStore = $sectionStore;
}

// generateReductionGiftFormOrderShop
public function createReductionGiftFormOrderShop(OrderShopInterface $orderShop)
{
$user = $orderShop->getUser();
$orderProductsGiftVouchers = $this->orderProductStore->getGiftVouchersByOrder($orderShop);

$sectionMarket = $this->sectionStore
->setMerchant($orderShop->getSection()->getMerchant())
->getOneMarket();

foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) {
$i = 1;

// création de la reductionCredit
while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) {
$reductionGift = $this->reductionCreditFactory->create($sectionMarket, ReductionCreditModel::TYPE_GIFT);
$reductionGift->setTitle($orderProductsGiftVoucher->getTitle());
$reductionGift->setOwner($user);
$reductionGift->setCreatedBy($user);
$reductionGift->setUpdatedBy($user);
$reductionGift->setValue($this->priceSolver->getPriceWithTax($orderProductsGiftVoucher->getProduct()));
$reductionGift->setBehaviorTaxRate(TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED);
$this->entityManager->persist($reductionGift);

$i++;
}
}
$this->entityManager->flush();

if (count($orderProductsGiftVouchers) > 0) {
$this->mailMailjetNotification->send([
MailMailjetNotification::SUBJECT => 'Comment offrir votre bon cadeau ?',
MailMailjetNotification::TO_EMAIL => $user->getEmail(),
MailMailjetNotification::TO_NAME => $this->userSolver->getName($user),
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/how-to-offer-gift-voucher'
]);
}
}
}

+ 0
- 1
CaracoleBundle 查看文件

@@ -1 +0,0 @@
CaracoleBundle

+ 9
- 0
Container/Merchant/MerchantContainer.php 查看文件

@@ -7,11 +7,13 @@ use Lc\CaracoleBundle\Factory\Merchant\MerchantFactory;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Solver\Merchant\MerchantSolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;

class MerchantContainer
{
protected MerchantFactory $factory;
protected MerchantSolver $solver;
protected MerchantBuilder $builder;
protected MerchantResolver $resolver;
protected MerchantRepositoryQuery $repositoryQuery;
@@ -19,12 +21,14 @@ class MerchantContainer

public function __construct(
MerchantFactory $factory,
MerchantSolver $solver,
MerchantBuilder $builder,
MerchantResolver $resolver,
MerchantRepositoryQuery $repositoryQuery,
MerchantStore $store
) {
$this->factory = $factory;
$this->solver = $solver;
$this->builder = $builder;
$this->resolver = $resolver;
$this->repositoryQuery = $repositoryQuery;
@@ -36,6 +40,11 @@ class MerchantContainer
return $this->factory;
}

public function getSolver(): MerchantSolver
{
return $this->solver;
}

public function getResolver(): MerchantResolver
{
return $this->resolver;

+ 4
- 1
Factory/Reduction/ReductionCreditFactory.php 查看文件

@@ -6,17 +6,20 @@ use App\Entity\Reduction\ReductionCredit;
use Lc\CaracoleBundle\Context\MerchantContextTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Factory\AbstractFactory;

class ReductionCreditFactory extends AbstractFactory
{

public function create(SectionInterface $section): ReductionCreditInterface
public function create(SectionInterface $section, string $type = ReductionCreditModel::TYPE_CREDIT): ReductionCreditInterface
{
$reductionCredit = new ReductionCredit();

$reductionCredit->setSection($section);
$reductionCredit->setType($type);
$reductionCredit->setStatus(1);

return $reductionCredit;
}

+ 13
- 1
Repository/Order/OrderProductStore.php 查看文件

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Repository\Order;

use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
@@ -38,7 +39,18 @@ class OrderProductStore extends AbstractStore
return $query;
}

//findOrderProductsInCartsByProduct
// findGiftVouchersByOrder
public function getGiftVouchersByOrder(OrderShopInterface $orderShop): array
{
$query = $this->createQuery();
$query
->filterByOrderShop($orderShop)
->filterIsGiftVoucherActive();

return $query->find();
}

// findOrderProductsInCartsByProduct
public function getInCartsByProduct(ProductInterface $product, $query = null): array
{
$query = $this->createDefaultQuery($query);

+ 19
- 0
Repository/Reduction/ReductionCreditRepositoryQuery.php 查看文件

@@ -13,6 +13,8 @@ class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
{
use SectionRepositoryQueryTrait;

protected $isJoinUsers = false;

public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
@@ -38,4 +40,21 @@ class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery
->andWhere('.type = :type')
->setParameter('type', $type);
}

public function filterInactive()
{
$this->joinUsers();
return $this->having('COUNT(users.id) = 0');
}

public function filterActive()
{
$this->joinUsers();
return $this->having('COUNT(users.id) > 0');
}

public function joinUsers()
{
return $this->leftJoin('.users', 'users');
}
}

+ 12
- 12
Repository/Reduction/ReductionCreditStore.php 查看文件

@@ -33,13 +33,8 @@ class ReductionCreditStore extends AbstractStore

public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
if($this->section) {
$query->filterBySection($this->section);
}

if(isset($this->merchant) && $this->merchant) {
$query->filterByMerchantViaSection($this->merchant);
}
$this->addFilterBySectionOptionnal($query);
$this->addFilterByMerchantViaSectionOptionnal($query);

$query->filterIsOnlineAndOffline();

@@ -66,7 +61,6 @@ class ReductionCreditStore extends AbstractStore
// findReductionGiftToUseByUser
public function getReductionGiftToUseByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByUser($user);
return $query->find();
@@ -75,18 +69,24 @@ class ReductionCreditStore extends AbstractStore
// findReductionGiftOwnedByUser
public function getReductionGiftOwnedByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByOwner($user);

$query
->filterByOwner($user)
->filterInactive();

return $query->find();
}

// findReductionGiftOwnedActiveByUser
public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null)
{
/// @TODO : à écrire
$query = $this->createDefaultQuery($query);
$query->filterByOwner($user);

$query
->filterByOwner($user)
->filterActive();

return $query->find();
}


+ 21
- 0
Solver/Merchant/MerchantSolver.php 查看文件

@@ -0,0 +1,21 @@
<?php

namespace Lc\CaracoleBundle\Solver\Merchant;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

class MerchantSolver
{
public function getNewsletters(MerchantInterface $merchant): array
{
$newsletterArray = [];

foreach($merchant->getSections() as $section) {
foreach($section->getNewsletters() as $newsletter) {
$newsletterArray[] = $newsletter;
}
}

return $newsletterArray;
}
}

Loading…
取消
儲存