Goods.php
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace app\admin\validate;
use think\Validate;
class Goods extends Validate
{
// 验证规则
protected $rule = [
['goods_name','require','请输入商品名称'],
['goods_sn','require','请输入商品编号'],
['sku','require','请输入商品条形码'],
['cat_id', 'number|gt:0', '商品分类必须填写|商品分类必须选择'],
//['goods_sn', 'unique:goods', '商品编号重复'], // 更多 内置规则 http://www.kancloud.cn/manual/thinkphp5/129356
['shop_price','regex:\d{1,10}(\.\d{1,2})?$','本店售价格式不对。'],
['market_price','regex:\d{1,10}(\.\d{1,2})?$','市场价格式不对。'],
['weight','regex:\d{1,10}(\.\d{1,2})?$','重量格式不对。'],
['exchange_integral','checkExchangeIntegral','积分抵扣金额不能超过商品总额']
];
/**
* 检查积分兑换
* @author dyr
* @return bool
*/
protected function checkExchangeIntegral($value, $rule)
{
$exchange_integral = $value;//I('exchange_integral', 0);
$shop_price = I('shop_price', 0);
$point_rate_value = tpCache('shopping.point_rate',getAdmStoId());
$point_rate_value = empty($point_rate_value) ? 0 : $point_rate_value;
if ($exchange_integral > ($shop_price * $point_rate_value)) {
return '积分抵扣金额不能超过商品总额';
} else {
return true;
}
}
}