OwnerStoreFeeDetailService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use App\OwnerStoreFeeDetail;
  5. use App\Traits\SettlementBillTrait;
  6. use Carbon\Carbon;
  7. use Illuminate\Database\Eloquent\Builder;
  8. class OwnerStoreFeeDetailService
  9. {
  10. use ServiceAppAop;
  11. use \App\Traits\SettlementBillServiceTrait;
  12. const TYPE = '入库费-明细';
  13. protected $modelClass = OwnerStoreFeeDetail::class;
  14. public function get(array $kvPairs): \Illuminate\Contracts\Pagination\LengthAwarePaginator
  15. {
  16. return $this->getSql($kvPairs['counting_month'], $kvPairs['owner_id'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  17. }
  18. /**
  19. * @param $counting_month
  20. * @param $owner_id
  21. * @return Builder
  22. */
  23. public function getSql($counting_month, $owner_id): Builder
  24. {
  25. list($start, $end) = $this->getStartAndEnd($counting_month);
  26. return OwnerStoreFeeDetail::query()
  27. ->with([
  28. 'ownerFeeDetail:id,worked_at',
  29. 'commodity:id,name',
  30. ])
  31. ->whereBetween('created_at', [$start, $end])
  32. ->where('owner_id', $owner_id);
  33. }
  34. public function buildExport($details): array
  35. {
  36. $results = [];
  37. foreach ($details as $detail) {
  38. $results[] = [
  39. $detail->ownerFeeDetail->worked_at ?? null,
  40. $detail->work_name ?? null,
  41. $detail->asn_code ?? null,
  42. $detail->sku ?? null,
  43. $detail->commodity->name ?? null,
  44. $detail->amount ?? null,
  45. $detail->unit_price ?? null,
  46. $detail->fee ?? null,
  47. ];
  48. }
  49. return $results;
  50. }
  51. }