Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
|
1478ee569f | 1 year ago |
|
34aaa3c6d8 | 1 year ago |
|
a08014988f | 1 year ago |
|
2165db8af3 | 1 year ago |
|
b605aa3484 | 1 year ago |
|
6b906b1b1f | 1 year ago |
|
0d18c65ee6 | 1 year ago |
|
5e5cd0c62c | 1 year ago |
|
88a772aa19 | 1 year ago |
|
b26f0bd431 | 1 year ago |
|
29a858757d | 1 year ago |
|
7e3949936f | 1 year ago |
|
a7db2d00ed | 1 year ago |
|
9879d074ae | 1 year ago |
|
b3562824ee | 1 year ago |
|
d22ea6071f | 1 year ago |
|
6e5ebffa14 | 1 year ago |
@ -1,233 +0,0 @@ |
||||
<?php |
||||
|
||||
return [ |
||||
[ |
||||
'name' => 'accessKeyId', |
||||
'title' => 'AccessKey ID', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'LTAI5tEh3A4HH9SnAywhwtQV', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'accessKeySecret', |
||||
'title' => 'AccessKey Secret', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'oxeX7GZoGiKHGkshA2WbPn1z1hZo5a', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'bucket', |
||||
'title' => 'Bucket名称', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'hzy-shop', |
||||
'rule' => 'required;bucket', |
||||
'msg' => '', |
||||
'tip' => '阿里云OSS的空间名', |
||||
'ok' => '', |
||||
'extend' => 'data-rule-bucket="[/^[0-9a-z_\\-]{3,63}$/, \'请输入正确的Bucket名称\']"', |
||||
], |
||||
[ |
||||
'name' => 'endpoint', |
||||
'title' => 'Endpoint', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'oss-cn-nanjing.aliyuncs.com', |
||||
'rule' => 'required;endpoint', |
||||
'msg' => '', |
||||
'tip' => '请填写从阿里云存储获取的Endpoint', |
||||
'ok' => '', |
||||
'extend' => 'data-rule-endpoint="[/^(?!http(s)?:\\/\\/).*$/, \'不能以http(s)://开头\']"', |
||||
], |
||||
[ |
||||
'name' => 'cdnurl', |
||||
'title' => 'CDN地址', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'https://hzy-shop.oss-cn-nanjing.aliyuncs.com', |
||||
'rule' => 'required;cdnurl', |
||||
'msg' => '', |
||||
'tip' => '请填写CDN地址,必须以http(s)://开头', |
||||
'ok' => '', |
||||
'extend' => 'data-rule-cdnurl="[/^http(s)?:\\/\\/.*$/, \'必需以http(s)://开头\']"', |
||||
], |
||||
[ |
||||
'name' => 'uploadmode', |
||||
'title' => '上传模式', |
||||
'type' => 'select', |
||||
'content' => [ |
||||
'client' => '客户端直传(速度快,无备份)', |
||||
'server' => '服务器中转(占用服务器带宽,可备份)', |
||||
], |
||||
'value' => 'server', |
||||
'rule' => '', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'serverbackup', |
||||
'title' => '服务器中转模式备份', |
||||
'type' => 'radio', |
||||
'content' => [ |
||||
1 => '备份(附件管理将产生2条记录)', |
||||
0 => '不备份', |
||||
], |
||||
'value' => '1', |
||||
'rule' => '', |
||||
'msg' => '', |
||||
'tip' => '服务器中转模式下是否备份文件', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'savekey', |
||||
'title' => '保存文件名', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '/uploads/{year}{mon}{day}/{filemd5}{.suffix}', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'expire', |
||||
'title' => '上传有效时长', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '600', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '用户停留页面上传有效时长,单位秒', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'maxsize', |
||||
'title' => '最大可上传', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '10M', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'mimetype', |
||||
'title' => '可上传后缀格式', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'jpg,png,bmp,jpeg,gif,zip,rar,xls,xlsx', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'multiple', |
||||
'title' => '多文件上传', |
||||
'type' => 'bool', |
||||
'content' => [], |
||||
'value' => '0', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'thumbstyle', |
||||
'title' => '缩略图样式', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '', |
||||
'rule' => '', |
||||
'msg' => '', |
||||
'tip' => '用于后台列表缩略图样式,可使用:?x-oss-process=image/resize,m_lfit,w_120,h_90', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'chunking', |
||||
'title' => '分片上传', |
||||
'type' => 'radio', |
||||
'content' => [ |
||||
1 => '开启', |
||||
0 => '关闭', |
||||
], |
||||
'value' => '0', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'chunksize', |
||||
'title' => '分片大小', |
||||
'type' => 'number', |
||||
'content' => [], |
||||
'value' => '4194304', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'syncdelete', |
||||
'title' => '附件删除时是否同步删除云存储文件', |
||||
'type' => 'bool', |
||||
'content' => [], |
||||
'value' => '0', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'apiupload', |
||||
'title' => 'API接口使用云存储', |
||||
'type' => 'bool', |
||||
'content' => [], |
||||
'value' => '1', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'noneedlogin', |
||||
'title' => '免登录上传', |
||||
'type' => 'checkbox', |
||||
'content' => [ |
||||
'api' => 'API', |
||||
'index' => '前台', |
||||
'admin' => '后台', |
||||
], |
||||
'value' => '', |
||||
'rule' => '', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
]; |
@ -1,73 +0,0 @@ |
||||
<?php |
||||
|
||||
return [ |
||||
[ |
||||
'name' => 'key', |
||||
'title' => '应用key', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'LTAI5tPGGohByohCiS3TmHNA', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'secret', |
||||
'title' => '密钥secret', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => 'j4rMmZm8YmfuQbVOIoYXenJMENmebZ', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'sign', |
||||
'title' => '签名', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '一鸣网络', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'template', |
||||
'title' => '短信模板', |
||||
'type' => 'array', |
||||
'content' => [], |
||||
'value' => [ |
||||
'register' => 'SMS_288490555', |
||||
'resetpwd' => 'SMS_288490555', |
||||
'changepwd' => 'SMS_288490555', |
||||
'changemobile' => 'SMS_288490555', |
||||
'profile' => 'SMS_288490555', |
||||
'notice' => 'SMS_288490555', |
||||
'mobilelogin' => 'SMS_288490555', |
||||
'bind' => 'SMS_288490555', |
||||
], |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => '__tips__', |
||||
'title' => '温馨提示', |
||||
'type' => 'string', |
||||
'content' => [], |
||||
'value' => '应用key和密钥你可以通过 https://ak-console.aliyun.com/?spm=a2c4g.11186623.2.13.fd315777PX3tjy#/accesskey 获取', |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
]; |
@ -1,70 +0,0 @@ |
||||
<?php |
||||
|
||||
return [ |
||||
[ |
||||
'name' => 'version', |
||||
'title' => 'API版本(请勿修改该值)', |
||||
'type' => 'radio', |
||||
'content' => [], |
||||
'value' => 'v2', |
||||
'rule' => '', |
||||
'msg' => '', |
||||
'tip' => 'V2版本只支持微信支付V2密钥,V3版本只支持微信支付V3密钥,请勿修改该值!!!', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'wechat', |
||||
'title' => '微信', |
||||
'type' => 'array', |
||||
'content' => [], |
||||
'value' => [ |
||||
'appid' => '', |
||||
'app_id' => 'wx183e3fbc925f1ba3', |
||||
'app_secret' => '', |
||||
'miniapp_id' => '', |
||||
'mch_id' => '482572', |
||||
'key' => 'udiigvdhrhreehhtrtrjjrjrrrrhjheh', |
||||
'key_v3' => '', |
||||
'mode' => 'normal', |
||||
'sub_mch_id' => '', |
||||
'sub_appid' => '', |
||||
'sub_app_id' => '', |
||||
'sub_miniapp_id' => '', |
||||
'notify_url' => '', |
||||
'cert_client' => '/addons/epay/certs/apiclient_cert.pem', |
||||
'cert_key' => '/addons/epay/certs/apiclient_key.pem', |
||||
'log' => '1', |
||||
], |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '微信参数配置', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
[ |
||||
'name' => 'alipay', |
||||
'title' => '支付宝', |
||||
'type' => 'array', |
||||
'content' => [], |
||||
'value' => [ |
||||
'mode' => 'normal', |
||||
'pid' => '', |
||||
'app_id' => '', |
||||
'notify_url' => '/addons/epay/api/notifyx/type/alipay', |
||||
'return_url' => '/addons/epay/api/returnx/type/alipay', |
||||
'private_key' => '', |
||||
'signtype' => 'cert', |
||||
'ali_public_key' => '', |
||||
'app_cert_public_key' => '', |
||||
'alipay_root_cert' => '', |
||||
'log' => '1', |
||||
'scanpay' => '0', |
||||
], |
||||
'rule' => 'required', |
||||
'msg' => '', |
||||
'tip' => '支付宝参数配置', |
||||
'ok' => '', |
||||
'extend' => '', |
||||
], |
||||
]; |
@ -1,487 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace app\api\controller; |
||||
|
||||
use app\common\controller\Api; |
||||
use think\Db; |
||||
use think\Cache; |
||||
/** |
||||
* 首页接口 |
||||
*/ |
||||
|
||||
class Dynamic extends Api |
||||
{ |
||||
protected $noNeedLogin = ['list']; |
||||
protected $noNeedRight = ['*']; |
||||
/** |
||||
* 首页 |
||||
* |
||||
*/ |
||||
|
||||
public function index() |
||||
|
||||
{ |
||||
$users = Db::name("dynamic_form")->select(); |
||||
$this->success('请求成功!', $users); |
||||
} |
||||
|
||||
|
||||
public function test1(){ |
||||
$x=5; // 全局变量 |
||||
$y=10; // 局部变量 |
||||
echo "<p>测试函数内变量:<p>"; |
||||
echo "变量 x 为: $x"; |
||||
echo "<br>"; |
||||
echo "变量 y 为: $y"; |
||||
|
||||
} |
||||
/** |
||||
* 动态发表 |
||||
*/ |
||||
public function article(){ |
||||
$post = $this->request->post(); |
||||
$user_id = $this->auth->id; |
||||
$inData = [ |
||||
"user_id"=>$user_id, |
||||
"headline"=>$post['headline'] , |
||||
"content_type"=>$post["content_type"], |
||||
"content"=>$post['content'], |
||||
"topic_id"=>$post['topic_id'], |
||||
"create_time"=>date('Y-m-d H:i:s') |
||||
]; |
||||
$dynamic = Db::name("dynamic_form")->insert($inData); |
||||
$this->success("发布成功",$dynamic); |
||||
} |
||||
|
||||
/** |
||||
*分页查询 |
||||
*/ |
||||
|
||||
public function list(){ |
||||
//接收get请求的参数赋值给 $params |
||||
$params = $this->request->get(); |
||||
// 判断缓存是否存在 |
||||
$cacheKey = 'dynamic_list_' . md5(serialize($params)); |
||||
|
||||
if (Cache::store('redis')->has($cacheKey)) { |
||||
$result = Cache::store('redis')->get($cacheKey); |
||||
$this->success("OK", $result); |
||||
} |
||||
// echo "22222222"; |
||||
// exit; |
||||
//分页查询动态表某些字段的集合,并且进行遍历,数据处理 |
||||
$page = Db::name("dynamic_form")->field("id,headline,total_collect,image,user_id,topic_id,create_time")->paginate($params['limit'] ?? 10)->each(function($item, $key){//$item是forech 里面的$value,$key则是Key |
||||
//查询发表当前动态的用户信息 |
||||
$user = Db::name("user")->where("id",$item["user_id"] )->field("id,username,avatar")->find(); |
||||
//查询当前动态关联的话题 |
||||
$topic = Db::name("topic")->where("id", $item["topic_id"])->find(); |
||||
|
||||
//查询当前用户是否点赞了当前动态 |
||||
$like = Db::name("like") |
||||
->where("item_id",$item["id"]) |
||||
->where("item_type",1) |
||||
->where("user_id",$item["user_id"]) |
||||
->where('status',1) |
||||
->find(); |
||||
|
||||
$item["is_like"] = $like ? 1 : 0;//把是否点赞赋值给is_like对象 |
||||
$item["user"] = $user;//把查询到的当前动态用户信息赋值给user对象 |
||||
$item["topic"] = $topic;//把查询到动态关联的话题赋值给topic对象 |
||||
$item['create_time'] = strtotime($item['create_time']);//把发表时间进行时间戳转换 |
||||
|
||||
return $item; |
||||
}); |
||||
|
||||
// 设置缓存 |
||||
$expireTime = 3600; // 过期时间(单位:秒) |
||||
Cache::store('redis')->set($cacheKey, $page); |
||||
Cache::store('redis')->expire($cacheKey, $expireTime); |
||||
|
||||
$this->success("发布成功",$page); |
||||
} |
||||
|
||||
/** |
||||
* 查看详情 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function detail(){ |
||||
|
||||
$id = $this->request->get("id"); |
||||
$user_id = 47; |
||||
$detail = Db::name('dynamic_form')->where('id', $id)->find(); |
||||
if(!$detail){ |
||||
$this->error("动态已删除"); |
||||
} |
||||
$user = Db::name("user")->where("id",$detail["user_id"] )->field("id,username,avatar")->find(); |
||||
//查询当前动态是否是否收藏 |
||||
$like = Db::name("like") |
||||
->where("item_id",$detail["id"]) |
||||
->where("item_type",1) |
||||
->where("user_id",$detail["user_id"]) |
||||
->where('status',1) |
||||
->find(); |
||||
//查询当前动态是否收藏 |
||||
$collect = Db::name("collect") |
||||
->where("item_id",$detail["id"]) |
||||
->where("item_type",1) |
||||
->where("user_id",$detail["user_id"]) |
||||
->where('status',1) |
||||
->find(); |
||||
|
||||
$detail["user"]=$user; |
||||
//空 0 false都为false |
||||
$detail["is_like"]= $like ? 1 : 0; |
||||
$detail["is_collect"]= $collect ? 1 : 0; |
||||
|
||||
$this->success("查看成功",$detail); |
||||
} |
||||
|
||||
public function user(){ |
||||
$userId = $this->request->get("uesr_id"); |
||||
$user = Db::name("user")->where("id",$userId)->field("id,username,avatar")->find(); |
||||
$details["user"]=$user; |
||||
$this->success("查看成功",$user); |
||||
} |
||||
|
||||
/** |
||||
* 点赞 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function like(){ |
||||
$params=$this->request->post(); |
||||
$user_id = 47; |
||||
$currentTime = date("Y-m-d H:i:s"); |
||||
|
||||
|
||||
$data = Db::name("dynamic_form")->where("id",$params["item_id"])->find(); |
||||
if(!$data){ |
||||
$this->error("点赞对象不存在"); |
||||
} |
||||
$like = Db::name("like")->where("item_id",$params["item_id"])->where("user_id",$user_id)->find(); |
||||
$totalLike = $data["total_likes"]; |
||||
|
||||
if(!$like){ |
||||
$data = [ |
||||
"user_id"=>$user_id, |
||||
"item_type"=>$params["item_type"], |
||||
"item_id"=>$params["item_id"], |
||||
"status"=>"1", |
||||
"create_time"=>$currentTime, |
||||
"update_time"=>$currentTime, |
||||
]; |
||||
|
||||
$res = Db::name("like")->insert( $data); |
||||
} else{ |
||||
|
||||
if($like["status"]==1){ |
||||
$res = Db::name("like")->where("id",$like["id"])->update(["status"=>"0","update_time"=>$currentTime]); |
||||
//添加点赞总数 |
||||
Db::name("dynamic_form")->where ("id",$like["item_id"])->update(["total_likes"=>$totalLike-1]); |
||||
|
||||
} else { |
||||
$res = Db::name("like")->where("id",$like["id"])->update(["status"=>"1","update_time"=>$currentTime]); |
||||
Db::name("dynamic_form")->where ("id",$like["item_id"])->update(["total_likes"=>$totalLike+1]); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
$this->success("succ", $res); |
||||
} |
||||
|
||||
public function collect(){ |
||||
$params=$this->request->post(); |
||||
$user_id = 47; |
||||
$currentTime = date("Y-m-d H:i:s"); |
||||
|
||||
|
||||
$data = Db::name("dynamic_form")->where("id",$params["item_id"])->find(); |
||||
if(!$data){ |
||||
$this->error("收藏动态不存在"); |
||||
} |
||||
$collect = Db::name("collect")->where("item_id",$params["item_id"])->where("user_id",$user_id)->find(); |
||||
|
||||
$totalCollect = $data["total_collect"]; |
||||
|
||||
if(!$collect){ |
||||
$data = [ |
||||
"user_id"=>$user_id, |
||||
"item_type"=>$params["item_type"], |
||||
"item_id"=>$params["item_id"], |
||||
"status"=>"1", |
||||
"create_time"=>$currentTime, |
||||
"update_time"=>$currentTime, |
||||
]; |
||||
|
||||
$res = Db::name("collect")->insert( $data); |
||||
} else{ |
||||
|
||||
if($collect["status"]==1){ |
||||
$res = Db::name("collect")->where("id",$collect["id"])->update(["status"=>"0","update_time"=>$currentTime]); |
||||
//添加收藏总数 |
||||
Db::name("dynamic_form")->where ("id",$collect["item_id"])->update(["total_collect"=>$totalCollect-1]); |
||||
|
||||
} else { |
||||
$res = Db::name("collect")->where("id",$collect["id"])->update(["status"=>"1","update_time"=>$currentTime]); |
||||
Db::name("dynamic_form")->where ("id",$collect["item_id"])->update(["total_collect"=>$totalCollect+1]); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
$this->success("succ", $res); |
||||
} |
||||
|
||||
/** |
||||
* 评论 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function comment (){ |
||||
$params=$this->request->post(); |
||||
$currentTime = date("Y-m-d H:i:s"); |
||||
|
||||
$dynamic =Db::name("dynamic_form")->where("id",$params["item_id"])->find(); |
||||
|
||||
|
||||
if(!$dynamic){ |
||||
$this->error("动态不存在", $params); |
||||
} |
||||
|
||||
$inData = [ |
||||
"user_id"=>$dynamic["user_id"], |
||||
"item_id"=>$dynamic["id"], |
||||
"item_type"=>$params["item_type"], |
||||
"content"=>$params["content"], |
||||
"create_time"=>$currentTime, |
||||
"update_time"=>$currentTime, |
||||
]; |
||||
|
||||
$res = Db::name("comment")->insert($inData); |
||||
if($res === false){ |
||||
$this->error("服务器异常,请稍后重试"); |
||||
} |
||||
$upData = [ |
||||
"total_comments"=>$dynamic["total_comments"] + 1 |
||||
]; |
||||
$res= Db::name("dynamic_form")->where("id",$dynamic["id"])->update($upData); |
||||
if($res===false){ |
||||
$this->error("服务器异常,请稍后重试"); |
||||
} |
||||
$this->success("succ"); |
||||
} |
||||
|
||||
/** |
||||
* 查看评论数 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function commentList(){ |
||||
$params=$this->request->get(); |
||||
$page =$params["page"]; |
||||
$pageSize =$params["pageSize"]; |
||||
// 查询评论集合 |
||||
$comments = Db::name("comment") |
||||
->alias("c") |
||||
->join("user u", "c.user_id = u.id") |
||||
->field("c.*, u.avatar, u.username") |
||||
->limit(($page - 1) * $pageSize, $pageSize) |
||||
->select(); |
||||
/* foreach ($comments as $comment) { |
||||
echo "评论ID:" . $comment['id'] . "<br>"; |
||||
echo "评论内容:" . $comment['content'] . "<br>"; |
||||
echo "评论时间:" . $comment['create_time'] . "<br>"; |
||||
echo "评论人名字:" . $comment['username'] . "<br>"; |
||||
echo "评论人头像:" . $comment['avatar'] . "<br>"; |
||||
}*/ |
||||
|
||||
$this->success($comments); |
||||
} |
||||
|
||||
/** |
||||
* 回复 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function reply(){ |
||||
$params=$this->request->post(); |
||||
$user_id = 47; |
||||
$currentTime = date("Y-m-d H:i:s"); |
||||
|
||||
//1是回复评论,2是回复回复 |
||||
switch ($params["item_type"]) { |
||||
case '1': |
||||
$info = Db::name("comment")->where("id",$params["item_id"])->find(); |
||||
|
||||
// $dynamic =Db::name("dynamic_form")->where("id", $info["item_id"])->find(); |
||||
break; |
||||
case '2': |
||||
$info = Db::name('reply')->where("id",$params["item_id"])->find(); |
||||
break; |
||||
|
||||
} |
||||
|
||||
|
||||
if(!$info){ |
||||
$this->error("该评论或回复不存在"); |
||||
} |
||||
$totalReply = $info["total_reply"]; |
||||
|
||||
$inData = [ |
||||
"item_type"=>$params["item_type"], |
||||
"item_id"=>$params["item_id"], |
||||
"user_id"=>$user_id, |
||||
"content"=>$params["content"], |
||||
"repllied_user_id"=> $info["user_id"], |
||||
"create_time"=>$currentTime, |
||||
"update_time"=>$currentTime, |
||||
"comment_id"=>$params["item_id"] |
||||
]; |
||||
|
||||
$res = Db::name("reply")->insert($inData); |
||||
|
||||
|
||||
|
||||
//更新回复数 |
||||
switch($params["item_type"]){ |
||||
case '1': |
||||
$res = Db::name("comment")->where('id', $info['id'])->update(["total_reply"=>$totalReply + 1]); |
||||
|
||||
break; |
||||
|
||||
case '2': |
||||
$res = Db::name("reply")->where('id', $info['id'])->update(["total_reply"=>$totalReply + 1]); |
||||
break; |
||||
} |
||||
// Db::name("dynamic_form")->where('id',$dynamic["item_id"])->update(["total_reply"=>$totalReply+1]); |
||||
$this->success($res); |
||||
} |
||||
|
||||
/** |
||||
* 关注 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function follow(){ |
||||
$params = $this->request->post(); |
||||
$user_id = $this->auth->id; |
||||
$currentTime = date("Y-m-d H:i:s"); |
||||
$follow = Db::name("follow")->where("user_id",$user_id) |
||||
->where("item_type",$params["item_type"]) |
||||
->where("item_id",$params["item_id"])->find(); |
||||
|
||||
//数据不存在进行新增,存在进行判断 |
||||
if(!$follow){ |
||||
$inData = [ |
||||
"item_type"=>$params["item_type"], |
||||
"item_id"=>$params["item_id"], |
||||
"user_id"=>$user_id, |
||||
"status"=>1, |
||||
"create_time"=>$currentTime, |
||||
"update_time"=>$currentTime, |
||||
]; |
||||
|
||||
Db::name("follow")->insert($inData); |
||||
}else if($follow["status"]==0){ |
||||
Db::name("follow")->where("id",$follow["id"])->update(["status"=>1]); |
||||
}else{ |
||||
Db::name("follow")->where("id",$follow["id"])->update(["status"=>0]); |
||||
} |
||||
$this->success("succ"); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 我的关注 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function myFocus(){ |
||||
$params = $this->request->get(); |
||||
$user_id = $this->auth->id; |
||||
$followList = Db::name("follow")->where("user_id",$user_id)->where("status",1)->select(); |
||||
foreach($followList as $followUser){ |
||||
$userInfo = Db::name("user")->where("id",$followUser["item_id"])->field("id,username,avatar")->find(); |
||||
$followUser["user"]=$userInfo; |
||||
} |
||||
|
||||
$this->success($followList); |
||||
} |
||||
|
||||
/** |
||||
* 我的粉丝 |
||||
*/ |
||||
public function MyFans(){ |
||||
$params = $this->request->get(); |
||||
$user_id = $this->auth->id; |
||||
$followList = Db::name("follow")->where("item_id",$user_id)->where("status",1)->select(); |
||||
foreach($followList as $followUser){ |
||||
$userInfo = Db::name("user")->where("id",$followUser["item_id"])->field("id,username,avatar")->find(); |
||||
$followUser["user"]=$userInfo; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 轮播图 |
||||
* @return [type] [description] |
||||
*/ |
||||
public function slideshow(){ |
||||
$params = $this->request->get(); |
||||
$show = Db::name("slideshow")->where("status",$params["status"])->order('sort DESC, create_time DESC')->select(); |
||||
$this->success($show); |
||||
|
||||
} |
||||
|
||||
public function new(){ |
||||
$page = isset($_GET['page']); |
||||
$limit = 10; |
||||
$offset = ($page - 1) * $limit; |
||||
|
||||
$newList = Db::name("new")->where("status",1)->limit($offset, $limit)->select(); |
||||
if(empty($newList)){ |
||||
$this->success("新闻数据为空"); |
||||
} |
||||
$this->success($newList); |
||||
|
||||
} |
||||
|
||||
public function newDetail(){ |
||||
$id = isset($_GET['id']); |
||||
|
||||
$newDetail = Db::name("new")->where("status",1)->where("id",$id)->select(); |
||||
if(!$newDetail){ |
||||
$this->success("新闻数据为空"); |
||||
} |
||||
$this->success($newDetail); |
||||
|
||||
} |
||||
|
||||
public function category(){ |
||||
$params = $this->request->get(); |
||||
$category = Db::name("category_type")->where("status",1)->where("type",2)->select(); |
||||
$this->success($category); |
||||
} |
||||
|
||||
public function course(){ |
||||
$params = $this->request->get(); |
||||
$page = isset($_GET['page']); |
||||
$limit = 10; |
||||
$offset = ($page - 1) * $limit; |
||||
|
||||
$courseList = Db::name("course")->where("status",1)->where("item_type",$params["item_type"]) |
||||
->where("item_id",$params["item_id"])->limit($offset, $limit)->select(); |
||||
if(!$courseList){ |
||||
$this->success("课程数据为空"); |
||||
} |
||||
$this->success($courseList); |
||||
|
||||
} |
||||
|
||||
public function courseDetail(){ |
||||
$id = isset($_GET['id']); |
||||
|
||||
$newDetail = Db::name("course")->where("status",1)->where("item_type",$params["item_type"]) |
||||
->where("item_id",$params["item_id"])->where("id",$id)->select(); |
||||
if(!$newDetail){ |
||||
$this->success("新闻数据为空"); |
||||
} |
||||
$this->success($newDetail); |
||||
|
||||
} |
||||
|
||||
} |
@ -1,56 +1,56 @@ |
||||
<?php |
||||
|
||||
// +---------------------------------------------------------------------- |
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: liu21st <liu21st@gmail.com> |
||||
// +---------------------------------------------------------------------- |
||||
|
||||
use think\Env; |
||||
|
||||
return [ |
||||
// 数据库类型 |
||||
'type' => Env::get('database.type', 'mysql'), |
||||
// 服务器地址 |
||||
'hostname' => Env::get('database.hostname', '127.0.0.1'), |
||||
// 数据库名 |
||||
'database' => Env::get('database.database', 'hzy'), |
||||
// 用户名 |
||||
'username' => Env::get('database.username', 'hzy'), |
||||
// 密码 |
||||
'password' => Env::get('database.password', 'hzy'), |
||||
// 端口 |
||||
'hostport' => Env::get('database.hostport', ''), |
||||
// 连接dsn |
||||
'dsn' => '', |
||||
// 数据库连接参数 |
||||
'params' => [], |
||||
// 数据库编码默认采用 utf8mb4 |
||||
'charset' => Env::get('database.charset', 'utf8mb4'), |
||||
// 数据库表前缀 |
||||
'prefix' => Env::get('database.prefix', 'fa_'), |
||||
// 数据库调试模式 |
||||
'debug' => Env::get('database.debug', false), |
||||
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) |
||||
'deploy' => 0, |
||||
// 数据库读写是否分离 主从式有效 |
||||
'rw_separate' => false, |
||||
// 读写分离后 主服务器数量 |
||||
'master_num' => 1, |
||||
// 指定从服务器序号 |
||||
'slave_no' => '', |
||||
// 是否严格检查字段是否存在 |
||||
'fields_strict' => true, |
||||
// 数据集返回类型 |
||||
'resultset_type' => 'array', |
||||
// 自动写入时间戳字段 |
||||
'auto_timestamp' => false, |
||||
// 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s |
||||
'datetime_format' => false, |
||||
// 是否需要进行SQL性能分析 |
||||
'sql_explain' => false, |
||||
]; |
||||
<?php |
||||
|
||||
// +---------------------------------------------------------------------- |
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: liu21st <liu21st@gmail.com> |
||||
// +---------------------------------------------------------------------- |
||||
|
||||
use think\Env; |
||||
|
||||
return [ |
||||
// 数据库类型 |
||||
'type' => Env::get('database.type', 'mysql'), |
||||
// 服务器地址 |
||||
'hostname' => Env::get('database.hostname', '127.0.0.1'), |
||||
// 数据库名 |
||||
'database' => Env::get('database.database', 'hzy'), |
||||
// 用户名 |
||||
'username' => Env::get('database.username', 'hzy'), |
||||
// 密码 |
||||
'password' => Env::get('database.password', 'hzy'), |
||||
// 端口 |
||||
'hostport' => Env::get('database.hostport', ''), |
||||
// 连接dsn |
||||
'dsn' => '', |
||||
// 数据库连接参数 |
||||
'params' => [], |
||||
// 数据库编码默认采用 utf8mb4 |
||||
'charset' => Env::get('database.charset', 'utf8mb4'), |
||||
// 数据库表前缀 |
||||
'prefix' => Env::get('database.prefix', 'fa_'), |
||||
// 数据库调试模式 |
||||
'debug' => Env::get('database.debug', false), |
||||
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) |
||||
'deploy' => 0, |
||||
// 数据库读写是否分离 主从式有效 |
||||
'rw_separate' => false, |
||||
// 读写分离后 主服务器数量 |
||||
'master_num' => 1, |
||||
// 指定从服务器序号 |
||||
'slave_no' => '', |
||||
// 是否严格检查字段是否存在 |
||||
'fields_strict' => true, |
||||
// 数据集返回类型 |
||||
'resultset_type' => 'array', |
||||
// 自动写入时间戳字段 |
||||
'auto_timestamp' => false, |
||||
// 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s |
||||
'datetime_format' => false, |
||||
// 是否需要进行SQL性能分析 |
||||
'sql_explain' => false, |
||||
]; |
||||
|
@ -1,58 +0,0 @@ |
||||
<?php |
||||
|
||||
return array ( |
||||
'name' => '我的网站', |
||||
'beian' => '', |
||||
'cdnurl' => '', |
||||
'version' => '1.0.1', |
||||
'timezone' => 'Asia/Shanghai', |
||||
'forbiddenip' => '', |
||||
'languages' => |
||||
array ( |
||||
'backend' => 'zh-cn', |
||||
'frontend' => 'zh-cn', |
||||
), |
||||
'fixedpage' => 'dashboard', |
||||
'categorytype' => |
||||
array ( |
||||
'default' => '默认', |
||||
'page' => '单页', |
||||
'article' => '文章', |
||||
'test' => 'Test', |
||||
), |
||||
'configgroup' => |
||||
array ( |
||||
'basic' => '基础配置', |
||||
'email' => '邮件配置', |
||||
'dictionary' => '字典配置', |
||||
'user' => '会员配置', |
||||
'distribution' => '分销设置', |
||||
), |
||||
'mail_type' => '1', |
||||
'mail_smtp_host' => 'smtp.qq.com', |
||||
'mail_smtp_port' => '465', |
||||
'mail_smtp_user' => '10000', |
||||
'mail_smtp_pass' => 'password', |
||||
'mail_verify_type' => '2', |
||||
'mail_from' => '10000@qq.com', |
||||
'attachmentcategory' => |
||||
array ( |
||||
'category1' => '分类一', |
||||
'category2' => '分类二', |
||||
'custom' => '自定义', |
||||
), |
||||
'banner' => |
||||
array ( |
||||
0 => '/uploads/20231010/fc7f6f9b2bc96f98740942321433160f.jpeg', |
||||
1 => '/uploads/20231010/fc7f6f9b2bc96f98740942321433160f.jpeg', |
||||
), |
||||
'user_buy_limit_per_day' => '5', |
||||
'advance_user_buy_limit_per_day' => '1', |
||||
'goods_buy_limit' => '50.01', |
||||
'order_cancel_time' => '1200', |
||||
'auto_shoukuan_time' => '0', |
||||
'order_succ_image' => '/uploads/20231010/f7005536fecc1e70488e3d6c225bca1c.png', |
||||
'entrusted_ratio' => '5.00', |
||||
'primary_distribution' => '0.4', |
||||
'entrustment_ratio' => '3.2', |
||||
); |
@ -0,0 +1 @@ |
||||
|
@ -1 +0,0 @@ |
||||
/.idea |
@ -1,21 +0,0 @@ |
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2020 nelsons |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
@ -1,36 +0,0 @@ |
||||
{ |
||||
"name": "nelsonkti/sensitive-word", |
||||
"description": "敏感词", |
||||
"keywords": ["laravel", "敏感词", "sensitive", "word", "DFA"], |
||||
"type": "library", |
||||
"license": "MIT", |
||||
"support": { |
||||
"email": "nelsons.goole@gmail.com" |
||||
}, |
||||
"authors": [ |
||||
{ |
||||
"name": "nelsonkti", |
||||
"email": "nelsons.goole@gmail.com" |
||||
} |
||||
], |
||||
"require": { |
||||
"php":">=5.6" |
||||
}, |
||||
"require-dev": { |
||||
"phpunit/phpunit": "~4.1", |
||||
"mockery/mockery": "dev-master" |
||||
}, |
||||
"autoload": { |
||||
"psr-4": { |
||||
"Nelsonkti\\SensitiveWord\\": "src/" |
||||
} |
||||
}, |
||||
"extra": { |
||||
"branch-alias": { |
||||
"dev-master": "1.0-dev" |
||||
} |
||||
}, |
||||
"minimum-stability": "dev", |
||||
"prefer-stable": true |
||||
|
||||
} |
@ -1,14 +0,0 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace Nelsonkti\SensitiveWord\Facades; |
||||
|
||||
use Illuminate\Support\Facades\Facade; |
||||
|
||||
class SensitiveWord extends Facade |
||||
{ |
||||
protected static function getFacadeAccessor() |
||||
{ |
||||
return 'Nelsonkti\SensitiveWord\SensitiveWord'; |
||||
} |
||||
} |
@ -1,250 +0,0 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace Nelsonkti\SensitiveWord; |
||||
|
||||
|
||||
class SensitiveWord |
||||
{ |
||||
/** |
||||
* 替换码 |
||||
* |
||||
* @var string |
||||
*/ |
||||
private $replaceCode = '*'; |
||||
|
||||
/** |
||||
* 敏感词库集合 |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $trieTreeMap = array(); |
||||
|
||||
/** |
||||
* 干扰因子集合 |
||||
* |
||||
* @var array |
||||
*/ |
||||
private $disturbList = array('*'); |
||||
|
||||
/** |
||||
* 文件路径 |
||||
* |
||||
* @var string |
||||
*/ |
||||
private $filename = null; |
||||
|
||||
/** |
||||
* 敏感词树 |
||||
* |
||||
* @var array |
||||
*/ |
||||
private static $sensitiveWordTree = []; |
||||
|
||||
/** |
||||
* 干扰因子集合 |
||||
* |
||||
* @param array $disturbList |
||||
*/ |
||||
public function interference($disturbList = array()) |
||||
{ |
||||
$this->disturbList = $disturbList ?? $this->disturbList; |
||||
} |
||||
|
||||
/** |
||||
* 设置文件路径 |
||||
* |
||||
* @param $filename |
||||
*/ |
||||
protected function setFileName($filename) |
||||
{ |
||||
$this->filename = $filename; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* 获取文件内容 |
||||
* |
||||
* @param $filename "文件路径" |
||||
* @return \Generator |
||||
* @throws \Exception |
||||
*/ |
||||
protected function getFileContent() |
||||
{ |
||||
$handle = fopen($this->filename, 'r'); |
||||
|
||||
if (!$handle) { |
||||
throw new \Exception('open the file failed'); |
||||
} |
||||
|
||||
while (!feof($handle)) { |
||||
yield str_replace(['\'', ' ', PHP_EOL, ','], '', fgets($handle)); |
||||
} |
||||
|
||||
fclose($handle); |
||||
} |
||||
|
||||
/** |
||||
* 生成敏感词库集合 |
||||
* |
||||
* @param $filename "文件路径" |
||||
* @throws \Exception |
||||
*/ |
||||
protected function generateWords() |
||||
{ |
||||
// 获取文件内容 |
||||
$text = $this->getFileContent(); |
||||
|
||||
foreach ($text as $key => $words) { |
||||
$len = mb_strlen($words); |
||||
$treeArr = &$this->trieTreeMap; |
||||
for ($i = 0; $i < $len; $i++) { |
||||
$word = mb_substr($words, $i, 1); |
||||
//敏感词树结尾记录状态为false; |
||||
if ($i + 1 == $len) { |
||||
$treeArr[$word]['end'] = false; |
||||
} |
||||
$treeArr = &$treeArr[$word] ?? false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取敏感词库集合 |
||||
* |
||||
* @param $filename "文件路径" |
||||
*/ |
||||
private function getTrieTreeMap() |
||||
{ |
||||
$trieTreeMap = &$this->trieTreeMap; |
||||
|
||||
if (!$trieTreeMap) { |
||||
$this->generateWords($this->filename); |
||||
} |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* 匹配对应敏感词 |
||||
* |
||||
* @param $txt "内容" |
||||
* @param bool $hasReplace "是否替换原内容" |
||||
* @param array $replaceCodeList "替换符合" |
||||
* @return array |
||||
*/ |
||||
private function getWord($txt, $hasReplace = false, &$replaceCodeList = array()) |
||||
{ |
||||
$wordsList = $wordsListArr = array(); |
||||
$txtLength = mb_strlen($txt); |
||||
for ($i = 0; $i < $txtLength; $i++) { |
||||
$wordLength = $this->checkWord($txt, $i, $txtLength); |
||||
if ($wordLength > 0) { |
||||
$words = mb_substr($txt, $i, $wordLength); |
||||
|
||||
if ($hasReplace) { |
||||
$wordsListArr[] = array( |
||||
'length' => strlen($words), |
||||
'world' => $words, |
||||
'replace_code' => str_repeat($this->replaceCode, mb_strlen($words)) |
||||
); |
||||
} else { |
||||
$wordsList[] = $words; |
||||
} |
||||
|
||||
$i += $wordLength - 1; |
||||
} |
||||
} |
||||
|
||||
$hasReplace && $wordsList = $this->sortWord($wordsListArr, $replaceCodeList); |
||||
|
||||
return $wordsList; |
||||
} |
||||
|
||||
/** |
||||
* 对敏感词按长度进行倒叙排序 |
||||
* |
||||
* @param $wordsList |
||||
* @param $replaceCodeList |
||||
* @param $txt |
||||
*/ |
||||
private function sortWord($wordsListArr, &$replaceCodeList) |
||||
{ |
||||
$array_column = array_column($wordsListArr, 'length'); |
||||
array_multisort($array_column, SORT_DESC, $wordsListArr); |
||||
|
||||
$replaceCodeList = array_column($wordsListArr, 'replace_code'); |
||||
|
||||
return array_column($wordsListArr, 'world'); |
||||
} |
||||
|
||||
/** |
||||
* 查找对应敏感词 |
||||
* |
||||
* @param $txt "内容" |
||||
* @param bool $hasReplace "是否替换原内容" |
||||
* @param array $replaceCodeList "替换符合" |
||||
* @return array |
||||
*/ |
||||
public function searchWord($txt, $filename) |
||||
{ |
||||
return $this->setFileName($filename)->getTrieTreeMap()->getWord($txt); |
||||
} |
||||
|
||||
/** |
||||
* 过滤敏感词 |
||||
* |
||||
* @param $txt "内容" |
||||
* @param $filename "文件路径" |
||||
* @return string|string[] |
||||
*/ |
||||
public function filterWord($txt, $filename) |
||||
{ |
||||
$filename && $this->setFileName($filename)->interference(); |
||||
|
||||
$replaceCodeList = array(); |
||||
|
||||
$wordsList = $this->getTrieTreeMap()->getWord($txt, true, $replaceCodeList); |
||||
|
||||
|
||||
return $wordsList ? str_replace($wordsList, $replaceCodeList, $txt) : $txt; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 敏感词检测 |
||||
* |
||||
* @param $txt "内容" |
||||
* @param $begin "开始位置" |
||||
* @param $length "长度" |
||||
* @return int |
||||
*/ |
||||
private function checkWord($txt, $begin, $length) |
||||
{ |
||||
$treeArr = &$this->trieTreeMap; |
||||
$wordLength = 0; //敏感字符个数 |
||||
$wordLengthArray = []; |
||||
$flag = false; |
||||
for ($i = $begin; $i < $length; $i++) { |
||||
$txtWord = mb_substr($txt, $i, 1); |
||||
|
||||
//如果搜索字不存在词库中直接停止循环。 |
||||
if (!isset($treeArr[$txtWord])) { |
||||
break; |
||||
} |
||||
|
||||
$wordLength++; |
||||
if (isset($treeArr[$txtWord]['end'])) { |
||||
$flag = true; |
||||
$wordLengthArray[] = $wordLength; |
||||
} |
||||
$treeArr = &$treeArr[$txtWord]; |
||||
} |
||||
|
||||
$flag ?: $wordLength = 0; |
||||
|
||||
return $wordLength; |
||||
} |
||||
|
||||
} |
@ -1,40 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Nelsonkti\SensitiveWord; |
||||
|
||||
use Illuminate\Support\ServiceProvider; |
||||
|
||||
class SensitiveWordServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* Register services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function register() |
||||
{ |
||||
$this->app->singleton('Nelsonkti\SensitiveWord\Facades\SensitiveWordFacade', function ($app) { |
||||
return 'Nelsonkti\SensitiveWord\SensitiveWord'; |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Bootstrap services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Get the services provided by the provider. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function provides() |
||||
{ |
||||
return ['Nelsonkti\SensitiveWord\SensitiveWord', 'SensitiveWord']; |
||||
} |
||||
} |
Loading…
Reference in new issue