OwnerProcessSettlementBillService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. ->where('outer_table_name','processes');
  26. }
  27. public function switchType($type)
  28. {
  29. // TODO: Implement switchType() method.
  30. }
  31. public function buildExport($details): array
  32. {
  33. $result = array();
  34. foreach ($details as $detail) {
  35. $result[] = [
  36. $detail->worked_at,
  37. $detail->process->processMethod->name??'',
  38. $detail->process->code??'',
  39. $detail->operation_bill,
  40. $detail->process->remark??'',
  41. $detail->commodity_amount,
  42. $detail->process->unit_price??'',
  43. $detail->work_fee,
  44. ];
  45. }
  46. return $result;
  47. }
  48. public function add(array $model)
  49. {
  50. // TODO: Implement add() method.
  51. }
  52. public function getTotalFee($owner_id, $counting_month)
  53. {
  54. // TODO: Implement getTotalFee() method.
  55. }
  56. }