瀏覽代碼

[Backend] Abonnements : problème débit du crédit si point de vente supprimé #837

refactoring
Guillaume Bourgeois 1 年之前
父節點
當前提交
7ef2670718
共有 10 個文件被更改,包括 72 次插入12 次删除
  1. +29
    -4
      backend/controllers/PointSaleController.php
  2. +1
    -0
      backend/controllers/UserController.php
  3. +1
    -1
      backend/views/distribution/index.php
  4. +1
    -1
      backend/views/subscription/_form.php
  5. +4
    -0
      common/components/ActiveRecordCommon.php
  6. +2
    -1
      common/models/PointSale.php
  7. +5
    -3
      common/models/PointSaleSearch.php
  8. +26
    -0
      console/migrations/m230119_083942_point_sale_add_status.php
  9. +1
    -1
      producer/controllers/OrderController.php
  10. +2
    -1
      producer/controllers/SiteController.php

+ 29
- 4
backend/controllers/PointSaleController.php 查看文件

@@ -178,12 +178,37 @@ class PointSaleController extends BackendController
$pointSale = $this->findModel($id) ;
if($confirm) {
$pointSale->delete();
$pointSale->status = -1;
$pointSale->save();

// Suppression du lien entre les utilisateurs et le point de vente
UserPointSale::deleteAll(['id_point_sale' => $id]);
PointSaleDistribution::deleteAll(['id_point_sale' => $id]) ;
Order::updateAll(['id_point_sale' => 0], 'id_point_sale = :id_point_sale', [':id_point_sale' => $id]) ;

// Suppression du lien PointSaleDistribution pour toutes les distributions à venir
$incomingDistributions = Distribution::getIncomingDistributions();
foreach ($incomingDistributions as $distribution) {
PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]);
}

// Suppression de toutes les commandes à venir de ce point de vente
$ordersArray = Order::searchAll(
[
'id_point_sale' => $id,
],
[
'conditions' => 'date_delete IS NULL AND distribution.date > :today',
'params' => [':today' => date('Y-m-d')]
]
);

if($ordersArray) {
foreach($ordersArray as $order) {
$order->delete(true);
}
}

Yii::$app->getSession()->setFlash('success', 'Point de vente <strong>'.Html::encode($pointSale->name).'</strong> supprimé.');
}
}
else {
Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le point de vente <strong>'.Html::encode($pointSale->name).'</strong> ? '
. Html::a('Oui',['point-sale/delete','id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']).' '.Html::a('Non', ['point-sale/index'], ['class' => 'btn btn-default']));

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

@@ -154,6 +154,7 @@ class UserController extends BackendController
$pointsSaleArray = PointSale::find()
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
'status' => 1
])
->joinWith(['userPointSale' => function ($query) use ($model) {
if ($model->id) {

+ 1
- 1
backend/views/distribution/index.php 查看文件

@@ -175,7 +175,7 @@ $this->setPageTitle('Distributions') ;
</tr>
</thead>
<tbody>
<tr v-for="pointSale in pointsSale">
<tr v-for="pointSale in pointsSale" v-if="pointSale.status == 1">
<td>
<button class="btn btn-success" v-if="pointSale.pointSaleDistribution[0].delivery == 1"><span class="glyphicon glyphicon-ok"></span></button>
<button class="btn btn-default" v-else data-delivery-point-sale="1" :data-id-point-sale="pointSale.id" @click="pointSaleActiveClick"><span class="glyphicon glyphicon-ok"></span></button>

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

@@ -64,7 +64,7 @@ use common\helpers\GlobalParam ;
<div class="clr"></div>
<?= $form->field($model, 'id_producer')->hiddenInput() ?>
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSale::find()->where('id_producer = '.GlobalParam::getCurrentProducerId())->all(), 'id', function($model, $defaultValue) {
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSale::searchAll(), 'id', function($model, $defaultValue) {
return $model['name'];
}), ['prompt' => '--','class' => 'form-control user-id']) ?>
<?= $form->field($model, 'date_begin') ?>

+ 4
- 0
common/components/ActiveRecordCommon.php 查看文件

@@ -81,6 +81,10 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord
$options['type_search'] = self::SEARCH_ALL;
}

if($class == 'common\models\PointSale' && !isset($options['status'])) {
$params['status'] = 1;
}

$records = $class::find();

// With

+ 2
- 1
common/models/PointSale.php 查看文件

@@ -88,7 +88,7 @@ class PointSale extends ActiveRecordCommon
'delivery_wednesday', 'delivery_thursday', 'delivery_friday',
'delivery_saturday', 'delivery_sunday', 'default', 'is_bread_box'], 'boolean'],
['point_production', 'default', 'value' => 0],
[['id_producer', 'id_user', 'maximum_number_orders'], 'integer'],
[['id_producer', 'id_user', 'maximum_number_orders', 'status'], 'integer'],
['id_producer', 'required'],
[['users', 'users_comment', 'code'], 'safe'],
[['product_price_percent'], 'double'],
@@ -130,6 +130,7 @@ class PointSale extends ActiveRecordCommon
'maximum_number_orders' => 'Nombre maximum de commandes',
'is_bread_box' => 'Boîte à pain',
'bread_box_code' => 'Code boîte à pain',
'status' => 'Statut'
];
}


+ 5
- 3
common/models/PointSaleSearch.php 查看文件

@@ -69,9 +69,11 @@ class PointSaleSearch extends PointSale
$query = PointSale::find()
->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true)
->where(['point_sale.id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('is_bread_box ASC, name ASC')
;
->where([
'status' => 1,
'point_sale.id_producer' => GlobalParam::getCurrentProducerId()
])
->orderBy('is_bread_box ASC, name ASC');
$dataProvider = new ActiveDataProvider([
'query' => $query,

+ 26
- 0
console/migrations/m230119_083942_point_sale_add_status.php 查看文件

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

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

/**
* Class m230119_083942_point_sale_add_status
*/
class m230119_083942_point_sale_add_status extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('point_sale', 'status', Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('point_sale', 'status');
}
}

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

@@ -955,7 +955,7 @@ class OrderController extends ProducerBaseController

$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer])
->andWhere(
'restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0)'
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))'
)
->params([':id_user' => User::getCurrentId()])
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')

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

@@ -98,7 +98,8 @@ class SiteController extends ProducerBaseController
->where([
'id_producer' => $this->getProducer(
)->id,
'restricted_access' => 0
'restricted_access' => 0,
'status' => 1
])->orderBy(
'default DESC, is_bread_box ASC, name ASC'
),

Loading…
取消
儲存