EmailTemplateRepository.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\EmailTemplate;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. /**
  7. * Class EmailTemplateRepository.
  8. *
  9. * @package namespace App\Repositories;
  10. */
  11. class EmailTemplateRepository extends BaseRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return EmailTemplate::class;
  21. }
  22. /**
  23. * Boot up the repository, pushing criteria
  24. */
  25. public function boot()
  26. {
  27. $this->pushCriteria(app(RequestCriteria::class));
  28. }
  29. /**
  30. * 获得短信模板
  31. * @param string $alias
  32. * @param array $titleParams
  33. * @param array $contentParams
  34. * @return EmailTemplate
  35. */
  36. public function getTemplate(string $alias, array $titleParams = [], array $contentParams = [])
  37. {
  38. $template=$this->model->where('alias', $alias)->first();
  39. if (!empty($titleParams)) {
  40. $template->title=render_template($template->title, $titleParams);
  41. }
  42. if (!empty($contentParams)) {
  43. $template->value=render_template($template->value, $contentParams);
  44. }
  45. return $template;
  46. }
  47. }