113 lines
3.7 KiB
PHP
113 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Business;
|
|
|
|
use App\Business\ThirdPartyWarehouseQuoteRepository;
|
|
use App\Models\Business\ThirdPartyWarehouseQuote;
|
|
use Illuminate\Contracts\View\View;
|
|
use Livewire\Component;
|
|
|
|
class ThirdPartyWarehouseQuotes extends Component
|
|
{
|
|
public string $warehouseName = '南昌樵舍仓';
|
|
|
|
public string $effectiveAt = '';
|
|
|
|
public string $inboundRatePerTon = '20';
|
|
|
|
public string $outboundRatePerOrder = '0.85';
|
|
|
|
public string $piecesPerPallet = '23';
|
|
|
|
public string $palletAreaSqm = '3';
|
|
|
|
public string $storageRatePerSqmMonth = '10.5';
|
|
|
|
public string $remark = '';
|
|
|
|
public ?string $message = null;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->effectiveAt = now()->toDateString();
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$this->ensureAuthenticated();
|
|
abort_unless($this->repository()->ready(), 503, '仓储报价数据表尚未完成迁移,请联系管理员。');
|
|
|
|
$this->warehouseName = trim($this->warehouseName);
|
|
$data = $this->validate();
|
|
$this->repository()->create([
|
|
'warehouse_name' => $data['warehouseName'],
|
|
'effective_at' => $data['effectiveAt'],
|
|
'inbound_rate_per_ton' => $data['inboundRatePerTon'],
|
|
'outbound_rate_per_order' => $data['outboundRatePerOrder'],
|
|
'pieces_per_pallet' => $data['piecesPerPallet'],
|
|
'pallet_area_sqm' => $data['palletAreaSqm'],
|
|
'storage_rate_per_sqm_month' => $data['storageRatePerSqmMonth'],
|
|
'remark' => $data['remark'],
|
|
], (int) user_id());
|
|
|
|
$this->remark = '';
|
|
$this->message = '仓储报价已保存,新报价不会覆盖历史版本。';
|
|
}
|
|
|
|
public function setStatus(int $quoteId, string $status): void
|
|
{
|
|
$this->ensureAuthenticated();
|
|
|
|
$quote = ThirdPartyWarehouseQuote::query()->findOrFail($quoteId);
|
|
abort_unless((int) $quote->company_id === (int) company_id(), 404, '仓储报价不存在。');
|
|
|
|
$this->repository()->setStatus($quote, $status, (int) user_id());
|
|
$this->message = '仓储报价状态已更新。';
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
$data = $this->repository()->pageData();
|
|
|
|
return view('business.pages.courier-payables.partials.third-party-warehouse-quotes', [
|
|
'warehouseQuotes' => $data['rows'],
|
|
'warehouseQuoteSummary' => $data['summary'],
|
|
'warehouseQuotesReady' => $data['ready'],
|
|
]);
|
|
}
|
|
|
|
/** @return array<string,array<int,string>> */
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'warehouseName' => ['required', 'string', 'max:191'],
|
|
'effectiveAt' => ['required', 'date_format:Y-m-d'],
|
|
'inboundRatePerTon' => ['required', 'numeric', 'min:0', 'max:999999.9999'],
|
|
'outboundRatePerOrder' => ['required', 'numeric', 'min:0', 'max:999999.9999'],
|
|
'piecesPerPallet' => ['required', 'numeric', 'gt:0', 'max:999999.9999'],
|
|
'palletAreaSqm' => ['required', 'numeric', 'gt:0', 'max:999999.9999'],
|
|
'storageRatePerSqmMonth' => ['required', 'numeric', 'min:0', 'max:999999.9999'],
|
|
'remark' => ['nullable', 'string', 'max:2000'],
|
|
];
|
|
}
|
|
|
|
/** @return array<string,string> */
|
|
protected function messages(): array
|
|
{
|
|
return [
|
|
'piecesPerPallet.gt' => '每托折算件数必须大于 0。',
|
|
'palletAreaSqm.gt' => '每托占地面积必须大于 0。',
|
|
];
|
|
}
|
|
|
|
private function repository(): ThirdPartyWarehouseQuoteRepository
|
|
{
|
|
return app(ThirdPartyWarehouseQuoteRepository::class);
|
|
}
|
|
|
|
private function ensureAuthenticated(): void
|
|
{
|
|
abort_unless(auth()->check(), 401);
|
|
}
|
|
}
|