You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.7KB

  1. <?php
  2. namespace domain\Communication\Email;
  3. use common\helpers\GlobalParam;
  4. use domain\_\AbstractResolver;
  5. use domain\Distribution\Distribution\Distribution;
  6. use domain\PointSale\PointSale\PointSale;
  7. use domain\Producer\Producer\Producer;
  8. use domain\User\User\UserRepository;
  9. class ContactListResolver extends AbstractResolver
  10. {
  11. protected UserRepository $userRepository;
  12. public function loadDependencies(): void
  13. {
  14. $this->userRepository = $this->loadService(UserRepository::class);
  15. }
  16. public function search(
  17. Producer $producer,
  18. Distribution $distribution = null,
  19. PointSale $pointSale = null,
  20. bool $usersPointSaleLink = false,
  21. bool $usersPointSaleHasOrder = false,
  22. bool $isSubscriber = false,
  23. bool $isInactive = false
  24. ): array
  25. {
  26. if ($pointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
  27. $usersPointSaleLink = 1;
  28. }
  29. if ($distribution && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
  30. $usersPointSaleLink = 1;
  31. }
  32. if($distribution) {
  33. $users = [];
  34. foreach($distribution->pointSaleDistribution as $pointSaleDistribution) {
  35. if($pointSaleDistribution->delivery) {
  36. $usersPointSaleArray = $this->userRepository->queryUsersBy([
  37. 'id_producer' => $producer->id,
  38. 'id_point_sale' => $pointSaleDistribution->id_point_sale,
  39. 'users_point_sale_link' => $usersPointSaleLink,
  40. 'users_point_sale_has_order' => $usersPointSaleHasOrder,
  41. 'newsletter' => true
  42. ])->all();
  43. foreach($usersPointSaleArray as $user) {
  44. $users[$user['id']] = $user;
  45. }
  46. }
  47. }
  48. }
  49. else {
  50. $users = $this->userRepository->queryUsersBy([
  51. 'id_producer' => $producer->id,
  52. 'id_point_sale' => $pointSale ? $pointSale->id : null,
  53. 'users_point_sale_link' => $usersPointSaleLink,
  54. 'users_point_sale_has_order' => $usersPointSaleHasOrder,
  55. 'subscribers' => $isSubscriber,
  56. 'inactive' => $isInactive,
  57. 'newsletter' => true
  58. ])->all();
  59. }
  60. $usersArray = [];
  61. foreach ($users as $user) {
  62. if (isset($user['email']) && strlen($user['email']) > 0) {
  63. if($producer->isDemoAccount()) {
  64. $user['email'] = \Yii::$app->faker->email();
  65. }
  66. $usersArray[] = $user;
  67. }
  68. }
  69. return $usersArray;
  70. }
  71. }