dev
Jing Li 2022-11-02 11:38:04 +08:00
parent cc41bdde4f
commit 637a64ae73
9 changed files with 35 additions and 38 deletions

View File

@ -39,17 +39,6 @@ class RiceShrimpFlowController extends Controller
*/
public function store(RiceShrimpFlowStoreRequest $request): RiceShrimpFlowResource
{
$riceShrimpFlowExists = RiceShrimpFlow::query()
->where('year', $request->input('year'))
->where('quarter', $request->input('quarter'))
->exists();
if ($riceShrimpFlowExists) {
throw ValidationException::withMessages([
'quarter' => ['季度已经存在'],
]);
}
$user = $request->user();
$riceShrimpFlow = new RiceShrimpFlow(
@ -84,6 +73,8 @@ class RiceShrimpFlowController extends Controller
$riceShrimpFlow = RiceShrimpFlow::findOrFail($id);
foreach ([
'year',
'quarter',
'area',
'sales',
] as $key) {

View File

@ -39,17 +39,6 @@ class RiceShrimpIndustryController extends Controller
*/
public function store(RiceShrimpIndustryStoreRequest $request): RiceShrimpIndustryResource
{
$riceShrimpIndustryExists = RiceShrimpIndustry::query()
->where('year', $request->input('year'))
->where('quarter', $request->input('quarter'))
->exists();
if ($riceShrimpIndustryExists) {
throw ValidationException::withMessages([
'quarter' => ['季度已经存在'],
]);
}
$user = $request->user();
$riceShrimpIndustry = new RiceShrimpIndustry(
@ -85,6 +74,8 @@ class RiceShrimpIndustryController extends Controller
$riceShrimpIndustry = RiceShrimpIndustry::findOrFail($id);
foreach ([
'year',
'quarter',
'area',
'product_output',
'product_value',

View File

@ -40,17 +40,6 @@ class RiceShrimpPriceController extends Controller
*/
public function store(RiceShrimpPriceStoreRequest $request): RiceShrimpPriceResource
{
$riceShrimpPriceExists = RiceShrimpPrice::query()
->where('year', $request->input('year'))
->where('quarter', $request->input('quarter'))
->exists();
if ($riceShrimpPriceExists) {
throw ValidationException::withMessages([
'quarter' => ['季度已经存在'],
]);
}
$user = $request->user();
$riceShrimpPrice = RiceShrimpPrice::create(
@ -82,7 +71,15 @@ class RiceShrimpPriceController extends Controller
{
$riceShrimpPrice = RiceShrimpPrice::findOrFail($id);
$riceShrimpPrice->price = $request->input('price');
foreach ([
'year',
'quarter',
'price',
] as $key) {
if ($request->filled($key)) {
$riceShrimpPrice->{$key} = $request->input($key);
}
}
if ($riceShrimpPrice->isDirty()) {
$riceShrimpPrice->updated_by = $request->user()->id;

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@ -16,7 +17,7 @@ class RiceShrimpFlowStoreRequest extends FormRequest
{
return [
'year' => ['required', 'int'],
'quarter' => ['required', 'int', Rule::in([1, 2, 3, 4])],
'quarter' => ['required', new Quarter()],
'area' => ['required', 'int'],
'sales' => ['required', 'int', 'min:0'],
];

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
class RiceShrimpFlowUpdateRequest extends FormRequest
@ -14,6 +15,8 @@ class RiceShrimpFlowUpdateRequest extends FormRequest
public function rules()
{
return [
'year' => ['filled', 'int'],
'quarter' => ['filled', new Quarter()],
'area' => ['filled', 'int'],
'sales' => ['filled', 'int', 'min:0'],
];
@ -22,6 +25,8 @@ class RiceShrimpFlowUpdateRequest extends FormRequest
public function attributes()
{
return [
'year' => '年份',
'quarter' => '季度',
'area' => '地区',
'sales' => '销量',
];

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@ -16,7 +17,7 @@ class RiceShrimpIndustryStoreRequest extends FormRequest
{
return [
'year' => ['required', 'int'],
'quarter' => ['required', 'int', Rule::in([1, 2, 3, 4])],
'quarter' => ['required', new Quarter()],
'area' => ['required', 'int', 'min:0'],
'product_output' => ['required', 'int', 'min:0'],
'product_value' => ['required', 'int', 'min:0'],

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@ -15,6 +16,8 @@ class RiceShrimpIndustryUpdateRequest extends FormRequest
public function rules()
{
return [
'year' => ['filled', 'int'],
'quarter' => ['filled', new Quarter()],
'area' => ['filled', 'int', 'min:0'],
'product_output' => ['filled', 'int', 'min:0'],
'product_value' => ['filled', 'int', 'min:0'],
@ -24,6 +27,8 @@ class RiceShrimpIndustryUpdateRequest extends FormRequest
public function attributes()
{
return [
'year' => '年份',
'quarter' => '季度',
'area' => '面积',
'product_output' => '产量',
'product_value' => '产值',

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@ -16,7 +17,7 @@ class RiceShrimpPriceStoreRequest extends FormRequest
{
return [
'year' => ['required', 'int'],
'quarter' => ['required', 'int', Rule::in([1, 2, 3, 4])],
'quarter' => ['required', new Quarter()],
'price' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
];
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Requestes;
use App\Rules\Quarter;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
@ -15,13 +16,17 @@ class RiceShrimpPriceUpdateRequest extends FormRequest
public function rules()
{
return [
'price' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
'year' => ['filled', 'int'],
'quarter' => ['filled', new Quarter()],
'price' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
];
}
public function attributes()
{
return [
'year' => '年份',
'quarter' => '季度',
'price' => '价格',
];
}