EmailBatchRepository.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\EmailBatch;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. /**
  7. * Class EmailBatchRepository.
  8. *
  9. * @package namespace App\Repositories;
  10. */
  11. class EmailBatchRepository extends BaseRepository
  12. {
  13. /**
  14. * Specify Model class name
  15. *
  16. * @return string
  17. */
  18. public function model()
  19. {
  20. return EmailBatch::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. * @param $batch_id
  31. * @param bool $status
  32. * @return mixed
  33. */
  34. public function updateBatch($batch_id, $status = true)
  35. {
  36. if ($batch_id == 0) {
  37. return;
  38. }
  39. $batch=$this->model->find($batch_id);
  40. $batch->send_num=$batch->send_num+($status?1:0);
  41. if ($batch->queues()->count() == $batch->target_num) {
  42. $batch->status=1;
  43. }
  44. $batch->save();
  45. }
  46. }