OwnerBillReportArchiveService.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerAreaReport;
  4. use App\OwnerBillReport;
  5. use App\Traits\ServiceAppAop;
  6. use App\OwnerBillReportArchive;
  7. use Illuminate\Database\Eloquent\Builder;
  8. use Illuminate\Database\Eloquent\Model;
  9. class OwnerBillReportArchiveService
  10. {
  11. use ServiceAppAop;
  12. protected $modelClass = OwnerBillReportArchive::class;
  13. /**
  14. * @param $counting_month
  15. * @param $owner_id
  16. * @param $type
  17. * @return Builder
  18. */
  19. public function getSql($counting_month, $owner_id, $type): Builder
  20. {
  21. return OwnerBillReportArchive::query()->where('counting_month', $counting_month)
  22. ->where('owner_id', $owner_id)->where('type', $type);
  23. }
  24. /**
  25. * @param $counting_month
  26. * @param $owner_id
  27. * @param $type
  28. * @return int
  29. */
  30. public function isArchived($counting_month, $owner_id, $type): int
  31. {
  32. $type = $this->switchType($type);
  33. return $this->getSql($counting_month, $owner_id, $type)->exists() ? 1 : 2;
  34. }
  35. /**
  36. * 获取确认账单数据
  37. * @param array $kvPairs
  38. * @return Builder|Model|object|null
  39. */
  40. public function get(array $kvPairs)
  41. {
  42. return $this->getSql($kvPairs['counting_month'], $kvPairs['owner_id'], $this->switchType($kvPairs['type']))->first();
  43. }
  44. /**
  45. * @param $type
  46. * @return int|mixed
  47. */
  48. private function switchType($type)
  49. {
  50. //枚举转换
  51. if (is_string($type)) {
  52. $type = OwnerBillReportArchive::$enums['type'][$type];
  53. }
  54. return $type;
  55. }
  56. }