first commit
This commit is contained in:
1
金壶/ydyd_service/application/common/validate/.pydio
Normal file
1
金壶/ydyd_service/application/common/validate/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
dc0c4198-6f01-4d71-9ac1-4d89f0fbba9f
|
||||
63
金壶/ydyd_service/application/common/validate/BaseValidate.php
Normal file
63
金壶/ydyd_service/application/common/validate/BaseValidate.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\facade\Request;
|
||||
use think\Validate;
|
||||
|
||||
class BaseValidate extends Validate{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* 公用验证方法
|
||||
* @param array $data 待验证数据
|
||||
* @param string $scene 验证场景
|
||||
* @return array
|
||||
*/
|
||||
public function checkParam($scene=''){
|
||||
$res = [];
|
||||
|
||||
if (request()->isPost()){
|
||||
$data = input('param.');
|
||||
|
||||
if ($scene==''){
|
||||
$result = $this->check($data);
|
||||
}else{
|
||||
$result = $this->scene($scene)->check($data);
|
||||
}
|
||||
|
||||
if (!$result){
|
||||
$res['code'] = 5000;
|
||||
$res['scene'] = $scene;
|
||||
$res['msg'] = $this->getError();
|
||||
|
||||
}else{
|
||||
$res['code'] = 200;
|
||||
$res['msg'] = 'success';
|
||||
}
|
||||
}else{
|
||||
$res['code'] = 5010;
|
||||
$res['msg'] = '非法请求';
|
||||
}
|
||||
|
||||
if ($res['code']!=200){
|
||||
ajax_return($res);
|
||||
}
|
||||
return $res;
|
||||
|
||||
}
|
||||
}
|
||||
1
金壶/ydyd_service/application/common/validate/goods/.pydio
Normal file
1
金壶/ydyd_service/application/common/validate/goods/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
32a57b98-f412-4be2-9349-a5ac07b9e688
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\validate\goods;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class GoodsValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'goods_name|商品名称'=>'require',
|
||||
'goods_id|商品id'=>'require|number',
|
||||
'spu_id|'=>'require|number',
|
||||
'sku_id|商品sku_id'=>'require|integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [];
|
||||
/**
|
||||
* 定义验证场景
|
||||
* @var array ['场景名称1'=>[验证字段1,验证字段2,…],…]
|
||||
* 场景名称建议命名规范:控制器名_方法名
|
||||
*/
|
||||
protected $scene = [
|
||||
'goods_detail'=>['sku_id'],
|
||||
'goods_search'=>[null],//[null]或[''];[]校验全部$rule定义的字段
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
a4d496fc-28e0-43e4-a39a-afb87f73b1c6
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\validate\UserAddress;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class UserAddressValidate extends BaseValidate
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'area_id|区县id'=>'require|number',
|
||||
// 'address_id|地址id'=>'require|number',
|
||||
'consignee|收件人名称'=>'require',
|
||||
|
||||
'tel|收件人联系电话'=>'require|number',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [];
|
||||
/**
|
||||
* 定义验证场景
|
||||
* @var array ['场景名称1'=>[验证字段1,验证字段2,…],…]
|
||||
* 场景名称建议命名规范:控制器名_方法名
|
||||
*/
|
||||
protected $scene = [
|
||||
'userAddress_setDefaultAddress'=>['address_id'],
|
||||
'UserAddress_makeChangeAddress'=>['address_id','consignee','tel','area_id'],
|
||||
];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user