Quellcode durchsuchen

Merge branch 'feature/gestion_dons_utilisateur' into dev

refactoring
Guillaume Bourgeois vor 5 Jahren
Ursprung
Commit
52bdd77400
10 geänderte Dateien mit 155 neuen und 13 gelöschten Zeilen
  1. +2
    -3
      backend/controllers/DistributionController.php
  2. +22
    -4
      backend/views/producer-admin/index.php
  3. +6
    -0
      backend/views/producer/update.php
  4. +24
    -0
      common/models/Distribution.php
  5. +3
    -1
      common/models/Producer.php
  6. +17
    -0
      common/models/Product.php
  7. +33
    -0
      console/migrations/m190205_160337_produit_don_distrib.php
  8. +17
    -0
      console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php
  9. +15
    -0
      console/migrations/m190205_170712_ajout_option_autoriser_don_plateforme.php
  10. +16
    -5
      producer/controllers/OrderController.php

+ 2
- 3
backend/controllers/DistributionController.php Datei anzeigen

@@ -114,9 +114,8 @@ class DistributionController extends BackendController
// products
$productsArray = Product::find()
->where([
'id_producer' => Producer::getId(),
])
->orWhere(['id_producer' => Producer::getId(),])
->orWhere(['id_producer' => 0,]) // produit "Don"
->joinWith(['productDistribution' => function($query) use($distribution) {
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ;
}])

+ 22
- 4
backend/views/producer-admin/index.php Datei anzeigen

@@ -40,6 +40,7 @@ use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;
use common\models\Producer ;
use common\models\Distribution ;

$this->setTitle('Producteurs') ;
$this->addBreadcrumb($this->getTitle()) ;
@@ -139,12 +140,29 @@ $this->addBreadcrumb($this->getTitle()) ;
}
],
[
'attribute' => 'Cours',
'label' => 'CA mois en cours',
'label' => 'Dons (mois précédent)',
'format' => 'raw',
'value' => function($model) {
$turnover = $model->getTurnover(date('Y-m')) ;
return 'CA : '.number_format($turnover,2).' €<br />' ;
$productGift = Product::getProductGift() ;
$distributionsArray = Distribution::find()
->where(['>=', 'distribution.date', date('Y-m-01', strtotime("-1 month"))])
->andWhere(['<=', 'distribution.date', date('Y-m-31', strtotime("-1 month"))])
->andWhere(['distribution.id_producer' => $model->id])
->with(['order','order.productOrder'])
->all() ;
$gifts = 0 ;
foreach($distributionsArray as $distribution) {
foreach($distribution->order as $order) {
foreach($order->productOrder as $productOrder) {
if($productOrder->id_product == $productGift->id) {
$gifts += $productOrder->quantity * $productGift->price ;
}
}
}
}
return Price::format($gifts) ;
}
],
],

+ 6
- 0
backend/views/producer/update.php Datei anzeigen

@@ -136,6 +136,12 @@ $this->addBreadcrumb($this->getTitle()) ;
<?= $form->field($model, 'order_infos')
->textarea(['rows' => 6])
->hint('Affichées au client lors de sa commande')?>
<?= $form->field($model, 'option_allow_user_gift')
->dropDownList([
0 => 'Non',
1 => 'Oui',
], []) ; ?>
</div>
</div>


+ 24
- 0
common/models/Distribution.php Datei anzeigen

@@ -189,6 +189,7 @@ class Distribution extends ActiveRecordCommon
$distribution->linkProduct($product) ;
}
}
$distribution->linkProductGift() ;
}
return $distribution ;
@@ -262,6 +263,29 @@ class Distribution extends ActiveRecordCommon
$productDistribution->save();
}
/**
* Lie le produit "Don" à la distribution
*/
public function linkProductGift()
{
$productGift = Product::getProductGift() ;
if($productGift) {
$productDistribution = ProductDistribution::searchOne([
'id_distribution' => $this->id,
'id_product' => $productGift->id
]) ;

if(!$productDistribution) {
$productDistribution = new ProductDistribution();
$productDistribution->id_distribution = $this->id;
$productDistribution->id_product = $productGift->id;
$productDistribution->active = 1;
$productDistribution->save() ;
}
}
}
/**
* Lie un point de vente aux jours de distribution futurs.
*

+ 3
- 1
common/models/Producer.php Datei anzeigen

@@ -58,6 +58,7 @@ use yii\helpers\Html;
* @property boolean online_payment
* @property string mentions
* @property string gcs
* @property boolean option_allow_user_gift
*/
class Producer extends ActiveRecordCommon
{
@@ -89,7 +90,7 @@ class Producer extends ActiveRecordCommon
}
}],
[['description','mentions','gcs','order_infos','slug','secret_key_payplug'], 'string'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription'], 'boolean'],
[['negative_balance', 'credit', 'active','online_payment','user_manage_subscription', 'option_allow_user_gift'], 'boolean'],
[['name', 'siret', 'logo', 'photo', 'postcode', 'city', 'code','type'], 'string', 'max' => 255],
[['free_price', 'credit_limit_reminder'], 'double'],
['free_price', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
@@ -126,6 +127,7 @@ class Producer extends ActiveRecordCommon
'user_manage_subscription' => 'Autoriser les utilisateurs à gérer leurs abonnements',
'mentions' => 'Mentions légales',
'gcs' => 'Conditions générales de vente',
'option_allow_user_gift' => 'Autoriser les utilisateurs à effectuer un don à la plateforme lors de leur commande',
];
}


+ 17
- 0
common/models/Product.php Datei anzeigen

@@ -199,5 +199,22 @@ class Product extends ActiveRecordCommon
{
return self::searchCount() ;
}
/**
* Retourne le produit "Don".
*
* @return Product
*/
public static function getProductGift()
{
$productGift = Product::find()
->where([
'product.id_producer' => 0
])
->andFilterWhere(['like','product.name','Don'])
->one() ;
return $productGift ;
}

}

+ 33
- 0
console/migrations/m190205_160337_produit_don_distrib.php Datei anzeigen

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

use yii\db\Migration;

class m190205_160337_produit_don_distrib extends Migration {

public function up() {
$this->insert('product', [
'name' => 'Don',
'description' => 'Don à la plateforme distrib',
'recipe' => '',
'active' => 1,
'photo' => null,
'price' => 1,
'weight' => null,
'monday' => 1,
'tuesday' => 1,
'wednesday' => 1,
'thursday' => 1,
'friday' => 1,
'saturday' => 1,
'sunday' => 1,
'quantity_max' => null,
'id_producer' => 0,
'sale_mode' => 'unit',
'order' => 1000,
]) ;
}

public function down() {
$this->delete('product', 'name = \'Don\' AND id_producer = 0') ;
}
}

+ 17
- 0
console/migrations/m190205_164612_ajout_produit_don_aux_distributions_existantes.php Datei anzeigen

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

use yii\db\Migration;

class m190205_164612_ajout_produit_don_aux_distributions_existantes extends Migration {

public function up() {
$distributionsArray = common\models\Distribution::find()->all() ;
foreach($distributionsArray as $distribution) {
$distribution->linkProductGift() ;
}
}

public function down() {
}
}

+ 15
- 0
console/migrations/m190205_170712_ajout_option_autoriser_don_plateforme.php Datei anzeigen

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

use yii\db\Migration;
use yii\db\mysql\Schema;

class m190205_170712_ajout_option_autoriser_don_plateforme extends Migration {

public function up() {
$this->addColumn('producer', 'option_allow_user_gift', Schema::TYPE_BOOLEAN.' DEFAULT 1') ;
}

public function down() {
$this->dropColumn('producer', 'option_allow_user_gift') ;
}
}

+ 16
- 5
producer/controllers/OrderController.php Datei anzeigen

@@ -534,11 +534,17 @@ class OrderController extends ProducerBaseController
]);
// Produits
$productsArray = Product::find()
->where([
'id_producer' => $this->getProducer()->id,
])
->joinWith(['productDistribution' => function($query) use($distribution) {
if(Producer::getConfig('option_allow_user_gift')) {
$productsArray = Product::find()
->orWhere(['id_producer' => $this->getProducer()->id,])
->orWhere(['id_producer' => 0,]) ; // produit "Don";
}
else {
$productsArray = Product::find()
->where(['id_producer' => $this->getProducer()->id,]) ;
}
$productsArray = $productsArray->joinWith(['productDistribution' => function($query) use($distribution) {
$query->andOnCondition('product_distribution.id_distribution = '.$distribution->id) ;
}])
->orderBy('product_distribution.active DESC, order ASC')
@@ -548,6 +554,10 @@ class OrderController extends ProducerBaseController
$indexProduct = 0 ;
foreach($productsArray as &$product) {
if(is_null($product['photo'])) {
$product['photo'] = '' ;
}
$quantityOrder = Order::getProductQuantity($product['id'], $ordersArray) ;
$product['quantity_ordered'] = $quantityOrder ;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder ;
@@ -566,6 +576,7 @@ class OrderController extends ProducerBaseController
$product['index'] = $indexProduct ++ ;
}
$json['products'] = $productsArray;
}

Laden…
Abbrechen
Speichern