소스 검색

Refactoring services #885

refactoring
Guillaume 1 년 전
부모
커밋
c08c85f9f6
10개의 변경된 파일225개의 추가작업 그리고 79개의 파일을 삭제
  1. +139
    -0
      common/components/BusinessLogicContainerTrait.php
  2. +5
    -3
      common/controllers/CommonController.php
  3. +12
    -0
      common/logic/PointSale/PointSale/PointSaleRepository.php
  4. +19
    -0
      common/logic/Product/Product/ProductRepository.php
  5. +1
    -1
      common/logic/Product/ProductCategory/ProductCategory.php
  6. +1
    -1
      common/logic/Product/ProductCategory/ProductCategoryRepository.php
  7. +7
    -0
      common/logic/Subscription/Subscription/SubscriptionBuilder.php
  8. +5
    -17
      producer/controllers/OrderController.php
  9. +7
    -31
      producer/controllers/SiteController.php
  10. +29
    -26
      producer/controllers/SubscriptionController.php

+ 139
- 0
common/components/BusinessLogicContainerTrait.php 파일 보기

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

namespace common\components;

use common\logic\Config\TaxRate\TaxRateContainer;
use common\logic\Distribution\Distribution\DistributionContainer;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer;
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer;
use common\logic\Document\Document\DocumentContainer;
use common\logic\Order\Order\OrderContainer;
use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer;
use common\logic\Order\ProductOrder\ProductOrderContainer;
use common\logic\PointSale\PointSale\PointSaleContainer;
use common\logic\Producer\Producer\ProducerContainer;
use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer;
use common\logic\Product\Product\ProductContainer;
use common\logic\Product\ProductCategory\ProductCategoryContainer;
use common\logic\Product\ProductPointSale\ProductPointSaleContainer;
use common\logic\Product\ProductPrice\ProductPriceContainer;
use common\logic\Subscription\ProductSubscription\ProductSubscriptionContainer;
use common\logic\Subscription\Subscription\SubscriptionContainer;
use common\logic\User\CreditHistory\CreditHistoryContainer;
use common\logic\User\User\UserContainer;
use common\logic\User\UserGroup\UserGroupContainer;
use common\logic\User\UserProducer\UserProducerContainer;
use common\logic\User\UserUserGroup\UserUserGroupContainer;

trait BusinessLogicContainerTrait
{
public function getUserContainer(): UserContainer
{
return new UserContainer();
}

public function getProducerContainer(): ProducerContainer
{
return new ProducerContainer();
}

public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer
{
return new ProducerPriceRangeContainer();
}

public function getUserProducerContainer(): UserProducerContainer
{
return new UserProducerContainer();
}

public function getCreditHistoryContainer(): CreditHistoryContainer
{
return new CreditHistoryContainer();
}

public function getDocumentContainer(): DocumentContainer
{
return new DocumentContainer();
}

public function getUserGroupContainer(): UserGroupContainer
{
return new UserGroupContainer();
}

public function getUserUserGroupContainer(): UserUserGroupContainer
{
return new UserUserGroupContainer();
}

public function getDistributionContainer(): DistributionContainer
{
return new DistributionContainer();
}

public function getTaxRateContainer(): TaxRateContainer
{
return new TaxRateContainer();
}

public function getOrderContainer(): OrderContainer
{
return new OrderContainer();
}

public function getOrderSatusHistoryContainer(): OrderStatusHistoryContainer
{
return new OrderStatusHistoryContainer();
}

public function getPointSaleContainer(): PointSaleContainer
{
return new PointSaleContainer();
}

public function getProductOrderContainer(): ProductOrderContainer
{
return new ProductOrderContainer();
}

public function getProductContainer(): ProductContainer
{
return new ProductContainer();
}

public function getProductCategoryContainer(): ProductCategoryContainer
{
return new ProductCategoryContainer();
}

public function getProductPointSaleContainer(): ProductPointSaleContainer
{
return new ProductPointSaleContainer();
}

public function getProductPriceContainer(): ProductPriceContainer
{
return new ProductPriceContainer();
}

public function getSubscriptionContainer(): SubscriptionContainer
{
return new SubscriptionContainer();
}

public function getProductSubscriptionContainer(): ProductSubscriptionContainer
{
return new ProductSubscriptionContainer();
}

public function getPointSaleDistributionContainer(): PointSaleDistributionContainer
{
return new PointSaleDistributionContainer();
}

public function getProductDistributionContainer(): ProductDistributionContainer
{
return new ProductDistributionContainer();
}
}

+ 5
- 3
common/controllers/CommonController.php 파일 보기

@@ -39,15 +39,17 @@ termes.
namespace common\controllers;

use common\components\BusinessLogic;
use common\logic\User\User\User;
use common\components\BusinessLogicContainerTrait;
use yii;

class CommonController extends \yii\web\Controller
{
use BusinessLogicContainerTrait;

public function beforeAction($event)
{
if (!Yii::$app->user->isGuest) {
$this->getLogic()->getUserContainer()->getBuilder()->updateLastConnection(Yii::$app->user->identity);
$this->getUserContainer()->getBuilder()->updateLastConnection(Yii::$app->user->identity);
}

return parent::beforeAction($event);
@@ -80,7 +82,7 @@ class CommonController extends \yii\web\Controller

public function isUserCurrentAdmin()
{
return $this->getLogic()->getUserContainer()->getSolver()->isAdmin($this->getUserCurrent());
return $this->getUserContainer()->getSolver()->isAdmin($this->getUserCurrent());
}

public function getRequest()

+ 12
- 0
common/logic/PointSale/PointSale/PointSaleRepository.php 파일 보기

@@ -53,6 +53,18 @@ class PointSaleRepository extends BaseService implements RepositoryInterface
->all();;
}

public function queryPublic(Producer $producer)
{
return PointSale::find()
->where([
'id_producer' => $producer->id,
'restricted_access' => 0,
'status' => 1
])->orderBy(
'code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC'
);
}

public function populateDropdownList()
{
$pointSalesArrayDropdown = ['' => '--'];

+ 19
- 0
common/logic/Product/Product/ProductRepository.php 파일 보기

@@ -6,6 +6,7 @@ use common\helpers\GlobalParam;
use common\logic\BaseService;
use common\logic\Distribution\Distribution\Distribution;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\ProductCategory\ProductCategory;
use common\logic\Product\ProductPrice\ProductPriceSolver;
use common\logic\RepositoryInterface;
use common\logic\User\User\User;
@@ -117,4 +118,22 @@ class ProductRepository extends BaseService implements RepositoryInterface

return $priceArray;
}

public function queryByProductCategory(ProductCategory $productCategory)
{
return Product::find()
->andWhere([
'id_producer' => $productCategory->id_producer,
'active' => true,
])
->andWhere(
'product.id_product_category = :id_product_category'
)
->params(
[':id_product_category' => $productCategory->id]
)
->orderBy(
'order ASC'
);
}
}

+ 1
- 1
common/logic/Product/ProductCategory/ProductCategory.php 파일 보기

@@ -42,7 +42,7 @@ use common\helpers\GlobalParam;
use common\components\ActiveRecordCommon;

/**
* This is the model class for table "user_group".
* This is the model class for table "product_category".
*
*/
class ProductCategory extends ActiveRecordCommon

+ 1
- 1
common/logic/Product/ProductCategory/ProductCategoryRepository.php 파일 보기

@@ -20,7 +20,7 @@ class ProductCategoryRepository extends BaseService implements RepositoryInterfa

public function get()
{
return ProductCategory::find()->where('id_producer = ' . GlobalParam::getCurrentProducerId())->all();
return ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);
}

public function populateDropdownList()

+ 7
- 0
common/logic/Subscription/Subscription/SubscriptionBuilder.php 파일 보기

@@ -8,6 +8,7 @@ use common\logic\Distribution\Distribution\Distribution;
use common\logic\Distribution\Distribution\DistributionRepository;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Producer\Producer\Producer;
use common\logic\Subscription\ProductSubscription\ProductSubscription;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;

@@ -26,4 +27,10 @@ class SubscriptionBuilder extends BaseService implements BuilderInterface

return $subscription;
}

public function delete(Subscription $subscription): void
{
ProductSubscription::deleteAll(['id_subscription' => $id]);
$subscription->delete();
}
}

+ 5
- 17
producer/controllers/OrderController.php 파일 보기

@@ -45,6 +45,7 @@ use common\logic\User\CreditHistory\CreditHistory;
use common\logic\User\User\User;
use common\logic\User\UserProducer\UserProducer;
use DateTime;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;

class OrderController extends ProducerBaseController
@@ -54,17 +55,6 @@ class OrderController extends ProducerBaseController
public function behaviors()
{
return [];
/*return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
]
],
],
];*/
}

public function actionOrder($id = 0, $date = '')
@@ -74,7 +64,7 @@ class OrderController extends ProducerBaseController

if (\Yii::$app->user->isGuest && !$producer->option_allow_order_guest) {
return $this->redirect(
Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id])
$this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id])
);
}

@@ -107,9 +97,7 @@ class OrderController extends ProducerBaseController
}

/**
* Affiche l'historique des commandes de l'utilisateur
*
* @return ProducerView
* Affiche l'historique des commandes de l'utilisateur.
*/
public function actionHistory($type = 'incoming')
{
@@ -139,8 +127,8 @@ class OrderController extends ProducerBaseController

return $this->render('history', [
'dataProviderOrders' => $dataProviderOrders,
'orderOk' => Yii::$app->getRequest()->get('orderOk', false),
'cancelOk' => Yii::$app->getRequest()->get('cancelOk', false),
'orderOk' => \Yii::$app->getRequest()->get('orderOk', false),
'cancelOk' => \Yii::$app->getRequest()->get('cancelOk', false),
'type' => $type,
'countIncoming' => $queryIncoming->count(),
'countPassed' => $queryPassed->count(),

+ 7
- 31
producer/controllers/SiteController.php 파일 보기

@@ -40,9 +40,7 @@ namespace producer\controllers;

use common\forms\ContactForm;
use common\helpers\GlobalParam;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Product\Product\Product;
use common\logic\Product\ProductCategory\ProductCategory;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;

@@ -77,7 +75,7 @@ class SiteController extends ProducerBaseController
if ($exception !== null) {
if ($exception->getMessage() == 'Producteur introuvable') {
\Yii::$app->getResponse()->redirect(
\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true])
$this->getUrlManagerFrontend()->createAbsoluteUrl(['site/error', 'producer_not_found' => true])
)->send();
} else {
return $this->render('error', ['exception' => $exception]);
@@ -91,41 +89,19 @@ class SiteController extends ProducerBaseController
*/
public function actionIndex()
{
// points de vente
$dataProviderPointsSale = new ActiveDataProvider([
'query' => PointSale::find()
->where([
'id_producer' => $this->getProducer()->id,
'restricted_access' => 0,
'status' => 1
])->orderBy(
'code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC'
),
'query' => $this->getPointSaleContainer()->getRepostory()->queryPublic($this->getProducer()),
'pagination' => [
'pageSize' => 50,
],
'sort' => false,
]);

// produits
$categoriesArray = ProductCategory::searchAll([], ['orderby' => 'product_category.position ASC']);
$productCategoryArray = $this->getProductCategoryContainer()->getRepository()->get();
$dataProviderProductsByCategories = [];
foreach ($categoriesArray as $category) {
$dataProviderProductsByCategories[$category->id] = new ActiveDataProvider([
'query' => Product::find()
->andWhere([
'id_producer' => $this->getProducer()->id,
'active' => true,
])
->andWhere(
'product.id_product_category = :id_product_category'
)
->params(
[':id_product_category' => $category->id]
)
->orderBy(
'order ASC'
),
foreach ($productCategoryArray as $productCategory) {
$dataProviderProductsByCategories[$productCategory->id] = new ActiveDataProvider([
'query' => $this->getProductContainer()->getRepository()->queryByProductCategory($productCategory),
'pagination' => [
'pageSize' => 500,
],
@@ -175,7 +151,7 @@ class SiteController extends ProducerBaseController
'dataProviderProducts' => $dataProviderProducts,
'hasProductPhoto' => $hasProductPhoto,
'hasProductWeight' => $hasProductWeight,
'categories' => $categoriesArray,
'categories' => $productCategoryArray,
]);
}


+ 29
- 26
producer/controllers/SubscriptionController.php 파일 보기

@@ -90,7 +90,7 @@ class SubscriptionController extends ProducerBaseController

public function actionAjaxProcess()
{
$subscriptionRepository = $this->getLogic()->getSubscriptionContainer()->getRepository();
$subscriptionRepository = $this->getSubscriptionContainer()->getRepository();
$model = new SubscriptionForm();
$model->id_producer = GlobalParam::getCurrentProducerId();
$model->id_user = GlobalParam::getCurrentUserId();
@@ -111,7 +111,8 @@ class SubscriptionController extends ProducerBaseController
if ($model->load($posts) && $model->validate() && $model->save()) {

$subscription = $subscriptionRepository->getOneById($model->id);
$subscription->updateIncomingDistributions($isUpdate);
$this->getOrderContainer()->getBuilder()
->updateIncomingDistributions($subscription, $isUpdate);

if ($isUpdate) {
$this->setFlash('success', 'Abonnement modifié');
@@ -146,7 +147,7 @@ class SubscriptionController extends ProducerBaseController
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

$subscriptionRepository = $this->getLogic()->getSubscriptionContainer()->getRepository();
$subscriptionRepository = $this->getSubscriptionContainer()->getRepository();
$model = new SubscriptionForm;
$subscription = $subscriptionRepository->getOneById($id);

@@ -183,7 +184,7 @@ class SubscriptionController extends ProducerBaseController
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404);
}

$productsArray = $this->getLogic()->getProductContainer()->getRepository()->get();
$productsArray = $this->getProductContainer()->getRepository()->get();

if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
if (!strlen($model->date_end)) {
@@ -222,14 +223,17 @@ class SubscriptionController extends ProducerBaseController
{
if (\Yii::$app->user->isGuest) {
$producer = $this->getProducer();
return $this->redirect(\Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
return $this->redirect($this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $producer->id]));
}

$subscription = $this->getLogic()->getSubscriptionContainer()->getRepository()->getOneById($id);
ProductSubscription::deleteAll(['id_subscription' => $id]);
$subscription->deleteOrdersIncomingDistributions();
$subscription->delete();
\Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé');
$subscriptionContainer = $this->getSubscriptionContainer();
$subscription = $subscriptionContainer->getRepository()->getOneById($id);
$subscriptionContainer->getBuilder()->delete($subscription);

// @TODO : gérer via événements
$this->getOrderContainer()->getBuilder()->deleteOrdersIncomingDistributions($subscription);

$this->setFlash('success', 'Abonnement supprimé');

return $this->redirect(['subscription/index']);
}
@@ -238,13 +242,14 @@ class SubscriptionController extends ProducerBaseController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$params = [];
$productSolver = $this->getLogic()->getProductContainer()->getSolver();
$subscriptionRepositpry = $this->getLogic()->getSubscriptionContainer()->getRepository();
$productSolver = $this->getProductContainer()->getSolver();
$subscriptionRepositpry = $this->getSubscriptionContainer()->getRepository();
$user = GlobalParam::getCurrentUser();
$userProducer = UserProducer::searchOne([
'id_user' => GlobalParam::getCurrentUserId()
]);
$pointSale = false;
$userProducer = $this->getUserProducerContainer()->getRepository()->getOne(
GlobalParam::getCurrentUser(),
GlobalParam::getCurrentProducer()
);
$pointSale = null;

if ($idSubscription > 0) {
$arrayProductsSubscription = ProductSubscription::searchAll([
@@ -252,16 +257,14 @@ class SubscriptionController extends ProducerBaseController
]);

$subscription = $subscriptionRepositpry->getOneById($idSubscription);

if ($subscription) {
if ($subscription->id_point_sale) {
$pointSale = PointSale::findOne($subscription->id_point_sale);
}
if ($subscription && $subscription->id_point_sale) {
$pointSale = $this->getPointSaleContainer()->getRepostory()
->getOneById($subscription->id_point_sale);
}
}

// Produits
$productsArray = Product::searchAll();
$productsArray = $this->getProductContainer()->getRepository()->get();
$indexProduct = 0;
foreach ($productsArray as &$product) {
$quantity = 0;
@@ -293,8 +296,8 @@ class SubscriptionController extends ProducerBaseController
}

$params['products'] = $productsArray;
$pointsSaleArray = PointSale::searchAll();
$pointsSaleArray = $this->getPointSaleContainer()->getRepostory()->get();
foreach ($pointsSaleArray as &$pointSale) {
$pointSale = array_merge($pointSale->getAttributes(), [
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
@@ -326,9 +329,9 @@ class SubscriptionController extends ProducerBaseController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$pointSale = PointSale::findOne($idPointSale);
$pointSale = $this->getPointSaleContainer()->getRepostory()->getOneById($idPointSale);
if ($pointSale) {
if ($pointSale->validateCode($code)) {
if ($this->getPointSaleContainer()->getSolver()->validateCode($pointSale, $code)) {
return 1;
}
}

Loading…
취소
저장