| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?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)
- {
- 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');
- },])
- ->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;
- }
- }
|