| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?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 SettlementBillTrait;
- const TYPE = '入库费-明细';
- protected $modelClass = OwnerStoreFeeDetail::class;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- 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
- {
- $start = Carbon::parse($counting_month)->startOfMonth()->startOfDay()->toDateTimeString();
- $end = Carbon::parse($counting_month)->endOfMonth()->endOfDay()->toDateTimeString();
- 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;
- }
- }
|