OwnerWaybillSettlementBillService.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerFeeDetail;
  4. use App\OwnerFeeLogistic;
  5. use App\Traits\ServiceAppAop;
  6. use App\Waybill;
  7. use Illuminate\Database\Eloquent\Builder;
  8. use Illuminate\Support\Facades\DB;
  9. class OwnerWaybillSettlementBillService implements \App\Interfaces\SettlementBillDetailInterface
  10. {
  11. use ServiceAppAop;
  12. use \App\Traits\SettlementBillServiceTrait;
  13. const TYPE = '物流费';
  14. public function get(array $kvPairs)
  15. {
  16. return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  17. }
  18. /**
  19. * @param $owner_id
  20. * @param $counting_month
  21. * @return Builder
  22. */
  23. public function getSql($owner_id, $counting_month): Builder
  24. {
  25. list($start, $end) = $this->getStartAndEnd($counting_month);
  26. return OwnerFeeLogistic::query()
  27. ->where('owner_id', $owner_id)
  28. ->whereBetween('created_at', [$start, $end])
  29. ->with(['province', 'logistic', 'city','unit']);
  30. }
  31. public function switchType($type)
  32. {
  33. // TODO: Implement switchType() method.
  34. }
  35. public function buildExport($details): array
  36. {
  37. $results = [];
  38. foreach ($details as $detail) {
  39. $results[] = [
  40. $detail->logistic->name ?? '',
  41. $detail->order_number ?? '',
  42. $detail->recipient_name ?? '',
  43. $detail->recipient_phone ?? '',
  44. $detail->quantity ?? '',
  45. $detail->unit->name ?? '',
  46. $detail->interval ?? '',
  47. $detail->province->name ?? '',
  48. $detail->city->name ?? '',
  49. $detail->price ?? '',
  50. $detail->delivery_fee ?? '',
  51. $detail->pick_fee ?? '',
  52. $detail->fuel_fee ?? '',
  53. $detail->info_fee ?? '',
  54. $detail->other_fee ?? '',
  55. $detail->remark ?? '',
  56. $detail->initial_fee ?? '',
  57. $detail->initial_amount ?? '',
  58. $detail->total_fee ?? '',
  59. ];
  60. }
  61. return $results;
  62. }
  63. public function add(array $model)
  64. {
  65. // TODO: Implement add() method.
  66. }
  67. public function getTotalFee($owner_id, $counting_month)
  68. {
  69. list($start, $end) = $this->getStartAndEnd($counting_month);
  70. return OwnerFeeLogistic::query()
  71. ->selectRaw("
  72. sum(total_fee) as fee,
  73. sum(tax_rate*total_fee) as tax_fee
  74. ")
  75. ->where('owner_id', $owner_id)
  76. ->whereBetween('created_at', [$start, $end])
  77. ->first();
  78. }
  79. }