diff --git a/app/Http/Controllers/RiceShrimpFlowController.php b/app/Http/Controllers/RiceShrimpFlowController.php index 737ef90..dc4ed48 100644 --- a/app/Http/Controllers/RiceShrimpFlowController.php +++ b/app/Http/Controllers/RiceShrimpFlowController.php @@ -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) { diff --git a/app/Http/Controllers/RiceShrimpIndustryController.php b/app/Http/Controllers/RiceShrimpIndustryController.php index 2ecceb2..60a0abf 100644 --- a/app/Http/Controllers/RiceShrimpIndustryController.php +++ b/app/Http/Controllers/RiceShrimpIndustryController.php @@ -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', diff --git a/app/Http/Controllers/RiceShrimpPriceController.php b/app/Http/Controllers/RiceShrimpPriceController.php index 37ef63c..f9a8e37 100644 --- a/app/Http/Controllers/RiceShrimpPriceController.php +++ b/app/Http/Controllers/RiceShrimpPriceController.php @@ -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; diff --git a/app/Http/Requestes/RiceShrimpFlowStoreRequest.php b/app/Http/Requestes/RiceShrimpFlowStoreRequest.php index e69f55d..682e686 100644 --- a/app/Http/Requestes/RiceShrimpFlowStoreRequest.php +++ b/app/Http/Requestes/RiceShrimpFlowStoreRequest.php @@ -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'], ]; diff --git a/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php b/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php index 337886a..0a381b4 100644 --- a/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php +++ b/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php @@ -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' => '销量', ]; diff --git a/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php b/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php index 17d7d49..c0087be 100644 --- a/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php +++ b/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php @@ -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'], diff --git a/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php b/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php index d240546..b93962b 100644 --- a/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php +++ b/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php @@ -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' => '产值', diff --git a/app/Http/Requestes/RiceShrimpPriceStoreRequest.php b/app/Http/Requestes/RiceShrimpPriceStoreRequest.php index 276d3a1..fc17164 100644 --- a/app/Http/Requestes/RiceShrimpPriceStoreRequest.php +++ b/app/Http/Requestes/RiceShrimpPriceStoreRequest.php @@ -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})?$/'], ]; } diff --git a/app/Http/Requestes/RiceShrimpPriceUpdateRequest.php b/app/Http/Requestes/RiceShrimpPriceUpdateRequest.php index fa9f852..44c2eab 100644 --- a/app/Http/Requestes/RiceShrimpPriceUpdateRequest.php +++ b/app/Http/Requestes/RiceShrimpPriceUpdateRequest.php @@ -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' => '价格', ]; }