Commit 6f1de143 authored by luhongguang's avatar luhongguang

update:商品增加修改敏感词判断

parent ccf41451
...@@ -30,5 +30,9 @@ class GoodsException extends BaseException ...@@ -30,5 +30,9 @@ class GoodsException extends BaseException
16 => '到期时间不得小于当前时间', 16 => '到期时间不得小于当前时间',
17 => '商品名称重复,请重新修复', 17 => '商品名称重复,请重新修复',
18 => '库存设置不合理', 18 => '库存设置不合理',
19 => '商品名存在敏感词,请修改后提交',
20 => '商品说明存在敏感词,请修改后提交',
21 => '商品介绍存在敏感词,请修改后提交',
22 => '规则说明存在敏感词,请修改后提交',
]; ];
} }
\ No newline at end of file
...@@ -146,6 +146,22 @@ class GoodsService ...@@ -146,6 +146,22 @@ class GoodsService
if ($skuData["expiration_time"] < date("Y-m-d H:i:s")) { if ($skuData["expiration_time"] < date("Y-m-d H:i:s")) {
throw new GoodsException(['cus' => 16]); throw new GoodsException(['cus' => 16]);
} }
$checkGoodsName = self::isHaveSensitive($skuData["name"], 1);
if ($checkGoodsName) {
throw new GoodsException(['cus' => 19]);
}
$checkGoodsDesc = self::isHaveSensitive($skuData["desc"], 2);
if ($checkGoodsDesc) {
throw new GoodsException(['cus' => 20]);
}
$checkGoodsIntroduce = self::isHaveSensitive($skuData["introduce"], 3);
if ($checkGoodsIntroduce) {
throw new GoodsException(['cus' => 21]);
}
$checkGoodsRuleDesc = self::isHaveSensitive($skuData["rule_desc"], 2);
if ($checkGoodsRuleDesc) {
throw new GoodsException(['cus' => 22]);
}
$skuParams = [ $skuParams = [
"goods_sku_id" => $skuId, "goods_sku_id" => $skuId,
...@@ -437,6 +453,22 @@ class GoodsService ...@@ -437,6 +453,22 @@ class GoodsService
if ($inventoryCount < 0) { if ($inventoryCount < 0) {
throw new GoodsException(['cus' => 18]); throw new GoodsException(['cus' => 18]);
} }
$checkGoodsName = self::isHaveSensitive($params["name"], 1);
if ($checkGoodsName) {
throw new GoodsException(['cus' => 19]);
}
$checkGoodsDesc = self::isHaveSensitive($params["desc"], 2);
if ($checkGoodsDesc) {
throw new GoodsException(['cus' => 20]);
}
$checkGoodsIntroduce = self::isHaveSensitive($params["introduce"], 3);
if ($checkGoodsIntroduce) {
throw new GoodsException(['cus' => 21]);
}
$checkGoodsRuleDesc = self::isHaveSensitive($params["rule_desc"], 2);
if ($checkGoodsRuleDesc) {
throw new GoodsException(['cus' => 22]);
}
$skuParams = [ $skuParams = [
"category_1_id" => $params["category_1_id"], "category_1_id" => $params["category_1_id"],
...@@ -725,7 +757,7 @@ class GoodsService ...@@ -725,7 +757,7 @@ class GoodsService
} }
/** /**
* 敏感词检查 * 是否存在敏感词
* $text 送查内容 * $text 送查内容
* $scene 场景ID 1.标题 2.简介 3.正文 4.评论 6.昵称 7.搜索 * $scene 场景ID 1.标题 2.简介 3.正文 4.评论 6.昵称 7.搜索
* $businessId 1.一点 2.身边 9.VPN * $businessId 1.一点 2.身边 9.VPN
...@@ -735,7 +767,7 @@ class GoodsService ...@@ -735,7 +767,7 @@ class GoodsService
* @return bool|mixed * @return bool|mixed
* @throws \App\Exception\custom\CodeSpecialException * @throws \App\Exception\custom\CodeSpecialException
*/ */
private function checkSensitive($text, $scene, $businessId = 1) private static function isHaveSensitive($text, $scene, $businessId = 1)
{ {
$params = [ $params = [
'businessId' => $businessId, 'businessId' => $businessId,
...@@ -744,6 +776,10 @@ class GoodsService ...@@ -744,6 +776,10 @@ class GoodsService
]; ];
return (new Sensitive())->detect($params); $res = (new Sensitive())->detect($params);
if (empty($res["data"])) {
return false;
}
return true;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment