瀏覽代碼

Refactoring repositories #1084

feature/souke
Guillaume Bourgeois 1 年之前
父節點
當前提交
5314dc10e8
共有 34 個檔案被更改,包括 205 行新增144 行删除
  1. +6
    -5
      backend/controllers/DistributionController.php
  2. +1
    -1
      backend/controllers/DocumentController.php
  3. +1
    -4
      backend/controllers/OrderController.php
  4. +4
    -3
      backend/controllers/UserController.php
  5. +1
    -1
      backend/views/user/_form.php
  6. +1
    -1
      backend/views/user/credit.php
  7. +1
    -1
      common/components/BusinessLogic.php
  8. +3
    -1
      common/logic/AbstractRepository.php
  9. +2
    -1
      common/logic/AbstractRepositoryQuery.php
  10. +1
    -1
      common/logic/Distribution/Distribution/Service/DistributionBuilder.php
  11. +34
    -7
      common/logic/Order/Order/Repository/OrderRepository.php
  12. +1
    -1
      common/logic/Order/Order/Service/OrderBuilder.php
  13. +3
    -1
      common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php
  14. +7
    -3
      common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepositoryQuery.php
  15. +5
    -6
      common/logic/Producer/Producer/Repository/ProducerRepository.php
  16. +1
    -1
      common/logic/Producer/Producer/Repository/ProducerRepositoryQuery.php
  17. +2
    -3
      common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php
  18. +2
    -1
      common/logic/Producer/ProducerPriceRange/Service/ProducerPriceRangeDefinition.php
  19. +1
    -1
      common/logic/Product/Product/Repository/ProductRepository.php
  20. +3
    -1
      common/logic/Product/Product/Repository/ProductRepositoryQuery.php
  21. +21
    -64
      common/logic/User/User/Repository/UserRepository.php
  22. +37
    -0
      common/logic/User/User/Repository/UserRepositoryQuery.php
  23. +8
    -4
      common/logic/User/UserGroup/Repository/UserGroupRepository.php
  24. +6
    -0
      common/logic/User/UserGroup/Repository/UserGroupRepositoryQuery.php
  25. +10
    -14
      common/logic/User/UserProducer/Repository/UserProducerRepository.php
  26. +19
    -0
      common/logic/User/UserProducer/Repository/UserProducerRepositoryQuery.php
  27. +2
    -2
      common/logic/User/UserProducer/Service/UserProducerBuilder.php
  28. +4
    -4
      common/logic/User/UserUserGroup/Repository/UserUserGroupRepository.php
  29. +7
    -0
      common/logic/User/UserUserGroup/Repository/UserUserGroupRepositoryQuery.php
  30. +2
    -2
      frontend/controllers/SiteController.php
  31. +1
    -0
      frontend/forms/SignupForm.php
  32. +2
    -2
      producer/controllers/CreditController.php
  33. +5
    -4
      producer/controllers/OrderController.php
  34. +1
    -4
      producer/controllers/SubscriptionController.php

+ 6
- 5
backend/controllers/DistributionController.php 查看文件

@@ -457,12 +457,13 @@ class DistributionController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$userManager = $this->getUserManager();
$orderManager = $this->getOrderManager();

$user = $userManager->findOneUserById($idUser);
$idFavoritePointSale = 0;

if($user) {
$favoritePointSale = $userManager->getUserFavoritePointSale($user);
$favoritePointSale = $orderManager->getUserFavoritePointSale($user);
if ($favoritePointSale) {
$idFavoritePointSale = $favoritePointSale->id;
}
@@ -548,7 +549,7 @@ class DistributionController extends BackendController
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {
$userProducer = null;
if ($order->id_user) {
$userProducer = $userProducerManager->findOneUserProducer($order->user, $this->getProducerCurrent());
$userProducer = $userProducerManager->findOneUserProducer($order->user);
}
foreach ($order->productOrder as $productOrder) {
$invoicePrice = $productManager->getPrice($productOrder->product, [
@@ -1609,7 +1610,7 @@ class DistributionController extends BackendController

// init invoice prices
$user = $userManager->findOneUserById($deliveryNote->id_user);
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent);
$userProducer = $userProducerManager->findOneUserProducer($user);
$orderManager->updateOrderInvoicePrices($order, [
'user' => $user,
'user_producer' => $userProducer,
@@ -1703,7 +1704,7 @@ class DistributionController extends BackendController
if ($firstOrder->pointSale->id_user) {
$deliveryNote->id_user = $firstOrder->pointSale->id_user;
$user = $userManager->findOneUserById($deliveryNote->id_user);
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent);
$userProducer = $userProducerManager->findOneUserProducer($user);
} else {
$user = new User();
$user->type = User::TYPE_LEGAL_PERSON;
@@ -1744,7 +1745,7 @@ class DistributionController extends BackendController

if (!isset($user) || !$user) {
$user = $userManager->findOneUserById($deliveryNote->id_user);
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent);
$userProducer = $userProducerManager->findOneUserProducer($user);
}

// affectation du BL aux commandes

+ 1
- 1
backend/controllers/DocumentController.php 查看文件

@@ -573,7 +573,7 @@ class DocumentController extends BackendController
);
}

$userProducer = $userProducerManager->findOneUserProducer($document->user, $this->getProducerCurrent());
$userProducer = $userProducerManager->findOneUserProducer($document->user);
$pointSale = $pointSaleManager->findOnePointSaleByIdUser($document->user->id);

$productsArray = yii\helpers\ArrayHelper::map(

+ 1
- 4
backend/controllers/OrderController.php 查看文件

@@ -821,10 +821,7 @@ class OrderController extends BackendController
if (isset($order->user) && $order->user) {
$user = $order->user;

$userProducer = $userProducerManager->findOneUserProducer(
$user,
$producerManager->findOneProducerById($order->distribution->id_producer)
);
$userProducer = $userProducerManager->findOneUserProducer($user);
}

foreach ($products as $key => $dataProductOrder) {

+ 4
- 3
backend/controllers/UserController.php 查看文件

@@ -146,7 +146,7 @@ class UserController extends BackendController
$model->user_groups[] = $userUserGroup->id_user_group;
}
}
$userProducer = $userProducerManager->findOneUserProducer($model, $producerCurrent);
$userProducer = $userProducerManager->findOneUserProducer($model);
$model->product_price_percent = $userProducer->product_price_percent;
}

@@ -178,6 +178,7 @@ class UserController extends BackendController
{
$userManager = $this->getUserManager();
$producerManager = $this->getProducerManager();
$pointSaleManager = $this->getPointSaleManager();

$producerCurrent = $this->getProducerCurrent();
$model = $userManager->instanciateUser();
@@ -374,7 +375,7 @@ class UserController extends BackendController

$user = $userManager->findOneUserById($id);
$producer = $this->getProducerCurrent();
$userProducer = $userProducerManager->findOneUserProducer($user, $producer);
$userProducer = $userProducerManager->findOneUserProducer($user);

if ($userProducer) {
$userProducer->active = 0;
@@ -552,7 +553,7 @@ class UserController extends BackendController

$user = $userManager->findOneUserById($idUser);
$producerCurrent = $this->getproducerCurrent();
$userProducer = $userProducerManager->findOneUserProducer($user,$producerCurrent);
$userProducer = $userProducerManager->findOneUserProducer($user);

if ($userProducer) {
$userProducer->credit_active = $state;

+ 1
- 1
backend/views/user/_form.php 查看文件

@@ -102,7 +102,7 @@ $producerManager = $this->getProducerManager();

<div class="col-md-4">

<?php if($pointSaleBillingArray && count($pointSaleBillingArray) > 0): ?>
<?php if(isset($pointSaleBillingArray) && $pointSaleBillingArray && count($pointSaleBillingArray) > 0): ?>
<h3>Facturation</h3>
<?php foreach($pointSaleBillingArray as $pointSale): ?>
<a href="<?= Yii::$app->urlManager->createUrl(['point-sale/update', 'id' => $pointSale->id]) ?>"><?= $pointSale->name ?></a><br />

+ 1
- 1
backend/views/user/credit.php 查看文件

@@ -112,7 +112,7 @@ $this->addBreadcrumb('Créditer') ;
</div>
<div class="col-md-8">
<h2>Historique <span class="the-credit"><?= number_format($userManager->getCredit($user, $producer), 2); ?> €</span></h2>
<h2>Historique <span class="the-credit"><?= number_format($userManager->getCredit($user), 2); ?> €</span></h2>
<table class="table table-bordered">
<thead>
<tr>

+ 1
- 1
common/components/BusinessLogic.php 查看文件

@@ -18,6 +18,7 @@ class BusinessLogic
$this->getCreditHistoryContainer(),
$this->getProducerPriceRangeContainer(),
$this->getUserProducerContainer(),
$this->getUserPointSaleContainer(),
$this->getUserContainer(),
$this->getOrderSatusHistoryContainer(),
$this->getPointSaleDistributionContainer(),
@@ -27,7 +28,6 @@ class BusinessLogic
$this->getProductOrderContainer(),
$this->getProductPriceContainer(),
$this->getProductSubscriptionContainer(),
$this->getUserPointSaleContainer(),
$this->getQuotationContainer(),
$this->getInvoiceContainer(),
$this->getDeliveryNoteContainer(),

+ 3
- 1
common/logic/AbstractRepository.php 查看文件

@@ -16,7 +16,9 @@ abstract class AbstractRepository extends AbstractService implements RepositoryI

public function createQuery()
{
return $this->query->createQuery();
$this->query->createQuery();

return $this->query;
}

public function createDefaultQuery(): RepositoryQueryInterface

+ 2
- 1
common/logic/AbstractRepositoryQuery.php 查看文件

@@ -60,7 +60,8 @@ abstract class AbstractRepositoryQuery extends AbstractService implements Reposi

public function filterById(int $id): self
{
$this->query->andWhere(['id' => $id]);
$class = $this->definition->getEntityFqcn();
$this->query->andWhere([$class::tableName().'.id' => $id]);

return $this;
}

+ 1
- 1
common/logic/Distribution/Distribution/Service/DistributionBuilder.php 查看文件

@@ -163,7 +163,7 @@ class DistributionBuilder extends AbstractBuilder
$userProducer = null;
if (isset($order->user) && $order->user) {
$user = $order->user;
$userProducer = $this->userProducerRepository->findOneUserProducer($user, $distribution->producer);
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
}

$this->productOrderBuilder->updateProductOrderPrice(

+ 34
- 7
common/logic/Order/Order/Repository/OrderRepository.php 查看文件

@@ -2,23 +2,22 @@

namespace common\logic\Order\Order\Repository;

use common\helpers\GlobalParam;
use common\helpers\MeanPayment;
use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderBuilder;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Order\ProductOrder\Repository\ProductOrderRepository;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\PointSale\UserPointSale\Repository\UserPointSaleRepository;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserProducer\Repository\UserProducerRepository;
use yii\helpers\Html;

@@ -33,6 +32,7 @@ class OrderRepository extends AbstractRepository
protected UserProducerRepository $userProducerRepository;
protected DistributionRepository $distributionRepository;
protected PointSaleRepository $pointSaleRepository;
protected UserPointSaleRepository $userPointSaleRepository;

public function loadDependencies(): void
{
@@ -45,6 +45,7 @@ class OrderRepository extends AbstractRepository
$this->userProducerRepository = $this->loadService(UserProducerRepository::class);
$this->distributionRepository = $this->loadService(DistributionRepository::class);
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
$this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class);
}

public function getDefaultOptionsSearch(): array
@@ -281,10 +282,7 @@ class OrderRepository extends AbstractRepository
return 0;
}
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$userProducer = $this->userProducerRepository->findOneUserProducer(
$order->user,
$distribution->producer
);
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user);
if ($userProducer) {
return $userProducer->credit_active;
}
@@ -294,4 +292,33 @@ class OrderRepository extends AbstractRepository

return 0;
}

public function findOneOrderLastByUser(User $user)
{
return $this->createDefaultQuery()
->filterByUser($user)
->orderBy('order.id DESC')
->findOne();
}

/**
* Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié,
* le point de vente de la dernière commande sinon.
*/
public function getUserFavoritePointSale(User $user): ?PointSale
{
$pointSale = null;
$arrayUserPointSale = $this->userPointSaleRepository->findUserPointSalesByUser($user);

if (count($arrayUserPointSale) == 1) {
$pointSale = $this->pointSaleRepository->findOnePointSaleById($arrayUserPointSale[0]->id_point_sale);
} else {
$lastOrder = $this->findOneOrderLastByUser($user);
if ($lastOrder) {
$pointSale = $this->pointSaleRepository->findOnePointSaleById($lastOrder->id_point_sale);
}
}

return $pointSale;
}
}

+ 1
- 1
common/logic/Order/Order/Service/OrderBuilder.php 查看文件

@@ -297,7 +297,7 @@ class OrderBuilder extends AbstractBuilder
$order->auto_payment = 1;
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {

$userProducer = $this->userProducerRepository->findOneUserProducer($order->user, $subscription->producer);
$userProducer = $this->userProducerRepository->findOneUserProducer($order->user);

if ($userProducer) {
$order->auto_payment = $userProducer->credit_active;

+ 3
- 1
common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php 查看文件

@@ -22,13 +22,14 @@ class UserPointSaleRepository extends AbstractRepository
self::WITH => [],
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ATTRIBUTE_ID_PRODUCER => ''
self::ATTRIBUTE_ID_PRODUCER => 'point_sale.id_producer'
] ;
}

public function findUserPointSalesByUser(User $user): array
{
return $this->createDefaultQuery()
->joinPointSale()
->filterByUser($user)
->find();
}
@@ -40,6 +41,7 @@ class UserPointSaleRepository extends AbstractRepository
}

return $this->createDefaultQuery()
->joinPointSale()
->filterByUser($user)
->filterByPointSale($pointSale)
->findOne();

+ 7
- 3
common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepositoryQuery.php 查看文件

@@ -18,17 +18,21 @@ class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery
$this->loadDefinition(UserPointSaleDefinition::class);
}

public function filterByUser(User $user): self
public function joinPointSale(): self
{
$this->andWhere(['id_user' => $user->id]);
$this->innerJoinWith('pointSale', true);
return $this;
}

public function filterByUser(User $user): self
{
$this->andWhere(['user_point_sale.id_user' => $user->id]);
return $this;
}

public function filterByPointSale(PointSale $pointSale): self
{
$this->andWhere(['id_point_sale' => $pointSale->id]);

return $this;
}
}

+ 5
- 6
common/logic/Producer/Producer/Repository/ProducerRepository.php 查看文件

@@ -46,22 +46,21 @@ class ProducerRepository extends AbstractRepository

public function findOneProducerById(int $id)
{
return $this->createDefaultQuery()
return $this->createQuery()
->filterById($id)
->findOne();
}

public function findOneProducerBySlug(string $slug)
{
return $this->createDefaultQuery()
return $this->createQuery()
->filterBySlug($slug)
->findOne();
}

public function queryProducersActive()
{
return $this->createDefaultQuery()
->filterIsActive();
return $this->createQuery()->filterIsActive();
}

/**
@@ -69,7 +68,7 @@ class ProducerRepository extends AbstractRepository
*/
public function findOneProducerDemoAccount()
{
return $this->createDefaultQuery()
return $this->createQuery()
->filterIsDemoAccount()
->findOne();
}
@@ -79,7 +78,7 @@ class ProducerRepository extends AbstractRepository
*/
public function populateProducerDropdown(): array
{
return $this->createDefaultQuery()
$producers = $this->createQuery()
->filterIsActive()
->orderBy('postcode, city ASC')
->find();

+ 1
- 1
common/logic/Producer/Producer/Repository/ProducerRepositoryQuery.php 查看文件

@@ -16,7 +16,7 @@ class ProducerRepositoryQuery extends AbstractRepositoryQuery
$this->loadDefinition(ProducerDefinition::class);
}

public function filterBySlug(int $slug): self
public function filterBySlug(string $slug): self
{
$this->andWhere(['slug' => $slug]);
return $this;

+ 2
- 3
common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php 查看文件

@@ -37,13 +37,12 @@ class ProducerPriceRangeRepository extends AbstractRepository

public function queryProducerPriceRanges()
{
return $this->createDefaultQuery()
->find();
return $this->createDefaultQuery();
}

public function findProducerPriceRanges()
{
return $this->queryProducerPriceRanges()->all();
return $this->queryProducerPriceRanges()->find();
}

public function getAmountToBeBilledByTurnover(float $turnover = null, $format = false)

+ 2
- 1
common/logic/Producer/ProducerPriceRange/Service/ProducerPriceRangeDefinition.php 查看文件

@@ -3,11 +3,12 @@
namespace common\logic\Producer\ProducerPriceRange\Service;

use common\logic\AbstractDefinition;
use common\logic\Producer\ProducerPriceRange\Model\ProducerPriceRange;

class ProducerPriceRangeDefinition extends AbstractDefinition
{
public function getEntityFqcn(): string
{
return ProducerPriceRangeDefinition::class;
return ProducerPriceRange::class;
}
}

+ 1
- 1
common/logic/Product/Product/Repository/ProductRepository.php 查看文件

@@ -105,7 +105,7 @@ class ProductRepository extends AbstractRepository
$priceArray = [];
$userProducer = null;
if ($user) {
$userProducer = $this->userProducerRepository->findOneUserProducer($user, GlobalParam::getCurrentProducer());
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
}

// specific prices

+ 3
- 1
common/logic/Product/Product/Repository/ProductRepositoryQuery.php 查看文件

@@ -36,7 +36,9 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery

public function filterByProductCategory(ProductCategory $productCategory = null) : self
{
$this->andWhere(['product.id_product_category' => $productCategory->id]);
if($productCategory) {
$this->andWhere(['product.id_product_category' => $productCategory->id]);
}
return $this;
}
}

+ 21
- 64
common/logic/User/User/Repository/UserRepository.php 查看文件

@@ -4,15 +4,11 @@ namespace common\logic\User\User\Repository;

use common\helpers\GlobalParam;
use common\logic\AbstractRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserSolver;
use common\logic\User\UserGroup\Model\UserGroup;
use common\logic\User\UserProducer\Repository\UserProducerRepository;
use common\logic\User\UserUserGroup\Model\UserUserGroup;
use yii\db\Query;

class UserRepository extends AbstractRepository
@@ -45,7 +41,9 @@ class UserRepository extends AbstractRepository

public function findOneUserById($id)
{
return User::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findUsers(): array
@@ -65,50 +63,13 @@ class UserRepository extends AbstractRepository
return $usersArrayDropdown;
}

/**
* Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié,
* le point de vente de la dernière commande sinon.
*
*/
public function getUserFavoritePointSale(User $user): ?PointSale
{
$arrayUserPointSale = UserPointSale::find()
->innerJoinWith('pointSale', true)
->where([
'user_point_sale.id_user' => $user->id,
'point_sale.id_producer' => GlobalParam::getCurrentProducerId()
])
->all();

if (count($arrayUserPointSale) == 1) {
$pointSale = PointSale::findOne(['id' => $arrayUserPointSale[0]->id_point_sale]);
} else {
$lastOrder = Order::find()->innerJoinWith('pointSale', true)->where([
'order.id_user' => $user->id,
'point_sale.id_producer' => GlobalParam::getCurrentProducerId()
])
->orderBy('order.id DESC')
->one();

if ($lastOrder) {
$pointSale = PointSale::findOne(['id' => $lastOrder->id_point_sale]);
}
}

if (isset($pointSale)) {
return $pointSale;
}

return null;
}

/**
* Retourne le crédit de l'utilisateur pour un producteur donné.
*
*/
public function getCredit(User $user, Producer $producer): float
public function getCredit(User $user): float
{
$userProducer = $this->userProducerRepository->findOneUserProducer($user, $producer);
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
return $userProducer ? $userProducer->credit : 0;
}

@@ -119,7 +80,6 @@ class UserRepository extends AbstractRepository
* @param array $params
* @return Query
*/
// findBy
public function queryUsersBy(array $params = [])
{
if (!isset($params['id_producer'])) {
@@ -202,49 +162,46 @@ class UserRepository extends AbstractRepository
/**
* Finds user by password reset token
*/
// getByPasswordResetToken
public function findOneUserByPasswordResetToken(string $token)
{
if (!$this->userSolver->isPasswordResetTokenValid($token)) {
return null;
}

return User::findOne([
'password_reset_token' => $token,
]);
return $this->createDefaultQuery()
->filterByPasswordResetToken($token)
->findOne();
}

/**
* Recherche un utilisateur via son adresse email.
*/
// getOneByEmail
public function findOneUserByEmail(string $email): ?User
{
return User::searchOne(['email' => $email]);
return $this->createDefaultQuery()
->filterByEmail($email)
->findOne();
}

// getOneByUsername
public function findOneUserByUsername(string $username): ?User
{
return User::searchOne(['username' => $username]);
return $this->createDefaultQuery()
->filterByUsername($username)
->findOne();
}

public function findUsersByProducer(Producer $producer)
{
return User::find()
->where([
'id_producer' => $producer->id,
'status' => User::STATUS_PRODUCER
])
->all();
return $this->createDefaultQuery()
->isStatusProducer()
->filterByProducer($producer)
->find();
}

public function findUsersByStatus(string $status)
{
return User::find()
->where([
'user.status' => $status
])
->all();
return $this->createDefaultQuery()
->filterByStatus($status)
->find();
}
}

+ 37
- 0
common/logic/User/User/Repository/UserRepositoryQuery.php 查看文件

@@ -3,6 +3,8 @@
namespace common\logic\User\User\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserDefinition;

class UserRepositoryQuery extends AbstractRepositoryQuery
@@ -13,4 +15,39 @@ class UserRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(UserDefinition::class);
}

public function filterByPasswordResetToken(string $token): self
{
$this->andWhere(['password_reset_token' => $token]);
return $this;
}

public function filterByEmail(string $email): self
{
$this->andWhere(['email' => $email]);
return $this;
}

public function filterByUsername(string $username): self
{
$this->andWhere(['username' => $username]);
return $this;
}

public function filterByProducer(Producer $producer): self
{
$this->andWhere(['user.id_producer' => $producer->id]);
return $this;
}

public function filterByStatus(string $status): self
{
$this->andWhere(['user.status' => $status]);
return $this;
}

public function isStatusProducer(): self
{
return $this->filterByStatus(User::STATUS_PRODUCER);
}
}

+ 8
- 4
common/logic/User/UserGroup/Repository/UserGroupRepository.php 查看文件

@@ -21,23 +21,27 @@ class UserGroupRepository extends AbstractRepository
self::WITH => [],
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ATTRIBUTE_ID_PRODUCER => ''
self::ATTRIBUTE_ID_PRODUCER => 'user_group.id_producer'
];
}

public function findOneUserGroupById(int $id)
{
return UserGroup::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOneUserGroupByName(string $name)
{
return UserGroup::searchOne(['name' => $name]);
return $this->createDefaultQuery()
->filterByName($name)
->findOne();
}

public function findUserGroups()
{
return UserGroup::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all();
return $this->createDefaultQuery()->find();
}

public function populateUserGroupDropdownList(): array

+ 6
- 0
common/logic/User/UserGroup/Repository/UserGroupRepositoryQuery.php 查看文件

@@ -15,4 +15,10 @@ class UserGroupRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(UserGroupDefinition::class);
}

public function filterByName(string $name): self
{
$this->andWhere(['name' => $name]);
return $this;
}
}

+ 10
- 14
common/logic/User/UserProducer/Repository/UserProducerRepository.php 查看文件

@@ -19,30 +19,26 @@ class UserProducerRepository extends AbstractRepository
public function getDefaultOptionsSearch(): array
{
return [
self::WITH => [],
self::WITH => ['producer'],
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ATTRIBUTE_ID_PRODUCER => 'user_producer.id_producer'
];
}

public function findOneUserProducer(User $user, Producer $producer)
public function findOneUserProducer(User $user)
{
return UserProducer::searchOne([
'id_user' => $user->id,
'user_producer.id_producer' => $producer->id
]);
return $this->createDefaultQuery()
->filterByUser($user)
->findOne();
}

public function findUserProducersByUser(User $user, bool $active = true, bool $bookmark = true)
{
return UserProducer::find()
->with(['producer'])
->where([
'id_user' => $user->id,
'active' => $active,
'bookmark' => $bookmark
])
->all();
return $this->createDefaultQuery()
->filterByUser($user)
->filterByActive($active)
->filterByBookmark($bookmark)
->find();
}
}

+ 19
- 0
common/logic/User/UserProducer/Repository/UserProducerRepositoryQuery.php 查看文件

@@ -3,6 +3,7 @@
namespace common\logic\User\UserProducer\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserProducer\Service\UserProducerDefinition;
use yii\db\ActiveQuery;
@@ -15,4 +16,22 @@ class UserProducerRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(UserProducerDefinition::class);
}

public function filterByUser(User $user): self
{
$this->andWhere(['id_user' => $user->id]);
return $this;
}

public function filterByActive(bool $active): self
{
$this->andWhere(['active' => $active]);
return $this;
}

public function filterByBookmark(bool $bookmark): self
{
$this->andWhere(['bookmark' => $bookmark]);
return $this;
}
}

+ 2
- 2
common/logic/User/UserProducer/Service/UserProducerBuilder.php 查看文件

@@ -54,13 +54,13 @@ class UserProducerBuilder extends AbstractBuilder

public function createUserProducerIfNotExist(User $user, Producer $producer, int $bookmark = 1): UserProducer
{
return $this->userProducerRepository->findOneUserProducer($user, $producer)
return $this->userProducerRepository->findOneUserProducer($user)
?? $this->createUserProducer($user, $producer, $bookmark);
}

public function updateCredit(CreditHistory $creditHistory): void
{
$userProducer = $this->userProducerRepository->findOneUserProducer($creditHistory->user, $creditHistory->producer);
$userProducer = $this->userProducerRepository->findOneUserProducer($creditHistory->user);

if ($userProducer) {
$oldCredit = $userProducer->getCredit();

+ 4
- 4
common/logic/User/UserUserGroup/Repository/UserUserGroupRepository.php 查看文件

@@ -22,13 +22,13 @@ class UserUserGroupRepository extends AbstractRepository
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ATTRIBUTE_ID_PRODUCER => ''
] ;
];
}

public function findUserUserGroupsByUser(User $user)
{
return UserUserGroup::searchAll([
'id_user' => $user->id
]);
return $this->createDefaultQuery()
->filterByUser($user)
->find();
}
}

+ 7
- 0
common/logic/User/UserUserGroup/Repository/UserUserGroupRepositoryQuery.php 查看文件

@@ -3,6 +3,7 @@
namespace common\logic\User\UserUserGroup\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\User\User\Model\User;
use common\logic\User\UserUserGroup\Model\UserUserGroup;
use common\logic\User\UserUserGroup\Service\UserUserGroupDefinition;
use yii\db\ActiveQuery;
@@ -15,4 +16,10 @@ class UserUserGroupRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(UserUserGroupDefinition::class);
}

public function filterByUser(User $user): self
{
$this->andWhere(['id_user' => $user->id]);
return $this;
}
}

+ 2
- 2
frontend/controllers/SiteController.php 查看文件

@@ -145,7 +145,7 @@ class SiteController extends FrontendController
public function getDataProviderPrices()
{
return new ActiveDataProvider([
'query' => $this->getProducerPriceRangeManager()->queryProducerPriceRanges(),
'query' => $this->getProducerPriceRangeManager()->queryProducerPriceRanges()->query(),
'pagination' => [
'pageSize' => 100,
],
@@ -158,7 +158,7 @@ class SiteController extends FrontendController
public function actionProducers()
{
$dataProviderProducers = new ActiveDataProvider([
'query' => $this->getProducerManager()->queryProducersActive(),
'query' => $this->getProducerManager()->queryProducersActive()->query(),
'pagination' => [
'pageSize' => 100,
],

+ 1
- 0
frontend/forms/SignupForm.php 查看文件

@@ -251,6 +251,7 @@ class SignupForm extends Model

if ($user->save() && $producer) {
// Liaison User / Producer
\Yii::$app->logic->setProducerContext($producer);
$producerManager->addUser($user, $producer);

// Envoi d'un email de bienvenue à l'utilisateur

+ 2
- 2
producer/controllers/CreditController.php 查看文件

@@ -92,7 +92,7 @@ class CreditController extends ProducerBaseController
$searchModel = new CreditHistorySearch();
$searchModel->id_user = GlobalParam::getCurrentUserId();
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
$userProducer = $this->getUserProducerManager()->findOneUserProducer(GlobalParam::getCurrentUser(), $producer);
$userProducer = $this->getUserProducerManager()->findOneUserProducer($this->getUserCurrent());

if (strlen($returnPayment)) {
if ($returnPayment == 'success') {
@@ -289,7 +289,7 @@ class CreditController extends ProducerBaseController
]
]);
} else {
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user, $producer);
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user);

Mailjet::sendMail([
'from_email' => $producerManager->getEmailOpendistrib($producer),

+ 5
- 4
producer/controllers/OrderController.php 查看文件

@@ -384,7 +384,7 @@ class OrderController extends ProducerBaseController
$errors = [];

if ($order->validate() && count($productsArray) && !$errorDate && !$errorPointSale) {
$userProducer = $userProducerManager->findOneUserProducer($user, $producer);
$userProducer = $userProducerManager->findOneUserProducer($user);
$pointSale = $pointSaleManager->findOnePointSaleById($order->id_point_sale);

$order->comment_point_sale = ($pointSale && strlen($pointSaleManager->getComment($pointSale))) ?
@@ -445,7 +445,7 @@ class OrderController extends ProducerBaseController
$credit = $producerManager->getConfig('credit');
$creditLimit = $producerManager->getConfig('credit_limit');
$creditFunctioning = $producerManager->getPointSaleCreditFunctioning($pointSale);
$creditUser = $userManager->getCredit($user, $producer);
$creditUser = $userManager->getCredit($user);
$order = $orderManager->findOneOrderById($order->id);
$orderManager->initOrder($order);
$amountRemaining = $orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING);
@@ -772,7 +772,7 @@ class OrderController extends ProducerBaseController
$user = GlobalParam::getCurrentUser();
if($user) {
$userProducer = $userProducerManager->findOneUserProducer($user, $producer);
$userProducer = $userProducerManager->findOneUserProducer($user);
if (!$userProducer) {
$userProducer = $producerManager->addUser($user, $producer);
}
@@ -795,6 +795,7 @@ class OrderController extends ProducerBaseController
$pointSaleManager = $this->getPointSaleManager();
$userManager = $this->getUserManager();
$producerManager = $this->getProducerManager();
$orderManager = $this->getOrderManager();

$user = GlobalParam::getCurrentUser();
$pointsSaleArray = PointSale::find();
@@ -867,7 +868,7 @@ class OrderController extends ProducerBaseController

$favoritePointSale = false;
if ($user) {
$favoritePointSale = $userManager->getUserFavoritePointSale($user);
$favoritePointSale = $orderManager->getUserFavoritePointSale($user);
}

if ($favoritePointSale) {

+ 1
- 4
producer/controllers/SubscriptionController.php 查看文件

@@ -242,10 +242,7 @@ class SubscriptionController extends ProducerBaseController
$productManager = $this->getProductManager();
$subscriptionManager = $this->getSubscriptionManager();
$user = GlobalParam::getCurrentUser();
$userProducer = $this->getUserProducerManager()->findOneUserProducer(
GlobalParam::getCurrentUser(),
GlobalParam::getCurrentProducer()
);
$userProducer = $this->getUserProducerManager()->findOneUserProducer($this->getUserCurrent());
$pointSale = null;

if ($idSubscription > 0) {

Loading…
取消
儲存