소스 검색

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

Adaptation de la recherche des utilisateurs pour uniquement se baser sur UserPointSale
dev
부모
커밋
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…
취소
저장