wyyl/beike/Admin/Http/Requests/ProductRequest.php

72 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* PageRequest.php
*
* @copyright 2022 beikeshop.com - All Rights Reserved
* @link https://beikeshop.com
* @author Edward Yang <yangjin@guangda.work>
* @created 2022-08-19 21:58:20
* @modified 2022-08-19 21:58:20
*/
namespace Beike\Admin\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'descriptions.*.name' => 'required|string|min:3|max:128',
'brand_id' => 'int',
// 'skus.*.sku' => 'required|string',
'skus.*.price' => 'required|numeric',
// 'skus.*.origin_price' => 'required|numeric',
// 'skus.*.cost_price' => 'numeric',
];
// 判断:根据是否为 直接下单产品 进行对应的判断
if($this->active == 1){
// 直接下单产品 - 最小起订量必填
$rules['minimum_order'] = 'required|numeric|gt:0';
}else{
$rules['skus.*.origin_price'] = 'required|numeric';
}
// 判断:销售方式为按 批 卖每批的数量必须大于0
if($this->sales_method == 'batches'){
$rules['piece_to_batch'] = 'required|numeric|gt:0';
}
return $rules;
}
public function attributes()
{
return [
'descriptions.*.name' => trans('product.name'),
'brand_id' => trans('product.brand'),
// 'skus.*.sku' => trans('product.sku'),
'skus.*.price' => trans('product.price'),
'skus.*.origin_price' => trans('product.origin_price'),
// 'skus.*.cost_price' => trans('product.cost_price'),
'minimum_order' => trans('product.minimum_order'),
'piece_to_batch' => trans('product.one_batch_is_equal_to'),
];
}
}