OwnerProcessSettlementBillService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Services;
  3. use App\Interfaces\SettlementBillDetailInterface;
  4. use App\OwnerFeeDetail;
  5. use App\Traits\ServiceAppAop;
  6. use Illuminate\Database\Eloquent\Builder;
  7. class OwnerProcessSettlementBillService implements SettlementBillDetailInterface
  8. {
  9. use \App\Traits\SettlementBillServiceTrait;
  10. const TYPE = '加工费';
  11. use ServiceAppAop;
  12. public function get(array $kvPairs): array
  13. {
  14. $details = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  15. $totalFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->sum('work_fee');
  16. return array($details,$totalFee);
  17. }
  18. public function getSql($owner_id, $counting_month): Builder
  19. {
  20. list($start, $end) = $this->getStartAndEnd($counting_month);
  21. return OwnerFeeDetail::query()
  22. ->with(['process.processMethod'])
  23. ->where('owner_id', $owner_id)
  24. ->whereBetween('worked_at', [$start, $end]);
  25. }
  26. public function switchType($type)
  27. {
  28. // TODO: Implement switchType() method.
  29. }
  30. public function buildExport($details): array
  31. {
  32. $result = array();
  33. foreach ($details as $detail) {
  34. $result[] = [
  35. $detail->worked_at,
  36. $detail->process->processMethod->name??'',
  37. $detail->process->code??'',
  38. $detail->operation_bill,
  39. $detail->process->remark??'',
  40. $detail->commodity_amount,
  41. $detail->process->unit_price??'',
  42. $detail->work_fee,
  43. ];
  44. }
  45. return $result;
  46. }
  47. public function add(array $model)
  48. {
  49. // TODO: Implement add() method.
  50. }
  51. }