OwnerProcessSettlementBillService.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. use Illuminate\Support\Facades\DB;
  8. class OwnerProcessSettlementBillService implements SettlementBillDetailInterface
  9. {
  10. use \App\Traits\SettlementBillServiceTrait;
  11. const TYPE = '加工费';
  12. use ServiceAppAop;
  13. public function get(array $kvPairs): array
  14. {
  15. $details = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  16. $totalFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->sum('work_fee');
  17. return array($details,$totalFee);
  18. }
  19. public function getSql($owner_id, $counting_month): Builder
  20. {
  21. list($start, $end) = $this->getStartAndEnd($counting_month);
  22. return OwnerFeeDetail::query()
  23. ->with(['process.processMethod'])
  24. ->where('owner_id', $owner_id)
  25. ->whereBetween('worked_at', [$start, $end])
  26. ->where('outer_table_name','processes');
  27. }
  28. public function switchType($type)
  29. {
  30. // TODO: Implement switchType() method.
  31. }
  32. public function buildExport($details): array
  33. {
  34. $result = array();
  35. foreach ($details as $detail) {
  36. $result[] = [
  37. $detail->worked_at,
  38. $detail->process->processMethod->name??'',
  39. $detail->process->code??'',
  40. $detail->operation_bill,
  41. $detail->process->remark??'',
  42. $detail->commodity_amount,
  43. $detail->process->unit_price??'',
  44. $detail->work_fee,
  45. ];
  46. }
  47. return $result;
  48. }
  49. public function add(array $model)
  50. {
  51. // TODO: Implement add() method.
  52. }
  53. public function getTotalFee($owner_id, $counting_month)
  54. {
  55. list($start, $end) = $this->getStartAndEnd($counting_month);
  56. return DB::table('owner_fee_details')
  57. ->selectRaw("sum(work_fee) as fee,sum(work_tax_fee) as tax_fee")
  58. ->where('owner_id', $owner_id)
  59. ->whereBetween('worked_at', [$start, $end])
  60. ->where('outer_table_name','processes')
  61. ->first();
  62. }
  63. }