64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\validate;
|
|
|
|
use think\facade\Config;
|
|
use think\Validate;
|
|
|
|
class CouponRelease extends Validate
|
|
{
|
|
protected $rule = [
|
|
'business_code|商家code' => 'require',
|
|
//'lng|经度' => 'require',
|
|
//'lat|纬度' => 'require',
|
|
'count|总数' => 'require|number|>:0',
|
|
'type|优惠券类型' => 'require',
|
|
'start_time|开始时间' => 'require|date',
|
|
'end_time|结束时间' => 'require|date|checkEndTime',
|
|
'name|优惠券名称' => 'require|length:3,32',
|
|
'money|金额' => 'require|>:0|<=:5000',
|
|
'deduction_money|扣除金额' => 'require|>=:0.1|<=:5000',
|
|
'image_url|预览图' => 'require',
|
|
//'using_rule|使用规则' => '',
|
|
//'punishing_rule|处罚规则' => '',
|
|
//'using_count|使用中' => '',
|
|
//'received_count|已领取的优惠券数量' => '',
|
|
//'edition|发布的版本' => '',
|
|
'status|状态' => 'require|in:1,0',
|
|
'on_shelf|上架状态' => 'require|in:1,0',
|
|
//'intro|详情' => '',
|
|
//'white_list|白名单' => '',
|
|
];
|
|
|
|
protected $scene = [
|
|
'edit' => ['start_time', 'end_time', 'name',"status","on_shelf",'image_url'],
|
|
'api_edit' => ['name', 'type', 'start_time',"end_time","image_url"],
|
|
];
|
|
|
|
// edit 验证场景定义
|
|
public function sceneOrdinary()
|
|
{
|
|
return $this->append('deduction_money', 'checkDeductionMoney');
|
|
}
|
|
|
|
protected function checkEndTime($value, $rule, $data = [])
|
|
{
|
|
if (strtotime($value) <= strtotime($data['start_time'])) {
|
|
return "结束时间不能小于等于开始时间";
|
|
}
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
protected function checkDeductionMoney($value, $rule, $data = [])
|
|
{
|
|
//最小充值
|
|
Config::load('extra/wechat', 'wechat');
|
|
$minCouponDeductionMoney = config('wechat.minCouponDeductionMoney') ?? 0;
|
|
if($minCouponDeductionMoney > 0 &&$minCouponDeductionMoney>$value){
|
|
return "最小扣除佣金{$minCouponDeductionMoney}";
|
|
}
|
|
return true;
|
|
}
|
|
} |