Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

52 lines
1.7KB

  1. <?php
  2. use yii\db\Migration;
  3. class m190226_084104_lien_utilisateur_point_de_vente extends Migration
  4. {
  5. public function up()
  6. {
  7. $producersArray = \common\models\Producer::find()->all() ;
  8. foreach($producersArray as $producer) {
  9. $pointsSaleArray = common\models\PointSale::find()
  10. ->where([
  11. 'id_producer' => $producer->id
  12. ])
  13. ->all();
  14. foreach($pointsSaleArray as $pointSale) {
  15. $usersArray = common\models\User::find()->innerJoin(
  16. 'order',
  17. 'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
  18. [':id_point_sale' => $pointSale->id]
  19. )
  20. ->groupBy('user.id')
  21. ->all();
  22. foreach($usersArray as $user) {
  23. $userPointSale = \common\models\UserPointSale::find()
  24. ->where([
  25. 'id_user' => $user->id,
  26. 'id_point_sale' => $pointSale->id
  27. ])->one() ;
  28. if(!$userPointSale) {
  29. $userPointSale = new \common\models\UserPointSale() ;
  30. $userPointSale->id_user = $user->id ;
  31. $userPointSale->id_point_sale = $pointSale->id ;
  32. $userPointSale->save() ;
  33. }
  34. }
  35. }
  36. }
  37. }
  38. public function down()
  39. {
  40. echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
  41. return false;
  42. }
  43. }