| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?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 buildPriceRemarks(&$storeOutFeeDetails)
- // {
- // foreach ($storeOutFeeDetails as &$ownerStoreOutFeeDetail) {
- // //起步: 3 件 / 2.7000元 (满减单价: 0-19999 单(2.7元) , 20000-49999 单(2.5元) , 50000-99999 单(2元) , 100000+ 单(1.6元) )
- // //默认续费: 1 件 / 0.5000元 (满减单价: 0-19999 单(0.5元) , 20000-49999 单(0.4元) , 50000-99999 单(0.3元) , 100000+ 单(0.2元) )
- // $discount_counts = explode(',', $ownerStoreOutFeeDetail->ownerPriceOperation->discount_count);
- // $priceRemarks = [];
- // foreach ($ownerStoreOutFeeDetail->ownerPriceOperation->items as $operationItem) {
- // $discount_prices = explode(',', $operationItem->discount_price);
- // $strategy = $operationItem->strategy == '起步' ? '起步' : '默认续费';
- // $priceRemark = "{$strategy}: {$operationItem->amount} {$operationItem->unit->name}/{$operationItem->unit_price}元";
- // if (!empty($discount_prices)) {
- // $priceRemark .= "(满减单价:";
- // for ($i = 0; $i < count($discount_counts) - 1; $i++) {
- // $next_discount_count = $discount_counts[$i + 1] ?? '+';
- // $discount_count = $discount_counts[$i] ?? '';
- // $discount_price = $discount_prices[$i] ?? '';
- // $priceRemark .= "{$discount_count}-{$next_discount_count} {$operationItem->unit->name} {$discount_price}元,";
- // }
- // $priceRemark .= ")";
- // }
- // $priceRemarks[] = $priceRemark;
- // }
- // $ownerStoreOutFeeDetail['price_remarks'] = $priceRemarks;
- // }
- // }
- }
|