OwnerLogisticFeeDetailService.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Services;
  3. use App\Logistic;
  4. use App\OwnerFeeDetail;
  5. use App\OwnerFeeExpress;
  6. use App\Traits\ServiceAppAop;
  7. use App\OwnerLogisticFeeDetail;
  8. use App\Traits\SettlementBillServiceTrait;
  9. use Carbon\Carbon;
  10. use Illuminate\Database\Eloquent\Builder;
  11. use Illuminate\Pagination\LengthAwarePaginator;
  12. class OwnerLogisticFeeDetailService implements \App\Interfaces\SettlementBillDetailInterface
  13. {
  14. use SettlementBillServiceTrait;
  15. const TYPE = '快递费-明细';
  16. use ServiceAppAop;
  17. /**
  18. * @var $modelClass OwnerFeeExpress
  19. */
  20. protected $modelClass = OwnerFeeExpress::class;
  21. /**
  22. * 根据货主查询 和时间段查询
  23. * @param array $kvPairs
  24. * @return LengthAwarePaginator
  25. */
  26. public function get(array $kvPairs): LengthAwarePaginator
  27. {
  28. return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  29. }
  30. /**
  31. * @param $owner_id
  32. * @param $counting_month
  33. * @return Builder
  34. */
  35. public function getSql($owner_id, $counting_month): Builder
  36. {
  37. list($start, $end) = $this->getStartAndEnd($counting_month);
  38. return OwnerFeeExpress::query()
  39. ->with(['province', 'logistic'])
  40. ->where('owner_id', $owner_id)
  41. ->whereBetween('created_at', [$start, $end])
  42. ->orderBy('logistic_id');
  43. }
  44. public function switchType($type)
  45. {
  46. }
  47. public function buildExport($details): array
  48. {
  49. $result = [];
  50. foreach ($details as $key => $detail) {
  51. // $row = ['主键', '快递公司', '省份', '快递单号', '重量', '首重价格', '续重价格', '快递费',];
  52. $result[] = [
  53. $detail->id,
  54. $detail->logistic->name ?? '',
  55. $detail->province->name ?? '',
  56. $detail->logistic_number ?? '',
  57. $detail->weight ?? '',
  58. $detail->initial_weight_price ?? '',
  59. $detail->additional_weight_price ?? '',
  60. $detail->total_fee ?? '',
  61. ];
  62. }
  63. return $result;
  64. }
  65. public function add(array $model)
  66. {
  67. }
  68. public function getTotalFee($owner_id, $counting_month)
  69. {
  70. }
  71. }