OwnerDischargeTaskSettlementBillService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public function recordReport($counting_month = null)
  55. {
  56. // TODO: Implement recordReport() method.
  57. }
  58. }