二十七:子订单表设计、子订单验证规则
一:子订单验证规则
主订单验证入库的时候 子订单也需要进验证入库
(1):生成数据表对应的模型实体
php bin/swoft entity:create --table=orders_detail --pool=db.pool --path=@app/Models

(2):验证规则
<?php
namespace App\Http\MyValidator;
use Swoft\Validator\Annotation\Mapping\IsFloat;
use Swoft\Validator\Annotation\Mapping\IsInt;
use Swoft\Validator\Annotation\Mapping\IsString;
use Swoft\Validator\Annotation\Mapping\Length;
use Swoft\Validator\Annotation\Mapping\Max;
use Swoft\Validator\Annotation\Mapping\Min;
use Swoft\Validator\Annotation\Mapping\Validator;
/**
* 订单明细验证
* @Validator(name="orders_detail")
*/
class OrderDetailValidator{
/**
* @IsInt(message="商品ID不能为空")
* @Min(value=1,message="商品ID不正确")
* @var int
*/
protected $prod_id;
/**
* @IsString(message="商品名称不能空")
* @var string
*/
protected $prod_name;
/**
* @IsFloat(message="商品价格不能为空")
* @Min(value=0,message="商品金额不正确")
* @var float
*/
protected $prod_price;
/**
* @IsInt(message="折扣不能为空")
* @Min(value=1,message="折扣不正确min")
* @Max(value=10,message="折扣不正确max")
* @var int
*/
protected $discount;
/**
* @IsInt(message="商品数量不能为空")
* @Min(value=1,message="商品数量不正确")
* @var int
*/
protected $prod_num;
}

浙公网安备 33010602011771号