OwnerDischargeTaskSettlementBillService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Services;
  3. use App\DischargeTask;
  4. use App\Traits\ServiceAppAop;
  5. use App\Traits\SettlementBillServiceTrait;
  6. class OwnerDischargeTaskSettlementBillService implements \App\Interfaces\SettlementBillReportInterface
  7. {
  8. use \App\Traits\SettlementBillServiceTrait;
  9. const TYPE = '卸货费';
  10. use ServiceAppAop;
  11. public function get(array $kvPairs): array
  12. {
  13. $details = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  14. $totalFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->sum('expenditure_total_cost');
  15. return array($details, $totalFee);
  16. }
  17. public function getSql($owner_id, $counting_month): \Illuminate\Database\Eloquent\Builder
  18. {
  19. list($start, $end) = $this->getStartAndEnd($counting_month);
  20. return DischargeTask::query()
  21. ->where('owner_id', $owner_id)
  22. ->whereBetween('income_at', [$start, $end]);
  23. }
  24. public function switchType($type)
  25. {
  26. // TODO: Implement switchType() method.
  27. }
  28. public function buildExport($details): array
  29. {
  30. $result = [];
  31. foreach ($details as $detail) {
  32. $result[] = [
  33. $detail->income_at,
  34. $detail->type,
  35. $detail->numbers,
  36. $detail->expenditure_amount,
  37. $detail->expenditure_unit,
  38. $detail->expenditure_unit_price,
  39. $detail->expenditure_total_cost,
  40. $detail->income_remark,
  41. $detail->expenditure_remark,
  42. ];
  43. }
  44. return $result;
  45. }
  46. public function add(array $model)
  47. {
  48. // TODO: Implement add() method.
  49. }
  50. public function getTotalFee($owner_id, $counting_month)
  51. {
  52. return $this->getSql($owner_id, $counting_month)->sum('expenditure_total_cost');
  53. }
  54. /**
  55. * @param null $counting_month
  56. * @param array $ownerIds
  57. */
  58. public function recordReport($counting_month = null, array $ownerIds = [])
  59. {
  60. // TODO: Implement recordReport() method.
  61. }
  62. }