瀏覽代碼

Liaison utilisateur/point de vente (UserPointSale) des données existantes via migration

Adaptation de la recherche des utilisateurs pour uniquement se baser sur UserPointSale
refactoring
Guillaume Bourgeois 5 年之前
父節點
當前提交
79249a86d3
共有 2 個文件被更改,包括 52 次插入10 次删除
  1. +1
    -10
      common/models/UserSearch.php
  2. +51
    -0
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php

+ 1
- 10
common/models/UserSearch.php 查看文件

@@ -90,16 +90,7 @@ class UserSearch extends User
if(isset($this->id_point_sale) && $this->id_point_sale) {
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ;
if($pointSale->restricted_access) {
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
else {
$query->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $this->id_point_sale]
)->groupBy('user.id') ;
}
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
if(isset($this->inactive) && $this->inactive) {

+ 51
- 0
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php 查看文件

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

use yii\db\Migration;

class m190226_084104_lien_utilisateur_point_de_vente extends Migration
{
public function up()
{
$producersArray = \common\models\Producer::find()->all() ;
foreach($producersArray as $producer) {
$pointsSaleArray = common\models\PointSale::find()
->where([
'id_producer' => $producer->id
])
->all();
foreach($pointsSaleArray as $pointSale) {
$usersArray = common\models\User::find()->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $pointSale->id]
)
->groupBy('user.id')
->all();
foreach($usersArray as $user) {
$userPointSale = \common\models\UserPointSale::find()
->where([
'id_user' => $user->id,
'id_point_sale' => $pointSale->id
])->one() ;
if(!$userPointSale) {
$userPointSale = new \common\models\UserPointSale() ;
$userPointSale->id_user = $user->id ;
$userPointSale->id_point_sale = $pointSale->id ;
$userPointSale->save() ;
}
}
}
}
}

public function down()
{
echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
return false;
}
}

Loading…
取消
儲存