OwnerStoreFeeDetailService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 SettlementBillTrait;
  12. const TYPE = '入库费-明细';
  13. protected $modelClass = OwnerStoreFeeDetail::class;
  14. /** @var $archiveService OwnerBillReportArchiveService */
  15. private $archiveService;
  16. public function get(array $kvPairs)
  17. {
  18. return $this->getSql($kvPairs['counting_month'], $kvPairs['owner_id'])
  19. ->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  20. }
  21. /**
  22. * @param $type
  23. * @return int|mixed
  24. */
  25. public function switchType($type)
  26. {
  27. //枚举转换
  28. if (is_string($type)) {
  29. $type = OwnerStoreFeeDetail::$enums['type'][$type];
  30. }
  31. return $type;
  32. }
  33. /**
  34. * @param $counting_month
  35. * @param $owner_id
  36. * @return Builder
  37. */
  38. public function getSql($counting_month, $owner_id): Builder
  39. {
  40. $start = Carbon::parse($counting_month)->startOfMonth()->startOfDay()->toDateTimeString();
  41. $end = Carbon::parse($counting_month)->endOfMonth()->endOfDay()->toDateTimeString();
  42. return OwnerStoreFeeDetail::query()
  43. ->with(['ownerFeeDetail:id,work_fee,worked_at', 'storeItem' => function ($query) {
  44. $query->selectRaw("id,asn_line_code,sku,commodity_id")->with('commodity:id,name');
  45. },])
  46. ->whereBetween('created_at', [$start, $end])
  47. ->where('owner_id', $owner_id);
  48. }
  49. public function buildExport($details): array
  50. {
  51. $results = [];
  52. foreach ($details as $detail) {
  53. $results[] = [
  54. $detail->ownerFeeDetail->worked_at ?? null,
  55. $detail->type ?? null,
  56. $detail->storeItem->asn_line_code ?? null,
  57. $detail->storeItem->sku ?? null,
  58. $detail->storeItem->commodity->name ?? null,
  59. $detail->amount ?? null,
  60. $detail->unit_price ?? null,
  61. $detail->ownerFeeDetail->work_fee ?? null,
  62. ];
  63. }
  64. return $results;
  65. }
  66. }