coupon-admin/app/validate/Comment.php

53 lines
1.6 KiB
PHP
Raw Normal View History

2021-12-02 10:34:44 +00:00
<?php
namespace app\validate;
2021-12-08 02:25:31 +00:00
use app\model\CommentRule;
2021-12-02 10:34:44 +00:00
use think\Validate;
use app\model\Comment as CommentModel;
class Comment extends Validate
{
protected $rule = [
2021-12-08 02:25:31 +00:00
'comment|评论内容' => 'require|checkComment|max:1024',
2021-12-02 10:34:44 +00:00
'user_code|用户' => 'require|length:32',
'url|图片文件地址' => 'length:0,255',
'type|类型' => 'require|checkType',
'lng|定位信息' => 'require',
'lat|定位信息' => 'require',
'location|位置信息' => 'length:0,200',
];
protected $scene = [
'edit_password' => ['old_password', 'password', 'confirm_password'], //修改密码
];
protected function checkType($value,$rule,$data=[])
{
return isset(CommentModel::allType()[$value]) ? true : '评论类型错误';
}
2021-12-08 02:25:31 +00:00
/**
* 检查评论规则
* */
protected function checkComment($value,$rule,$data=[])
{
$rule = CommentRule::where("state",CommentRule::COMMON_ON)->select();
if($rule->isEmpty()){
return true;
}
foreach ($rule as $item){
$font = explode("|",$item["rule"]);
foreach ($font as $ruleItem){
if(empty(trim($ruleItem))){
continue;
}
if(strpos($value,trim($ruleItem))!=false){
return "评论内容不能包含敏感词语";
}
}
}
return true;
}
2021-12-02 10:34:44 +00:00
}