OwnerBillReportArchiveService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use App\OwnerBillReportArchive;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Database\Eloquent\Model;
  7. class OwnerBillReportArchiveService
  8. {
  9. use ServiceAppAop;
  10. protected $modelClass = OwnerBillReportArchive::class;
  11. /**
  12. * @param $counting_month
  13. * @param $owner_id
  14. * @param $type
  15. * @return Builder
  16. */
  17. public function getSql($counting_month, $owner_id, $type): Builder
  18. {
  19. return OwnerBillReportArchive::query()->where('counting_month', \Carbon\Carbon::parse($counting_month)->toDateString())
  20. ->where('owner_id', $owner_id)->where('type', $type);
  21. }
  22. /**
  23. * @param $counting_month
  24. * @param $owner_id
  25. * @param $type
  26. * @return int 1 已确认 2 未确认
  27. */
  28. public function isArchived($counting_month, $owner_id, $type): int
  29. {
  30. return $this->getSql($counting_month, $owner_id, $this->switchType($type))->exists() ? 1 : 2;
  31. }
  32. /**
  33. * 获取确认账单数据
  34. * @param array $kvPairs
  35. * @return Builder|Model|object|null
  36. */
  37. public function get(array $kvPairs)
  38. {
  39. return $this->getSql($kvPairs['counting_month'], $kvPairs['owner_id'], $this->switchType($kvPairs['type']))->first();
  40. }
  41. /**
  42. * @param $type
  43. * @return int|mixed
  44. */
  45. private function switchType($type)
  46. {
  47. //枚举转换
  48. if (is_string($type)) {
  49. $type = OwnerBillReportArchive::$enums['type'][$type];
  50. }
  51. return $type;
  52. }
  53. /**
  54. *查询没有确认的账单
  55. */
  56. public function getUnAchieved($counting_month, $owner_id): array
  57. {
  58. //TODO 5 => "包材费"
  59. // 8 => "卸货费"
  60. // 9 => "理赔费"
  61. //]
  62. $archives = OwnerBillReportArchive::query()
  63. ->where('counting_month', $counting_month)
  64. ->where('owner_id', $owner_id)
  65. ->pluck('type')->toArray();
  66. $all = ['仓储费', '快递费-合计', '入库费-合计', '出库费-合计', '物流费', '包材费', '加工费', '杂项费', '卸货费', '理赔费',];
  67. return array_diff($all, $archives);
  68. }
  69. }