rule['record_status'] = 'require|in:' . implode(',', LotteryEnum::getDrawStatusList()); parent::__construct($rules, $message, $field); } /** * 验证规则 */ protected $rule = [ 'lottery_id' => 'require|integer|gt:0', 'lottery_id_optional' => 'integer|gt:0', // 可选的lottery_id 'page' => 'integer|egt:1', 'pageSize' => 'integer|between:1,100', 'status' => 'integer|in:0,1,2,3', 'type' => 'array|length:1,10', // 奖品类型,数组且每个元素为整型 'type.*' => 'integer|length:1,10', // 奖品类型,数组且每个元素为整型 'win_record_id' => 'require|integer|gt:0', 'receiver_name' => 'require|length:2,20|chsAlphaNum', 'receiver_mobile' => 'require|regex:/^1[3-9]\d{9}$/', 'receiver_address' => 'require|length:10,200', 'province' => 'length:1,50', 'city' => 'length:1,50', 'district' => 'length:1,50', 'detail_address' => 'require|length:5,100', 'order_id' => 'require|integer|gt:0', 'draw_record_id' => 'require|integer|gt:0' ]; /** * 提示消息 */ protected $message = [ 'lottery_id.require' => '活动ID不能为空', 'lottery_id.integer' => '活动ID必须是整数', 'lottery_id.gt' => '活动ID必须大于0', 'lottery_id_optional.integer' => '活动ID必须是整数', 'lottery_id_optional.gt' => '活动ID必须大于0', 'page.integer' => '页码必须是整数', 'page.egt' => '页码必须大于等于1', 'pageSize.integer' => '每页数量必须是整数', 'pageSize.between' => '每页数量必须在1-100之间', 'status.integer' => '状态必须是整数', 'status.in' => '状态值不正确', 'record_status.integer' => '状态必须是整数', 'record_status.in' => '状态值不正确', 'type.array' => '奖品类型必须是数组格式', 'type.*.integer' => '奖品类型数组中的每个元素必须是整型', 'type.*.length' => '奖品类型数组中的每个元素长度必须在1-10之间', 'win_record_id.require' => '中奖记录ID不能为空', 'win_record_id.integer' => '中奖记录ID必须是整数', 'win_record_id.gt' => '中奖记录ID必须大于0', 'receiver_name.require' => '收货人姓名不能为空', 'receiver_name.length' => '收货人姓名长度必须在2-20个字符之间', 'receiver_name.chsAlphaNum' => '收货人姓名只能包含中文、字母和数字', 'receiver_mobile.require' => '收货人手机号不能为空', 'receiver_mobile.regex' => '收货人手机号格式不正确', 'receiver_address.require' => '收货地址不能为空', 'receiver_address.length' => '收货地址长度必须在10-200个字符之间', 'province.length' => '省份名称不能超过50个字符', 'city.length' => '城市名称不能超过50个字符', 'district.length' => '区县名称不能超过50个字符', 'detail_address.require' => '详细地址不能为空', 'detail_address.length' => '详细地址长度必须在5-100个字符之间', 'order_id.require' => '订单ID不能为空', 'order_id.integer' => '订单ID必须是整数', 'order_id.gt' => '订单ID必须大于0', 'draw_record_id.require' => '抽奖记录ID不能为空', 'draw_record_id.integer' => '抽奖记录ID必须是整数', 'draw_record_id.gt' => '抽奖记录ID必须大于0' ]; /** * 验证场景 */ protected $scene = [ // 获取活动列表(所有参数都可选) 'activityList' => ['page', 'limit', 'status'], // 获取活动详情(lottery_id必填) 'activityDetail' => ['lottery_id'], // 执行抽奖(lottery_id必填) 'draw' => ['lottery_id'], // 获取用户抽奖机会(lottery_id必填) 'getUserChances' => ['lottery_id'], // 获取用户抽奖记录( 可选,page和pageSize可选) 'getDrawRecords' => ['lottery_id_optional', 'page', 'pageSize', 'record_status'], // 获取用户中奖记录(page和pageSize可选) 'getWinRecords' => ['page', 'pageSize'], // 设置中奖记录收货地址(所有地址相关字段必填) 'setWinRecordAddress' => ['win_record_id', 'receiver_name', 'receiver_mobile', 'receiver_address'], // 设置详细收货地址(包含省市区) 'setDetailAddress' => ['win_record_id', 'receiver_name', 'receiver_mobile', 'province', 'city', 'district', 'detail_address'], // 获取活动排行榜(lottery_id必填,page和pageSize可选) 'getRanking' => ['lottery_id', 'page', 'pageSize'], // 获取奖品列表(lottery_id可选,page、pageSize、type可选) 'getPrizes' => ['lottery_id_optional', 'page', 'pageSize', 'type'], // 获取订单完成后分发抽奖机会 'getLotteryChanceByOrder' => ['order_id'], // 获取抽奖记录详情 'getDrawRecordDetail' => ['draw_record_id'] ]; }