| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Services;
- use App\Traits\ServiceAppAop;
- use App\OwnerStoreFeeDetail;
- use App\Traits\SettlementBillTrait;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Builder;
- class OwnerStoreFeeDetailService
- {
- use ServiceAppAop;
- use \App\Traits\SettlementBillServiceTrait;
- const TYPE = '入库费-明细';
- protected $modelClass = OwnerStoreFeeDetail::class;
- public function get(array $kvPairs): \Illuminate\Contracts\Pagination\LengthAwarePaginator
- {
- return $this->getSql($kvPairs['counting_month'], $kvPairs['owner_id'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
- }
- // /**
- // * @param $type
- // * @return int|mixed
- // */
- // public function switchType($type)
- // {
- // //枚举转换
- // if (is_string($type)) {
- // $type = OwnerStoreFeeDetail::$enums['type'][$type];
- // }
- // return $type;
- // }
- /**
- * @param $counting_month
- * @param $owner_id
- * @return Builder
- */
- public function getSql($counting_month, $owner_id): Builder
- {
- list($start, $end) = $this->getStartAndEnd($counting_month);
- return OwnerStoreFeeDetail::query()
- ->with([
- 'ownerFeeDetail:id,work_fee,worked_at',
- 'storeItem' => function ($query) {$query->selectRaw("id,asn_line_code,sku,commodity_id")->with('commodity:id,name');},
- 'ownerPriceOperation:id,name'
- ])
- ->whereBetween('created_at', [$start, $end])
- ->where('owner_id', $owner_id);
- }
- public function buildExport($details): array
- {
- $results = [];
- foreach ($details as $detail) {
- $results[] = [
- $detail->ownerFeeDetail->worked_at ?? null,
- $detail->type ?? null,
- $detail->storeItem->asn_line_code ?? null,
- $detail->storeItem->sku ?? null,
- $detail->storeItem->commodity->name ?? null,
- $detail->amount ?? null,
- $detail->unit_price ?? null,
- $detail->ownerFeeDetail->work_fee ?? null,
- ];
- }
- return $results;
- }
- }
|