Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

84 linhas
2.8KB

  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. string $newsletterType = null,
  19. Distribution $distribution = null,
  20. PointSale $pointSale = null,
  21. bool $usersPointSaleLink = false,
  22. bool $usersPointSaleHasOrder = false,
  23. bool $isSubscriber = false,
  24. bool $isInactive = false
  25. ): array
  26. {
  27. if ($pointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
  28. $usersPointSaleLink = 1;
  29. }
  30. if ($distribution && !$usersPointSaleLink && !$usersPointSaleHasOrder) {
  31. $usersPointSaleLink = 1;
  32. }
  33. if($distribution) {
  34. $users = [];
  35. foreach($distribution->pointSaleDistribution as $pointSaleDistribution) {
  36. if($pointSaleDistribution->delivery) {
  37. $usersPointSaleArray = $this->userRepository->queryUsersBy([
  38. 'id_producer' => $producer->id,
  39. 'id_point_sale' => $pointSaleDistribution->id_point_sale,
  40. 'users_point_sale_link' => $usersPointSaleLink,
  41. 'users_point_sale_has_order' => $usersPointSaleHasOrder,
  42. 'newsletter_type' => $newsletterType,
  43. 'newsletter' => true
  44. ])->all();
  45. foreach($usersPointSaleArray as $user) {
  46. $users[$user['id']] = $user;
  47. }
  48. }
  49. }
  50. }
  51. else {
  52. $users = $this->userRepository->queryUsersBy([
  53. 'id_producer' => $producer->id,
  54. 'id_point_sale' => $pointSale ? $pointSale->id : null,
  55. 'users_point_sale_link' => $usersPointSaleLink,
  56. 'users_point_sale_has_order' => $usersPointSaleHasOrder,
  57. 'subscribers' => $isSubscriber,
  58. 'inactive' => $isInactive,
  59. 'newsletter_type' => $newsletterType,
  60. 'newsletter' => true
  61. ])->all();
  62. }
  63. $usersArray = [];
  64. foreach ($users as $user) {
  65. if (isset($user['email']) && strlen($user['email']) > 0) {
  66. if($producer->isDemoAccount()) {
  67. $user['email'] = \Yii::$app->faker->email();
  68. }
  69. $usersArray[] = $user;
  70. }
  71. }
  72. return $usersArray;
  73. }
  74. }