添加数据验证

This commit is contained in:
lewis 2025-07-17 11:35:35 +08:00
parent e3beb860d3
commit a0c2eaaf53
9 changed files with 646 additions and 576 deletions

View File

@ -48,7 +48,7 @@ class DishesLists extends BaseAdminDataLists implements ListsSearchInterface
$dishesCategoryIds = DishesCategory::where('id', $this->params['dishes_category_id'])->whereOr('pid', $this->params['dishes_category_id'])->column('id'); $dishesCategoryIds = DishesCategory::where('id', $this->params['dishes_category_id'])->whereOr('pid', $this->params['dishes_category_id'])->column('id');
$query->whereIn('dishes_category_id', $dishesCategoryIds); $query->whereIn('dishes_category_id', $dishesCategoryIds);
} }
return $query->field(['id', 'name', 'dishes_category_id', 'create_time']) return $query->field(['id', 'name', 'dishes_category_id', 'create_time', 'image', 'intro'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()

View File

@ -30,6 +30,8 @@ class DishesLogic extends BaseLogic
try { try {
Dishes::create([ Dishes::create([
'name' => $params['name'], 'name' => $params['name'],
'image' => $params['image'],
'intro' => $params['intro'],
'dishes_category_id' => $params['dishes_category_id'], 'dishes_category_id' => $params['dishes_category_id'],
]); ]);
@ -56,6 +58,8 @@ class DishesLogic extends BaseLogic
try { try {
Dishes::where('id', $params['id'])->update([ Dishes::where('id', $params['id'])->update([
'name' => $params['name'], 'name' => $params['name'],
'image' => $params['image'],
'intro' => $params['intro'],
'dishes_category_id' => $params['dishes_category_id'], 'dishes_category_id' => $params['dishes_category_id'],
]); ]);
@ -93,4 +97,4 @@ class DishesLogic extends BaseLogic
{ {
return Dishes::findOrEmpty($params['id'])->toArray(); return Dishes::findOrEmpty($params['id'])->toArray();
} }
} }

View File

@ -1,82 +1,90 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* Dishes验证器 * Dishes验证器
* Class DishesValidate * Class DishesValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class DishesValidate extends BaseValidate class DishesValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'name' => 'require',
'dishes_category_id' => 'require',
'image' => 'require',
/** 'intro' => 'require',
* 参数描述 ];
* @var string[]
*/
protected $field = [ /**
'id' => 'id', * 参数描述
]; * @var string[]
*/
protected $field = [
/** 'id' => 'id',
* @notes 添加场景 'name' => '名称',
* @return DishesValidate 'dishes_category_id' => '菜品分类id',
* @author likeadmin 'image' => '图片',
* @date 2025/07/11 11:41 'intro' => '简介',
*/ ];
public function sceneAdd()
{
return $this->remove('id', true); /**
} * @notes 添加场景
* @return DishesValidate
* @author likeadmin
/** * @date 2025/07/11 11:41
* @notes 编辑场景 */
* @return DishesValidate public function sceneAdd()
* @author likeadmin {
* @date 2025/07/11 11:41 return $this->remove('id', true);
*/ }
public function sceneEdit()
{
return $this->only(['id']); /**
} * @notes 编辑场景
* @return DishesValidate
* @author likeadmin
/** * @date 2025/07/11 11:41
* @notes 删除场景 */
* @return DishesValidate public function sceneEdit()
* @author likeadmin {
* @date 2025/07/11 11:41 return $this->only(['id', 'dishes_category_id', 'name', 'image', 'intro']);
*/ }
public function sceneDelete()
{
return $this->only(['id']); /**
} * @notes 删除场景
* @return DishesValidate
* @author likeadmin
/** * @date 2025/07/11 11:41
* @notes 详情场景 */
* @return DishesValidate public function sceneDelete()
* @author likeadmin {
* @date 2025/07/11 11:41 return $this->only(['id']);
*/ }
public function sceneDetail()
{
return $this->only(['id']); /**
} * @notes 详情场景
* @return DishesValidate
} * @author likeadmin
* @date 2025/07/11 11:41
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,82 +1,86 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* ProductCategory验证器 * ProductCategory验证器
* Class ProductCategoryValidate * Class ProductCategoryValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProductCategoryValidate extends BaseValidate class ProductCategoryValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'pid' => 'require',
'name' => 'require',
];
/**
* 参数描述
* @var string[] /**
*/ * 参数描述
protected $field = [ * @var string[]
'id' => 'id', */
]; protected $field = [
'id' => 'id',
'pid' => '上级',
/** 'name' => '名称',
* @notes 添加场景 ];
* @return ProductCategoryValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 添加场景
public function sceneAdd() * @return ProductCategoryValidate
{ * @author likeadmin
return $this->remove('id', true); * @date 2025/07/11 11:41
} */
public function sceneAdd()
{
/** return $this->remove('id', true);
* @notes 编辑场景 }
* @return ProductCategoryValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 编辑场景
public function sceneEdit() * @return ProductCategoryValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneEdit()
{
/** return $this->only(['id', 'pid', 'name']);
* @notes 删除场景 }
* @return ProductCategoryValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 删除场景
public function sceneDelete() * @return ProductCategoryValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneDelete()
{
/** return $this->only(['id']);
* @notes 详情场景 }
* @return ProductCategoryValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 详情场景
public function sceneDetail() * @return ProductCategoryValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneDetail()
} {
return $this->only(['id']);
}
}

View File

@ -1,82 +1,86 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* ProductUnit验证器 * ProductUnit验证器
* Class ProductUnitValidate * Class ProductUnitValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProductUnitValidate extends BaseValidate class ProductUnitValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'name' => 'require',
'conversion_value' => 'require',
];
/**
* 参数描述
* @var string[] /**
*/ * 参数描述
protected $field = [ * @var string[]
'id' => 'id', */
]; protected $field = [
'id' => 'id',
'name' => '名称',
/** 'conversion_value' => '换算值',
* @notes 添加场景 ];
* @return ProductUnitValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 添加场景
public function sceneAdd() * @return ProductUnitValidate
{ * @author likeadmin
return $this->remove('id', true); * @date 2025/07/11 11:41
} */
public function sceneAdd()
{
/** return $this->remove('id', true);
* @notes 编辑场景 }
* @return ProductUnitValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 编辑场景
public function sceneEdit() * @return ProductUnitValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneEdit()
{
/** return $this->only(['id']);
* @notes 删除场景 }
* @return ProductUnitValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 删除场景
public function sceneDelete() * @return ProductUnitValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneDelete()
{
/** return $this->only(['id']);
* @notes 详情场景 }
* @return ProductUnitValidate
* @author likeadmin
* @date 2025/07/11 11:41 /**
*/ * @notes 详情场景
public function sceneDetail() * @return ProductUnitValidate
{ * @author likeadmin
return $this->only(['id']); * @date 2025/07/11 11:41
} */
public function sceneDetail()
} {
return $this->only(['id']);
}
}

View File

@ -1,82 +1,96 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* Product验证器 * Product验证器
* Class ProductValidate * Class ProductValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProductValidate extends BaseValidate class ProductValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'category_id' => 'require',
'unit_id' => 'require',
'name' => 'require',
/** 'image' => 'require',
* 参数描述 'intro' => 'require',
* @var string[] 'conent' => 'require',
*/ 'product_type' => 'require',
protected $field = [ ];
'id' => 'id',
];
/**
* 参数描述
/** * @var string[]
* @notes 添加场景 */
* @return ProductValidate protected $field = [
* @author likeadmin 'id' => 'id',
* @date 2025/07/11 11:41 'category_id' => '分类',
*/ 'unit_id' => '单位',
public function sceneAdd() 'name' => '名称',
{ 'image' => '图片',
return $this->remove('id', true); 'intro' => '简介',
} 'conent' => '内容',
'product_type' => '商品类型',
];
/**
* @notes 编辑场景
* @return ProductValidate /**
* @author likeadmin * @notes 添加场景
* @date 2025/07/11 11:41 * @return ProductValidate
*/ * @author likeadmin
public function sceneEdit() * @date 2025/07/11 11:41
{ */
return $this->only(['id']); public function sceneAdd()
} {
return $this->remove('id', true);
}
/**
* @notes 删除场景
* @return ProductValidate /**
* @author likeadmin * @notes 编辑场景
* @date 2025/07/11 11:41 * @return ProductValidate
*/ * @author likeadmin
public function sceneDelete() * @date 2025/07/11 11:41
{ */
return $this->only(['id']); public function sceneEdit()
} {
return $this->only(['id', 'category_id', 'unit_id', 'name', 'image', 'intro', 'conent', 'product_type']);
}
/**
* @notes 详情场景
* @return ProductValidate /**
* @author likeadmin * @notes 删除场景
* @date 2025/07/11 11:41 * @return ProductValidate
*/ * @author likeadmin
public function sceneDetail() * @date 2025/07/11 11:41
{ */
return $this->only(['id']); public function sceneDelete()
} {
return $this->only(['id']);
} }
/**
* @notes 详情场景
* @return ProductValidate
* @author likeadmin
* @date 2025/07/11 11:41
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,82 +1,94 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* ProjectDishesProduct验证器 * ProjectDishesProduct验证器
* Class ProjectDishesProductValidate * Class ProjectDishesProductValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProjectDishesProductValidate extends BaseValidate class ProjectDishesProductValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'project_id' => 'require',
'dishes_id' => 'require',
'product_id' => 'require',
/** 'unit_id' => 'require',
* 参数描述 'nums' => 'require',
* @var string[] 'consume_time' => 'require',
*/ ];
protected $field = [
'id' => 'id',
]; /**
* 参数描述
* @var string[]
/** */
* @notes 添加场景 protected $field = [
* @return ProjectDishesProductValidate 'id' => 'id',
* @author likeadmin 'project_id' => '项目ID',
* @date 2025/07/16 15:09 'dishes_id' => '菜品ID',
*/ 'product_id' => '商品ID',
public function sceneAdd() 'unit_id' => '单位ID',
{ 'nums' => '数量',
return $this->remove('id', true); 'consume_time' => '食用时间',
} ];
/** /**
* @notes 编辑场景 * @notes 添加场景
* @return ProjectDishesProductValidate * @return ProjectDishesProductValidate
* @author likeadmin * @author likeadmin
* @date 2025/07/16 15:09 * @date 2025/07/16 15:09
*/ */
public function sceneEdit() public function sceneAdd()
{ {
return $this->only(['id']); return $this->remove('id', true);
} }
/** /**
* @notes 删除场景 * @notes 编辑场景
* @return ProjectDishesProductValidate * @return ProjectDishesProductValidate
* @author likeadmin * @author likeadmin
* @date 2025/07/16 15:09 * @date 2025/07/16 15:09
*/ */
public function sceneDelete() public function sceneEdit()
{ {
return $this->only(['id']); return $this->only(['id', 'project_id', 'dishes_id', 'product_id', 'unit_id', 'nums', 'consume_time']);
} }
/** /**
* @notes 详情场景 * @notes 删除场景
* @return ProjectDishesProductValidate * @return ProjectDishesProductValidate
* @author likeadmin * @author likeadmin
* @date 2025/07/16 15:09 * @date 2025/07/16 15:09
*/ */
public function sceneDetail() public function sceneDelete()
{ {
return $this->only(['id']); return $this->only(['id']);
} }
}
/**
* @notes 详情场景
* @return ProjectDishesProductValidate
* @author likeadmin
* @date 2025/07/16 15:09
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,82 +1,88 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* ProjectDishes验证器 * ProjectDishes验证器
* Class ProjectDishesValidate * Class ProjectDishesValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProjectDishesValidate extends BaseValidate class ProjectDishesValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'project_id' => 'require',
'dishes_id' => 'require',
'consume_time' => 'require',
/** ];
* 参数描述
* @var string[]
*/ /**
protected $field = [ * 参数描述
'id' => 'id', * @var string[]
]; */
protected $field = [
'id' => 'id',
/** 'project_id' => '项目ID',
* @notes 添加场景 'dishes_id' => '菜品ID',
* @return ProjectDishesValidate 'consume_time' => '食用时间',
* @author likeadmin ];
* @date 2025/07/16 15:09
*/
public function sceneAdd() /**
{ * @notes 添加场景
return $this->remove('id', true); * @return ProjectDishesValidate
} * @author likeadmin
* @date 2025/07/16 15:09
*/
/** public function sceneAdd()
* @notes 编辑场景 {
* @return ProjectDishesValidate return $this->remove('id', true);
* @author likeadmin }
* @date 2025/07/16 15:09
*/
public function sceneEdit() /**
{ * @notes 编辑场景
return $this->only(['id']); * @return ProjectDishesValidate
} * @author likeadmin
* @date 2025/07/16 15:09
*/
/** public function sceneEdit()
* @notes 删除场景 {
* @return ProjectDishesValidate return $this->only(['id']);
* @author likeadmin }
* @date 2025/07/16 15:09
*/
public function sceneDelete() /**
{ * @notes 删除场景
return $this->only(['id']); * @return ProjectDishesValidate
} * @author likeadmin
* @date 2025/07/16 15:09
*/
/** public function sceneDelete()
* @notes 详情场景 {
* @return ProjectDishesValidate return $this->only(['id', 'project_id', 'dishes_id', 'consume_time']);
* @author likeadmin }
* @date 2025/07/16 15:09
*/
public function sceneDetail() /**
{ * @notes 详情场景
return $this->only(['id']); * @return ProjectDishesValidate
} * @author likeadmin
* @date 2025/07/16 15:09
} */
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -1,82 +1,100 @@
<?php <?php
namespace app\admin\validate; namespace app\admin\validate;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* Project验证器 * Project验证器
* Class ProjectValidate * Class ProjectValidate
* @package app\admin\validate * @package app\admin\validate
*/ */
class ProjectValidate extends BaseValidate class ProjectValidate extends BaseValidate
{ {
/** /**
* 设置校验规则 * 设置校验规则
* @var string[] * @var string[]
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
]; 'name' => 'require',
'address' => 'require',
'start_time' => 'require',
/** 'end_time' => 'require',
* 参数描述 'linkman' => 'require',
* @var string[] 'contacts_dept' => 'require',
*/ 'contact_number' => 'require',
protected $field = [ 'area_manager_id' => 'require',
'id' => 'id', 'project_status' => 'require',
]; ];
/** /**
* @notes 添加场景 * 参数描述
* @return ProjectValidate * @var string[]
* @author likeadmin */
* @date 2025/07/16 15:09 protected $field = [
*/ 'id' => 'id',
public function sceneAdd() 'name' => '名称',
{ 'address' => '地址',
return $this->remove('id', true); 'start_time' => '开始时间',
} 'end_time' => '结束时间',
'linkman' => '联系人',
'contacts_dept' => '联系部门',
/** 'contact_number' => '联系电话',
* @notes 编辑场景 'area_manager_id' => '区域经理',
* @return ProjectValidate 'project_status' => '项目状态',
* @author likeadmin ];
* @date 2025/07/16 15:09
*/
public function sceneEdit() /**
{ * @notes 添加场景
return $this->only(['id']); * @return ProjectValidate
} * @author likeadmin
* @date 2025/07/16 15:09
*/
/** public function sceneAdd()
* @notes 删除场景 {
* @return ProjectValidate return $this->remove('id', true);
* @author likeadmin }
* @date 2025/07/16 15:09
*/
public function sceneDelete() /**
{ * @notes 编辑场景
return $this->only(['id']); * @return ProjectValidate
} * @author likeadmin
* @date 2025/07/16 15:09
*/
/** public function sceneEdit()
* @notes 详情场景 {
* @return ProjectValidate return $this->only(['id', 'name', 'address', 'start_time', 'end_time', 'linkman', 'contacts_dept', 'contact_number', 'area_manager_id', 'project_status']);
* @author likeadmin }
* @date 2025/07/16 15:09
*/
public function sceneDetail() /**
{ * @notes 删除场景
return $this->only(['id']); * @return ProjectValidate
} * @author likeadmin
* @date 2025/07/16 15:09
} */
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectValidate
* @author likeadmin
* @date 2025/07/16 15:09
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}