OwnerStoreFeeDetailService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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,work_fee,worked_at',
  41. 'storeItem' => function ($query) {$query->selectRaw("id,asn_line_code,sku,commodity_id")->with('commodity:id,name');},
  42. 'ownerPriceOperation:id,name'
  43. ])
  44. ->whereBetween('created_at', [$start, $end])
  45. ->where('owner_id', $owner_id);
  46. }
  47. public function buildExport($details): array
  48. {
  49. $results = [];
  50. foreach ($details as $detail) {
  51. $results[] = [
  52. $detail->ownerFeeDetail->worked_at ?? null,
  53. $detail->type ?? null,
  54. $detail->storeItem->asn_line_code ?? null,
  55. $detail->storeItem->sku ?? null,
  56. $detail->storeItem->commodity->name ?? null,
  57. $detail->amount ?? null,
  58. $detail->unit_price ?? null,
  59. $detail->ownerFeeDetail->work_fee ?? null,
  60. ];
  61. }
  62. return $results;
  63. }
  64. }