您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

56 行
1.8KB

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