| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Services;
- use App\Interfaces\SettlementBillDetailInterface;
- use App\Traits\ServiceAppAop;
- use App\OwnerStoreOutFeeDetail;
- use App\Traits\SettlementBillServiceTrait;
- use Illuminate\Contracts\Pagination\LengthAwarePaginator;
- use Illuminate\Database\Eloquent\Builder;
- class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
- {
- const TYPE = '出库费-明细';
- use ServiceAppAop;
- use SettlementBillServiceTrait;
- protected $modelClass = OwnerStoreOutFeeDetail::class;
- /**
- * 详情的查询不管是否却认都是原始数据且分页
- * @param array $kvPairs
- * @return LengthAwarePaginator
- */
- public function get(array $kvPairs): LengthAwarePaginator
- {
- return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
- }
- public function getSql($owner_id, $counting_month): Builder
- {
- list($start, $end) = $this->getStartAndEnd($counting_month);
- return OwnerStoreOutFeeDetail::query()
- ->with([
- 'commodity:id,name,sku',
- 'ownerFeeDetail:id,worked_at,operation_bill,work_fee',
- 'ownerPriceOperation.items.unit',
- ])
- ->where('owner_id', $owner_id)
- ->whereBetween('created_at', [$start, $end]);
- }
- public function switchType($type)
- {
- // TODO: Implement switchType() method.
- }
- public function buildExport($details): array
- {
- $result = [];
- foreach ($details as $detail) {
- $result[] = [
- $detail->ownerFeeDetail->worked_at,
- $detail->ownerPriceOperation->name ?? '',
- $detail->source_bill,
- $detail->ownerFeeDetail->operation_bill,
- $detail->commodity->sku,
- $detail->commodity->name,
- $detail->amount,
- $detail->price_remark,
- $detail->ownerFeeDetail->work_fee,
- ];
- }
- return $result;
- }
- public function add(array $model)
- {
- // TODO: Implement add() method.
- }
- public function getTotalFee($owner_id, $counting_month)
- {
- list($start, $end) = $this->getStartAndEnd($counting_month);
- return \App\OwnerFeeDetail::query()
- ->selectRaw("owner_price_operation_id,
- sum(work_fee) as work_fee,
- sum(work_tax_fee) as work_tax_fee
- ")
- ->where('owner_id', $owner_id)
- ->whereBetween('created_at', [$start, $end])
- ->groupBy('owner_id', 'owner_price_operation_id')
- ->get();
- }
- }
|