'number', 'limit|条数' => 'number', 'goods_name|商品名称' => 'max:20', 'user_isli|用户ISLI标识码' => 'require', 'goods_isli|商品ISLI标识码' => 'require', 'goods_num|商品数量' => 'require|number|>:0', 'use_years|使用年限' => 'require|number|>:0', // 'platform' => '、require|number|in:1,2', // 'hot' => 'require|number|in:1,2', // 'hotsale' => 'require|number|in:1,2', 'source_type' => 'max:20', 'entrust_time' => 'checkDateTime', 'record_type' => 'number|in:1,2', 'entrust_user_name' => 'max:30', 'authorization' => 'number|in:1,2', 'pay_type' => 'number|in:1,2', 'entrust_name' => 'max:300', 'type' => 'require|in:1,2,3', 'goods_status' => 'checkStatusStr', 'createtime' => 'checkDateTime', ]; /** * 提示消息. */ protected $message = [ ]; /** * 字段描述. */ protected $field = [ ]; /** * 验证场景. */ protected $scene = [ 'list' => ['page', 'limit', 'goods_name'], 'addShoppingCar' => ['user_isli', 'goods_isli', 'use_years'], 'delShoppingCar' => ['user_isli', 'goods_isli'], 'addCarGoodsCount' => ['user_isli', 'goods_isli'], 'decCarGoodsCount' => ['user_isli', 'goods_isli'], 'getShoppingCar' => ['user_isli'], 'getTypeGoods' => ['type'], 'searchGoods' => ['entrust_time', 'record_type', 'entrust_user_name', 'authorization', 'pay_type', 'entrust_name', 'source_type', 'goods_status', 'page', 'limit'], ]; function checkDateTime($value){ if(!is_array($value)){ return "时间格式为数组"; } if(count($value) != 2){ return "时间数组错误"; } if(!isset($value[0]) || !isset($value[1]) || empty($value[0]) || empty($value[1])){ return "时间数组错误"; } if(strtotime($value[0]) == false || strtotime($value[1]) == false){ return "格式错误"; } return true; } function checkStatusStr($value){ if(empty($value)){ return true; } if(!is_string($value)){ return "格式错误"; } $arr = explode(',', $value); if(count($arr) <= 0){ return "数据错误"; } foreach($arr as $val){ if(!preg_match("/^\d*$/" , $val)){ return "需为数字"; } } return true; } }