OwnerStoreOutFeeDetailService.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Services;
  3. use App\Interfaces\SettlementBillDetailInterface;
  4. use App\Traits\ServiceAppAop;
  5. use App\OwnerStoreOutFeeDetail;
  6. use App\Traits\SettlementBillServiceTrait;
  7. use Illuminate\Contracts\Pagination\LengthAwarePaginator;
  8. use Illuminate\Database\Eloquent\Builder;
  9. class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
  10. {
  11. const TYPE = '出库费-明细';
  12. use ServiceAppAop;
  13. use SettlementBillServiceTrait;
  14. protected $modelClass = OwnerStoreOutFeeDetail::class;
  15. /**
  16. * 详情的查询不管是否却认都是原始数据且分页
  17. * @param array $kvPairs
  18. * @return LengthAwarePaginator
  19. */
  20. public function get(array $kvPairs): LengthAwarePaginator
  21. {
  22. return $this->getSql($kvPairs['owner_id'],$kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate']??50);
  23. }
  24. public function getSql($owner_id, $counting_month): Builder
  25. {
  26. list($start, $end) = $this->getStartAndEnd($counting_month);
  27. return OwnerStoreOutFeeDetail::query()
  28. ->with(['commodity:id,name,sku', 'ownerFeeDetail:id,worked_at,operation_bill,work_fee'])
  29. ->where('owner_id', $owner_id)
  30. ->whereBetween('created_at', [$start, $end]);
  31. }
  32. public function switchType($type)
  33. {
  34. // TODO: Implement switchType() method.
  35. }
  36. public function buildExport($details): array
  37. {
  38. $result = [];
  39. foreach ($details as $detail) {
  40. $result[] = [
  41. $detail->ownerFeeDetail->worked_at,
  42. $detail->work_name,
  43. $detail->source_bill,
  44. $detail->ownerFeeDetail->operation_bill,
  45. $detail->commodity->sku,
  46. $detail->commodity->name,
  47. $detail->amount,
  48. $detail->remark,
  49. $detail->ownerFeeDetail->work_fee,
  50. ];
  51. }
  52. return $result;
  53. }
  54. public function add(array $model)
  55. {
  56. // TODO: Implement add() method.
  57. }
  58. }