coupon-admin/app/validate/CouponRelease.php

78 lines
2.6 KiB
PHP
Raw Normal View History

2021-11-25 10:11:50 +00:00
<?php
namespace app\validate;
2021-12-15 07:04:20 +00:00
use think\facade\Config;
2021-11-25 10:11:50 +00:00
use think\Validate;
class CouponRelease extends Validate
{
protected $rule = [
'business_code|商家code' => 'require',
//'lng|经度' => 'require',
//'lat|纬度' => 'require',
'count|总数' => 'require|number|>:0',
2022-03-31 06:42:56 +00:00
'type|签到券类型' => 'require|>:0',
2021-11-25 10:11:50 +00:00
'start_time|开始时间' => 'require|date',
'end_time|结束时间' => 'require|date|checkEndTime',
2022-03-31 06:42:56 +00:00
'name|签到券名称' => 'require|length:3,32',
2022-01-19 05:40:46 +00:00
//'money|金额' => 'require|>:0|<=:5000',
2022-02-08 06:32:23 +00:00
'deduction_money|扣除金额' => 'require|>=:0|<=:100000',
2021-12-17 06:52:51 +00:00
'image_url|预览图' => 'require',
2021-11-25 10:11:50 +00:00
//'using_rule|使用规则' => '',
//'punishing_rule|处罚规则' => '',
//'using_count|使用中' => '',
2022-03-31 06:42:56 +00:00
//'received_count|已领取的签到券数量' => '',
2021-11-25 10:11:50 +00:00
//'edition|发布的版本' => '',
'status|状态' => 'require|in:1,0',
'on_shelf|上架状态' => 'require|in:1,0',
2022-01-20 05:56:21 +00:00
'on_screen|展示到商圈大屏' => 'require|in:1,0',
2021-11-25 10:11:50 +00:00
//'intro|详情' => '',
2021-12-23 07:00:33 +00:00
//'content|详情' => '',
2021-12-13 07:57:27 +00:00
//'white_list|白名单' => '',
2021-11-25 10:11:50 +00:00
];
2022-01-20 05:56:21 +00:00
protected $message = [
'business_code.require' => '商家信息错误',
2022-03-31 06:42:56 +00:00
'type' => '签到券类型错误',
2022-01-20 05:56:21 +00:00
'status' => '状态错误',
'on_shelf' => '上架状态错误',
'on_screen' => '展示到商圈大屏状态错误',
];
2021-11-25 10:11:50 +00:00
protected $scene = [
2022-01-20 05:56:21 +00:00
'edit' => ['type','start_time', 'end_time', 'name',"status","on_shelf",'image_url'],
'api_edit' => ['type','name', 'type', 'start_time',"end_time","image_url"],
2021-11-25 10:11:50 +00:00
];
2021-12-16 02:34:06 +00:00
// edit 验证场景定义
public function sceneOrdinary()
{
2022-03-24 03:08:28 +00:00
return $this->append("deduction_money",'checkDeductionMoney');
2021-12-16 02:34:06 +00:00
}
2021-11-25 10:11:50 +00:00
protected function checkEndTime($value, $rule, $data = [])
{
if (strtotime($value) <= strtotime($data['start_time'])) {
return "结束时间不能小于等于开始时间";
}
return true;
}
2021-12-15 07:04:20 +00:00
protected function checkDeductionMoney($value, $rule, $data = [])
{
2022-03-24 02:59:46 +00:00
if ($value <= 0) {
return "最小扣除佣金不能为0";
}
2021-12-15 07:04:20 +00:00
//最小充值
Config::load('extra/wechat', 'wechat');
$minCouponDeductionMoney = config('wechat.minCouponDeductionMoney') ?? 0;
2022-03-24 02:59:46 +00:00
if ($minCouponDeductionMoney > $value) {
2021-12-15 07:04:20 +00:00
return "最小扣除佣金{$minCouponDeductionMoney}";
}
return true;
}
2021-11-25 10:11:50 +00:00
}