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

49 行
1.5KB

  1. <?php
  2. namespace domain\PointSale\UserPointSale;
  3. use domain\PointSale\PointSale\PointSale;
  4. use domain\User\User\User;
  5. use domain\_\AbstractBuilder;
  6. class UserPointSaleBuilder extends AbstractBuilder
  7. {
  8. protected UserPointSaleRepository $userPointSaleRepository;
  9. public function loadDependencies(): void
  10. {
  11. $this->userPointSaleRepository = $this->loadService(UserPointSaleRepository::class);
  12. }
  13. public function instanciateUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  14. {
  15. $userPointSale = new UserPointSale();
  16. $userPointSale->populatePointSale($pointSale);
  17. $userPointSale->populateUser($user);
  18. if($comment) {
  19. $userPointSale->comment = $comment;
  20. }
  21. return $userPointSale;
  22. }
  23. public function createUserPointSale(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  24. {
  25. $userPointSale = $this->instanciateUserPointSale($user, $pointSale, $comment);
  26. $this->saveCreate($userPointSale);
  27. return $userPointSale;
  28. }
  29. public function createUserPointSaleIfNotExist(User $user, PointSale $pointSale, string $comment = null): UserPointSale
  30. {
  31. return $this->userPointSaleRepository->findOneUserPointSale($user, $pointSale)
  32. ?? $this->createUserPointSale($user, $pointSale);
  33. }
  34. public function deleteUserPointSalesByPointSale(PointSale $pointSale): void
  35. {
  36. UserPointSale::deleteAll(['id_point_sale' => $pointSale->id]);
  37. }
  38. }