OwnerStoreFeeDetailService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // $row = ['作业日期', '作业名称', '入库单号', '商品条码', '商品名称', '数量', '单价', '入库费'];
  40. $results = [];
  41. foreach ($details as $detail) {
  42. $results[] = [
  43. $detail->worked_at ?? '',
  44. $detail->model->name ?? '',
  45. $detail->doc_number ?? '',
  46. $detail->commodity->sku ?? '',
  47. $detail->commodity->name ?? '',
  48. $detail->details[0]->amount ?? '',
  49. $detail->details[0]->price ?? '',
  50. $detail->total_fee ?? '',
  51. ];
  52. }
  53. return $results;
  54. }
  55. }