OwnerStoreFeeDetailService.php 1.9 KB

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