46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Purchase;
|
|
|
|
use Modules\Common\Http\Requests\BaseFormRequest;
|
|
|
|
/**
|
|
* 采购单门店单品 新增/修改 验证(amount = 数量×单价 由后端重算)
|
|
*/
|
|
class PurchaseStoreItemRequest extends BaseFormRequest
|
|
{
|
|
protected $stopOnFirstFailure = true;
|
|
|
|
public function rules(): array
|
|
{
|
|
if ($this->isUpdate()) {
|
|
return [
|
|
'quantity' => 'required|integer|min:0',
|
|
'price' => 'nullable|numeric|min:0',
|
|
'weight' => 'nullable|numeric|min:0',
|
|
];
|
|
}
|
|
|
|
return [
|
|
'product_id' => 'required|integer|exists:product,id',
|
|
'quantity' => 'required|integer|min:1',
|
|
'weight' => 'nullable|numeric|min:0',
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'product_id.required' => '请选择商品',
|
|
'product_id.exists' => '商品不存在或已删除',
|
|
'quantity.required' => '采购数量不能为空',
|
|
'quantity.integer' => '采购数量必须为整数',
|
|
'quantity.min' => '采购数量不能小于 0',
|
|
'price.numeric' => '单价必须为数字',
|
|
'price.min' => '单价不能小于 0',
|
|
'weight.numeric' => '称重必须为数字',
|
|
'weight.min' => '称重不能小于 0',
|
|
];
|
|
}
|
|
}
|