diff --git a/app/Http/Requestes/MaterielStoreRequest.php b/app/Http/Requestes/MaterielStoreRequest.php index 7ed20f8..25ad45a 100644 --- a/app/Http/Requestes/MaterielStoreRequest.php +++ b/app/Http/Requestes/MaterielStoreRequest.php @@ -17,12 +17,12 @@ class MaterielStoreRequest extends FormRequest public function rules() { return [ - 'year' => ['required', 'int'], - 'quarter' => ['required', new Quarter()], - 'name' => ['required', 'string', 'max:255'], - 'type' => ['required', new Enum(MaterielType::class)], - 'lowest_price' => ['required', 'int'], - 'highest_price' => ['required', 'int', 'gte:lowest_price'], + 'year' => ['bail', 'required', 'int'], + 'quarter' => ['bail', 'required', new Quarter()], + 'name' => ['bail', 'required', 'string', 'max:255'], + 'type' => ['bail', 'required', new Enum(MaterielType::class)], + 'lowest_price' => ['bail', 'required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], + 'highest_price' => ['bail', 'required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/', 'gte:lowest_price'], ]; } diff --git a/app/Http/Requestes/MaterielUpdateRequest.php b/app/Http/Requestes/MaterielUpdateRequest.php index 342c893..7fca878 100644 --- a/app/Http/Requestes/MaterielUpdateRequest.php +++ b/app/Http/Requestes/MaterielUpdateRequest.php @@ -21,8 +21,8 @@ class MaterielUpdateRequest extends FormRequest 'quarter' => ['filled', new Quarter()], 'name' => ['filled', 'string', 'max:255'], 'type' => ['filled', new Enum(MaterielType::class)], - 'lowest_price' => ['filled', 'int'], - 'highest_price' => ['filled', 'int', 'gte:lowest_price'], + 'lowest_price' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], + 'highest_price' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/', 'gte:lowest_price'], 'unit' => ['filled', 'string'], ]; } diff --git a/app/Http/Requestes/RiceShrimpFlowStoreRequest.php b/app/Http/Requestes/RiceShrimpFlowStoreRequest.php index d45d227..1eba1bb 100644 --- a/app/Http/Requestes/RiceShrimpFlowStoreRequest.php +++ b/app/Http/Requestes/RiceShrimpFlowStoreRequest.php @@ -18,7 +18,7 @@ class RiceShrimpFlowStoreRequest extends FormRequest 'year' => ['required', 'int'], 'quarter' => ['required', new Quarter()], 'area' => ['required', 'string'], - 'sales' => ['required', 'int', 'min:0'], + 'sales' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'unit' => ['required', 'string'], ]; } diff --git a/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php b/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php index daa04d9..daeec84 100644 --- a/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php +++ b/app/Http/Requestes/RiceShrimpFlowUpdateRequest.php @@ -18,7 +18,7 @@ class RiceShrimpFlowUpdateRequest extends FormRequest 'year' => ['filled', 'int'], 'quarter' => ['filled', new Quarter()], 'area' => ['filled', 'string'], - 'sales' => ['filled', 'int', 'min:0'], + 'sales' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'unit' => ['filled', 'string'], ]; } diff --git a/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php b/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php index 7550d44..4cf3bb8 100644 --- a/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php +++ b/app/Http/Requestes/RiceShrimpIndustryStoreRequest.php @@ -17,11 +17,11 @@ class RiceShrimpIndustryStoreRequest extends FormRequest return [ 'year' => ['required', 'int'], 'quarter' => ['required', new Quarter()], - 'area' => ['required', 'int', 'min:0'], + 'area' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'area_unit' => ['required', 'string'], - 'product_output' => ['required', 'int', 'min:0'], + 'product_output' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'product_output_unit' => ['required', 'string'], - 'product_value' => ['required', 'int', 'min:0'], + 'product_value' => ['required', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'product_value_unit' => ['required', 'string'], ]; } diff --git a/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php b/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php index 5ffe614..e8a8c77 100644 --- a/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php +++ b/app/Http/Requestes/RiceShrimpIndustryUpdateRequest.php @@ -17,11 +17,11 @@ class RiceShrimpIndustryUpdateRequest extends FormRequest return [ 'year' => ['filled', 'int'], 'quarter' => ['filled', new Quarter()], - 'area' => ['filled', 'int', 'min:0'], + 'area' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'area_unit' => ['filled', 'string'], - 'product_output' => ['filled', 'int', 'min:0'], + 'product_output' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'product_output_unit' => ['filled', 'string'], - 'product_value' => ['filled', 'int', 'min:0'], + 'product_value' => ['filled', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'], 'product_value_unit' => ['filled', 'string'], ]; } diff --git a/app/Http/Resources/MaterielResource.php b/app/Http/Resources/MaterielResource.php index b5b95b6..3698cb6 100644 --- a/app/Http/Resources/MaterielResource.php +++ b/app/Http/Resources/MaterielResource.php @@ -20,8 +20,8 @@ class MaterielResource extends JsonResource 'type' => $this->type, 'year' => $this->year, 'quarter' => $this->quarter, - 'lowest_price' => $this->lowest_price, - 'highest_price' => $this->highest_price, + 'lowest_price' => trim_trailing_zero($this->lowest_price), + 'highest_price' => trim_trailing_zero($this->highest_price), 'unit' => $this->unit, 'created_by' => AdminUserResource::make($this->whenLoaded('createdBy')), 'updated_by' => AdminUserResource::make($this->whenLoaded('updatedBy')), diff --git a/app/Http/Resources/RiceShrimpFlowResource.php b/app/Http/Resources/RiceShrimpFlowResource.php index 95ef931..30c4922 100644 --- a/app/Http/Resources/RiceShrimpFlowResource.php +++ b/app/Http/Resources/RiceShrimpFlowResource.php @@ -19,7 +19,7 @@ class RiceShrimpFlowResource extends JsonResource 'year' => $this->year, 'quarter' => $this->quarter, 'area' => $this->area, - 'sales' => $this->sales, + 'sales' => trim_trailing_zero($this->sales), 'unit' => $this->unit, 'created_by' => AdminUserResource::make($this->whenLoaded('createdBy')), 'updated_by' => AdminUserResource::make($this->whenLoaded('updatedBy')), diff --git a/app/Http/Resources/RiceShrimpIndustryResource.php b/app/Http/Resources/RiceShrimpIndustryResource.php index 801f8ed..f515da2 100644 --- a/app/Http/Resources/RiceShrimpIndustryResource.php +++ b/app/Http/Resources/RiceShrimpIndustryResource.php @@ -18,11 +18,11 @@ class RiceShrimpIndustryResource extends JsonResource 'id' => $this->id, 'year' => $this->year, 'quarter' => $this->quarter, - 'area' => $this->area, + 'area' => trim_trailing_zero($this->area), 'area_unit' => $this->area_unit, - 'product_output' => $this->product_output, + 'product_output' => trim_trailing_zero($this->product_output), 'product_output_unit' => $this->product_output_unit, - 'product_value' => $this->product_value, + 'product_value' => trim_trailing_zero($this->product_value), 'product_value_unit' => $this->product_value_unit, 'created_by' => AdminUserResource::make($this->whenLoaded('createdBy')), 'updated_by' => AdminUserResource::make($this->whenLoaded('updatedBy')), diff --git a/app/helpers.php b/app/helpers.php new file mode 100644 index 0000000..0750a91 --- /dev/null +++ b/app/helpers.php @@ -0,0 +1,10 @@ +id(); $table->integer('year')->comment('年'); $table->tinyInteger('quarter')->comment('季度'); - $table->unsignedBigInteger('area')->comment('面积'); + $table->unsignedDecimal('area', 18, 2)->comment('面积'); $table->string('area_unit')->comment('面积单位'); - $table->unsignedBigInteger('product_output')->comment('产量'); + $table->unsignedDecimal('product_output', 18, 2)->comment('产量'); $table->string('product_output_unit')->comment('产量单位'); - $table->unsignedBigInteger('product_value')->comment('产值'); + $table->unsignedDecimal('product_value', 18, 2)->comment('产值'); $table->string('product_value_unit')->comment('产值单位'); $table->unsignedBigInteger('created_by')->comment('创建人ID'); $table->unsignedBigInteger('updated_by')->comment('修改人ID'); diff --git a/database/migrations/2022_11_01_172739_create_rice_shrimp_flows_table.php b/database/migrations/2022_11_01_172739_create_rice_shrimp_flows_table.php index d84475a..81e5ded 100644 --- a/database/migrations/2022_11_01_172739_create_rice_shrimp_flows_table.php +++ b/database/migrations/2022_11_01_172739_create_rice_shrimp_flows_table.php @@ -18,7 +18,7 @@ return new class extends Migration $table->integer('year')->comment('年'); $table->tinyInteger('quarter')->comment('季度'); $table->string('area')->comment('地区'); - $table->unsignedBigInteger('sales')->comment('销量'); + $table->unsignedDecimal('sales', 18, 2)->comment('销量'); $table->string('unit')->comment('单位'); $table->unsignedBigInteger('created_by')->comment('创建人ID'); $table->unsignedBigInteger('updated_by')->comment('修改人ID'); diff --git a/database/migrations/2022_11_02_104745_create_materiels_table.php b/database/migrations/2022_11_02_104745_create_materiels_table.php index 5f41542..4effc2c 100644 --- a/database/migrations/2022_11_02_104745_create_materiels_table.php +++ b/database/migrations/2022_11_02_104745_create_materiels_table.php @@ -19,8 +19,8 @@ return new class extends Migration $table->tinyInteger('type')->comment('类型: 1 饲料, 2 肥料'); $table->integer('year')->comment('年'); $table->tinyInteger('quarter')->comment('季度'); - $table->unsignedBigInteger('lowest_price')->comment('最低价格'); - $table->unsignedBigInteger('highest_price')->comment('最低价格'); + $table->unsignedDecimal('lowest_price', 18, 2)->comment('最低价格'); + $table->unsignedDecimal('highest_price', 18, 2)->comment('最低价格'); $table->string('unit')->comment('单位'); $table->unsignedBigInteger('created_by')->comment('创建人ID'); $table->unsignedBigInteger('updated_by')->comment('修改人ID');