| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Services;
- use App\Interfaces\SettlementBillDetailInterface;
- use App\OwnerFeeDetail;
- use App\OwnerFeeOperation;
- use App\OwnerPriceOperation;
- use App\Traits\ServiceAppAop;
- use App\OwnerStoreOutFeeDetail;
- use App\Traits\SettlementBillServiceTrait;
- use Illuminate\Contracts\Pagination\LengthAwarePaginator;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Collection;
- 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);
- $OwnerPriceOperationQuery = OwnerPriceOperation::query()
- ->select('id')
- ->where('operation_type', '出库');
- return OwnerFeeOperation::query()
- ->with(['details', 'model', 'commodity.barcodes'])
- ->whereIn('model_id', $OwnerPriceOperationQuery)
- ->whereBetween('worked_at', [$start, $end])
- ->where('owner_id', $owner_id);
- }
- public function switchType($type)
- {
- // TODO: Implement switchType() method.
- }
- public function buildExport($details): array
- {
- $result = [];
- foreach ($details as $detail) {
- // $row = ['作业时间', '作业名称', '上游单号', '订单号', '商家编码', '商品条码', '商品名称', '商品数量', '单价', '价格描述', '合计'];
- $result[] = [
- $detail->worked_at ?? '',
- $detail->model->name ?? '',
- $detail->source_number,
- $detail->doc_number ?? '',
- $detail->commodity->sku ?? '',
- $detail->source_number ?? '',
- $detail->commodity->name ?? '',
- $detail->details[0]->amount ?? '',
- $detail->details[0]->price ?? '',
- $detail->fee_description ?? '',
- $detail->fee ?? '',
- ];
- }
- return $result;
- }
- public function add(array $model)
- {
- // TODO: Implement add() method.
- }
- /**
- * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费
- * @param $owner_id
- * @param $counting_month
- * @return Builder[]|Collection
- */
- public function getTotalFee($owner_id, $counting_month)
- {
- list($start, $end) = $this->getStartAndEnd($counting_month);
- return 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();
- }
- }
|