OwnerStoreFeeDetailService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 $type
  20. // * @return int|mixed
  21. // */
  22. // public function switchType($type)
  23. // {
  24. // //枚举转换
  25. // if (is_string($type)) {
  26. // $type = OwnerStoreFeeDetail::$enums['type'][$type];
  27. // }
  28. // return $type;
  29. // }
  30. /**
  31. * @param $counting_month
  32. * @param $owner_id
  33. * @return Builder
  34. */
  35. public function getSql($counting_month, $owner_id): Builder
  36. {
  37. list($start, $end) = $this->getStartAndEnd($counting_month);
  38. return OwnerStoreFeeDetail::query()
  39. ->with([
  40. 'ownerFeeDetail:id,worked_at',
  41. 'commodity:id,name',
  42. ])
  43. ->whereBetween('created_at', [$start, $end])
  44. ->where('owner_id', $owner_id);
  45. }
  46. public function buildExport($details): array
  47. {
  48. $results = [];
  49. foreach ($details as $detail) {
  50. $results[] = [
  51. $detail->ownerFeeDetail->worked_at ?? null,
  52. $detail->type ?? null,
  53. $detail->storeItem->asn_line_code ?? null,
  54. $detail->storeItem->sku ?? null,
  55. $detail->storeItem->commodity->name ?? null,
  56. $detail->amount ?? null,
  57. $detail->unit_price ?? null,
  58. $detail->ownerFeeDetail->work_fee ?? null,
  59. ];
  60. }
  61. return $results;
  62. }
  63. }