Compare commits

..

17 Commits

Author SHA1 Message Date
lqmac 1478ee569f 1 1 year ago
lqmac 34aaa3c6d8 1 1 year ago
lqmac a08014988f 1 1 year ago
lqmac 2165db8af3 1 1 year ago
lqmac b605aa3484 1 1 year ago
lqmac 6b906b1b1f 1 1 year ago
lqmac 0d18c65ee6 单点 1 year ago
lqmac 5e5cd0c62c 1 1 year ago
lqmac 88a772aa19 redis锁 1 year ago
lqmac b26f0bd431 1 1 year ago
lqmac 29a858757d 加redis锁 1 year ago
lqmac 7e3949936f 1 1 year ago
lqmac a7db2d00ed 累计收益不累加的问题 1 year ago
lqmac 9879d074ae fix bug 1 year ago
lqmac b3562824ee 1 1 year ago
lqmac d22ea6071f fix bug 1 year ago
lqmac 6e5ebffa14 1 1 year ago
  1. 6
      .gitignore
  2. 233
      addons/alioss/config.php
  3. 73
      addons/alisms/config.php
  4. 70
      addons/epay/config.php
  5. 60
      application/admin/controller/Order.php
  6. 2
      application/admin/view/order/index.html
  7. 25
      application/api/controller/Common.php
  8. 487
      application/api/controller/Dynamic.php
  9. 20
      application/api/controller/Index.php
  10. 8
      application/api/controller/Sms.php
  11. 29
      application/api/controller/User.php
  12. 112
      application/database.php
  13. 58
      application/extra/site.php
  14. 3
      composer.json
  15. 65
      composer.lock
  16. 2
      public/assets/js/backend/auth/adminlog.js
  17. 18
      public/assets/js/backend/order.js
  18. 1
      public/uploads/.gitkeep
  19. 21
      vendor/composer/InstalledVersions.php
  20. 4
      vendor/composer/autoload_files.php
  21. 1
      vendor/composer/autoload_psr4.php
  22. 12
      vendor/composer/autoload_static.php
  23. 66
      vendor/composer/installed.json
  24. 21
      vendor/composer/installed.php
  25. 1
      vendor/nelsonkti/sensitive-word/.gitignore
  26. 21
      vendor/nelsonkti/sensitive-word/LICENSE
  27. 47
      vendor/nelsonkti/sensitive-word/README.md
  28. 36
      vendor/nelsonkti/sensitive-word/composer.json
  29. 14
      vendor/nelsonkti/sensitive-word/src/Facades/SensitiveWord.php
  30. 250
      vendor/nelsonkti/sensitive-word/src/SensitiveWord.php
  31. 40
      vendor/nelsonkti/sensitive-word/src/SensitiveWordServiceProvider.php

6
.gitignore vendored

@ -11,4 +11,8 @@
node_modules
.user.ini
sftp-config.json
.DS_Store
.DS_Store
addons/alisms/config.php
addons/epay/config.php
addons/alioss/config.php
application/extra/site.php

@ -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' => '',
],
];

@ -6,6 +6,10 @@ use app\common\controller\Backend;
use app\admin\model\order\Detail;
use think\Db;
use think\Config;
use app\common\service\UserService;
use app\admin\model\Goods;
use app\admin\model\Order as OrderModel;
/**
*
*
@ -67,7 +71,7 @@ class Order extends Backend
->join('user user', 'user.id = order.buyer_id', 'left')
->join('user user1', 'user1.id = order.seller_id', 'left')
->join('order_detail detail', 'detail.order_id = order.id', 'left')
->field("count(order.id) as order_count,sum(order.order_amount) as order_amount,sum(order.coupon_price) as coupon_price,count(distinct order.buyer_id) as user_count")
->field("count(order.id) as order_count,sum(order.order_amount) as order_amount,sum(order.coupon_price) as coupon_price,sum(detail.dikou_price) as dikou_price,count(distinct order.buyer_id) as user_count")
->where($where)
->find();
// var_dump($single);
@ -76,15 +80,27 @@ class Order extends Backend
$coupon_price = $single['coupon_price'] ?? 0;
$order_count = $single['order_count'] ?? 0;
$user_count = $single['user_count'] ?? 0;
$dikou_price = $single['dikou_price'] ?? 0;
$users = Db::name('order')->field("buyer_id")->where('createtime', ">", strtotime(date("Y-m-d")))->group("buyer_id")->select();
// var_dump($users);
// exit();
$userIds = array_column($users, "buyer_id");
$beforeUsers = Db::name('order')->whereIn('buyer_id', $userIds)->field("buyer_id")->where('createtime', "<", strtotime(date("Y-m-d")))->group("buyer_id")->select();
$new_user_count = count($users) - count($beforeUsers);
// var_dump($userIds);
// exit();
$result = array(
"total" => $list->total(),
"rows" => $list->items(),
"extend" => [
'order_amount' => bcdiv($order_amount, 1, 2),
'coupon_price' => bcdiv($coupon_price, 1, 2),
'dikou_price' => bcdiv($dikou_price, 1, 2),
'order_count' => $order_count,
'user_count' => $user_count,
'new_user_count' => $new_user_count,
]
);
@ -123,5 +139,45 @@ class Order extends Backend
$this->view->assign("type", $type);
return $this->view->fetch();
}
public function cancel($ids = NULL){
$row = $this->model->get($ids);
// var_dump($row);
// exit;
if (!$row)
$this->error(__('No Results were found'));
if ($this->request->isPost()){
$params = $this->request->post("row/a");
$info = OrderModel::where('id', $ids)->update(['status' => -1,'cancel_time' => time()]);
if ($info === false) {
$this->error("取消失败");
}
$detail = Detail::where("order_id", $ids)->find();
if (!$detail)
$this->error(__('No Results were found'));
//上架商品
Goods::where('id', $detail['goods_id'])->update(['status' => 'normal', "updatetime" => time()]);
//分佣给买家上级
$site = Config::get("site");
$commission = bcmul($row->order_amount, $site['primary_distribution'] * 0.01, 2);
$user = Db::name('user')->where('id', $row->buyer_id)->find();
$obj = new UserService();
$ret = $obj->userCommission(1, $user, $row->order_sn, -$commission);
if(!$ret){
$this->error(__('Operation failed'));
}
return $this->success();
}
}
}

@ -17,7 +17,9 @@
订单数:<span id="order_count" style="color:red">0</span>
订单金额:<span id="order_amount" style="color:red">0</span>
优惠金额:<span id="coupon_price" style="color:red">0</span>
佣金抵扣金额:<span id="dikou_price" style="color:red">0</span>
购买人数:<span id="user_count" style="color:red">0</span>
新购人数:<span id="new_user_count" style="color:red">0</span>
</span>
</a>

@ -1,5 +1,5 @@
<?php
declare(encoding='UTF-8');
namespace app\api\controller;
use app\common\controller\Api;
@ -17,7 +17,7 @@ use think\Hook;
*/
class Common extends Api
{
protected $noNeedLogin = ['init', 'captcha'];
protected $noNeedLogin = ['init', 'captcha','getAppidByDomain'];
protected $noNeedRight = '*';
public function _initialize()
@ -161,4 +161,25 @@ class Common extends Api
$captcha = new Captcha((array)Config::get('captcha'));
return $captcha->entry($id);
}
public function getAppidByDomain(){
$domain = $this->request->post("domain");
$wx_appid = Config::get("site.wx_appid");
if (!$wx_appid) {
$this->error("appid没有配置");
}
$this->success('ok', ['wx_appid' => $wx_appid]);
}
}

@ -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);
}
}

@ -7,7 +7,6 @@ use think\Db;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['*'];
@ -17,13 +16,9 @@ class Index extends Api
* 首页
*
*/
public function index()
{
$this->test1();
echo "7766677767";
echo "111";
exit();
$list = Db::name('user')->where('status','normal')->select();
foreach ($list as $key => $value) {
@ -31,17 +26,6 @@ class Index extends Api
$ret = Db::name('user')->where('id', $value['id'])->update(['profit_amount' => $amount]);
var_dump($ret);
}
$this->success('请求成功!');
}
public function test1(){
$x=5; // 全局变量
$y=10; // 局部变量
echo "<p>测试函数内变量:<p>";
echo "变量 x 为: $x";
echo "<br>";
echo "变量 y 为: $y";
$this->success('请求成功');
}
}

@ -35,10 +35,10 @@ class Sms extends Api
if ($last && time() - $last['createtime'] < 60) {
$this->error(__('发送频繁'));
}
$ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
if ($ipSendTotal >= 5) {
$this->error(__('发送频繁'));
}
// $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
// if ($ipSendTotal >= 5) {
// $this->error(__('发送频繁'));
// }
if ($event) {
$userinfo = User::getByMobile($mobile);
if ($event == 'register' && $userinfo) {

@ -63,9 +63,10 @@ class User extends Api
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
$site = Config::get("site");
$config = [
'app_id' => 'wx183e3fbc925f1ba3',
'secret' => 'b3e26edaa7642673dd98a951564e02c7',
'app_id' => $site['wx_appid'],
'secret' => $site['wx_secrect'],
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
];
@ -166,10 +167,10 @@ class User extends Api
$extend['pid'] = $user->id;
}
}
// $ret = Sms::check($mobile, $code, 'register');
// if (!$ret) {
// $this->error(__('Captcha is incorrect'));
// }
$ret = Sms::check($mobile, $code, 'register');
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
$ret = $this->auth->register($username, $password, $email, $mobile, $extend);
if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()];
@ -270,6 +271,16 @@ class User extends Api
if (isset($params['avatar']) && $params['avatar']) {
$upData['avatar'] = $params['avatar'];
}
if ((isset($params['bank_realname']) && $params['bank_realname'] ) || (isset($params['wechat_image']) && $params['wechat_image']) || (isset($params['alipay_image']) && $params['alipay_image'])) {
if (isset($params['code']) && $params['code']) {
$user = $this->auth->getUserinfo();
$ret = Sms::check($user['mobile'], $params['code'], 'notice');
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
}
}
if (!$upData) {
$this->success();
}
@ -541,8 +552,8 @@ class User extends Api
$user_ids = array_column($users, "id");
$data = [
'total_fans_order_amount' => order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5])->count(),
'today_fans_order_num' => order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5])->sum('order_amount'),
'total_fans_order_amount' => order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5,6,7])->sum('order_amount'),
'today_fans_order_num' => order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5,6,7])->count(),
];
$this->success("succ", $data);
}
@ -557,7 +568,7 @@ class User extends Api
$users = UserModel::where('pid', $this->auth->id)->select();
$user_ids = array_column($users, "id");
$list = order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5])->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){
$list = order::whereIn('buyer_id', $user_ids)->whereIn('status', [0,1,2,3,4,5,6,7])->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){
$order_goods = Detail::where('order_id', $item['id'])->select();
if ($order_goods) {
foreach ($order_goods as $key => $value) {

@ -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',
);

@ -30,8 +30,7 @@
"ext-curl": "*",
"ext-pdo": "*",
"ext-bcmath": "*",
"txthinking/mailer": "^2.0",
"nelsonkti/sensitive-word": "^1.0"
"txthinking/mailer": "^2.0"
},
"config": {
"preferred-install": "dist"

65
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "adfded006374d2140e57a0c32874ba94",
"content-hash": "403d56866617dde74ba4ed7c463a7399",
"packages": [
{
"name": "easywechat-composer/easywechat-composer",
@ -987,69 +987,6 @@
},
"time": "2020-07-11T21:01:42+00:00"
},
{
"name": "nelsonkti/sensitive-word",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/nelsonkti/sensitive-word.git",
"reference": "1998cd2c5f0d7091fe6933948224491c01769dbe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelsonkti/sensitive-word/zipball/1998cd2c5f0d7091fe6933948224491c01769dbe",
"reference": "1998cd2c5f0d7091fe6933948224491c01769dbe",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"mockery/mockery": "dev-master",
"phpunit/phpunit": "~4.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Nelsonkti\\SensitiveWord\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "nelsonkti",
"email": "nelsons.goole@gmail.com"
}
],
"description": "敏感词",
"keywords": [
"dfa",
"laravel",
"sensitive",
"word",
"敏感词"
],
"support": {
"email": "nelsons.goole@gmail.com",
"issues": "https://github.com/nelsonkti/sensitive-word/issues",
"source": "https://github.com/nelsonkti/sensitive-word/tree/master"
},
"time": "2020-07-04T07:03:11+00:00"
},
{
"name": "overtrue/pinyin",
"version": "3.0.6",

@ -8,7 +8,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
index_url: 'auth/adminlog/index',
add_url: '',
edit_url: '',
del_url: 'auth/adminlog/del',
// del_url: 'auth/adminlog/del',
multi_url: 'auth/adminlog/multi',
}
});

@ -21,8 +21,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
$("#order_count").text(data.extend.order_count);
$("#order_amount").text(data.extend.order_amount);
$("#coupon_price").text(data.extend.coupon_price);
$("#dikou_price").text(data.extend.dikou_price);
$("#user_count").text(data.extend.user_count);
$("#new_user_count").text(data.extend.new_user_count);
});
// 初始化表格
@ -63,6 +65,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
_html += '<br/>' + row.user.mobile;
return _html;
}, operate:false},
{field: 'user.nickname', title: __('联系人'),operate:"LIKE",sortable:true},
{field: 'user', title: __('状态/下单时间/支付时间'),operate:'LIKE', align: 'left', formatter: function (value, row) {
var _html = ' ';
_html += '<br/>' + row.status_text;
@ -99,6 +102,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table,events: Table.api.events.operate,
buttons:[
{
name:'cancel',
text:'取消订单',
title:'取消订单',
classname: 'btn btn-xs btn-info btn-ajax',
icon: 'fa fa-check',
url: 'order/cancel',
visible:function(row){
if (row.status == 0) {
return true;
}
return false;
},
refresh:true
},
{
name:'split',
text:'发货',

@ -27,12 +27,12 @@ class InstalledVersions
private static $installed = array (
'root' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'aliases' =>
array (
),
'reference' => '496176963450e4fa6501aa135efa478dc48b560b',
'reference' => '8b86e4171769271cc35afa799854f287892f7216',
'name' => 'karsonzhang/fastadmin',
),
'versions' =>
@ -84,12 +84,12 @@ private static $installed = array (
),
'karsonzhang/fastadmin' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'aliases' =>
array (
),
'reference' => '496176963450e4fa6501aa135efa478dc48b560b',
'reference' => '8b86e4171769271cc35afa799854f287892f7216',
),
'karsonzhang/fastadmin-addons' =>
array (
@ -154,15 +154,6 @@ private static $installed = array (
),
'reference' => '501b52f6fc393a599b44ff348a42740e1eaac7c6',
),
'nelsonkti/sensitive-word' =>
array (
'pretty_version' => 'v1.0.0',
'version' => '1.0.0.0',
'aliases' =>
array (
),
'reference' => '1998cd2c5f0d7091fe6933948224491c01769dbe',
),
'overtrue/pinyin' =>
array (
'pretty_version' => '3.0.6',

@ -15,8 +15,8 @@ return array(
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'488987c28e9b5e95a1ce6b6bcb94606c' => $vendorDir . '/karsonzhang/fastadmin-addons/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => $vendorDir . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => $vendorDir . '/overtrue/wechat/src/Kernel/Helpers.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
'cc56288302d9df745d97c934d6a6e5f0' => $vendorDir . '/topthink/think-queue/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => $vendorDir . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => $vendorDir . '/overtrue/wechat/src/Kernel/Helpers.php',
);

@ -35,7 +35,6 @@ return array(
'PhpOffice\\PhpSpreadsheet\\' => array($vendorDir . '/phpoffice/phpspreadsheet/src/PhpSpreadsheet'),
'Overtrue\\Socialite\\' => array($vendorDir . '/overtrue/socialite/src'),
'Overtrue\\Pinyin\\' => array($vendorDir . '/overtrue/pinyin/src'),
'Nelsonkti\\SensitiveWord\\' => array($vendorDir . '/nelsonkti/sensitive-word/src'),
'MyCLabs\\Enum\\' => array($vendorDir . '/myclabs/php-enum/src'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'Matrix\\' => array($vendorDir . '/markbaker/matrix/classes/src'),

@ -16,10 +16,10 @@ class ComposerStaticInita171a4a837511915e525c40585d599c6
'2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'488987c28e9b5e95a1ce6b6bcb94606c' => __DIR__ . '/..' . '/karsonzhang/fastadmin-addons/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Helpers.php',
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
'cc56288302d9df745d97c934d6a6e5f0' => __DIR__ . '/..' . '/topthink/think-queue/src/common.php',
'f0e7e63bbb278a92db02393536748c5f' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Support/Helpers.php',
'6747f579ad6817f318cc3a7e7a0abb93' => __DIR__ . '/..' . '/overtrue/wechat/src/Kernel/Helpers.php',
);
public static $prefixLengthsPsr4 = array (
@ -70,10 +70,6 @@ class ComposerStaticInita171a4a837511915e525c40585d599c6
'Overtrue\\Socialite\\' => 19,
'Overtrue\\Pinyin\\' => 16,
),
'N' =>
array (
'Nelsonkti\\SensitiveWord\\' => 24,
),
'M' =>
array (
'MyCLabs\\Enum\\' => 13,
@ -217,10 +213,6 @@ class ComposerStaticInita171a4a837511915e525c40585d599c6
array (
0 => __DIR__ . '/..' . '/overtrue/pinyin/src',
),
'Nelsonkti\\SensitiveWord\\' =>
array (
0 => __DIR__ . '/..' . '/nelsonkti/sensitive-word/src',
),
'MyCLabs\\Enum\\' =>
array (
0 => __DIR__ . '/..' . '/myclabs/php-enum/src',

@ -963,72 +963,6 @@
},
"install-path": "../nelexa/zip"
},
{
"name": "nelsonkti/sensitive-word",
"version": "v1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/nelsonkti/sensitive-word.git",
"reference": "1998cd2c5f0d7091fe6933948224491c01769dbe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelsonkti/sensitive-word/zipball/1998cd2c5f0d7091fe6933948224491c01769dbe",
"reference": "1998cd2c5f0d7091fe6933948224491c01769dbe",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"mockery/mockery": "dev-master",
"phpunit/phpunit": "~4.1"
},
"time": "2020-07-04T07:03:11+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Nelsonkti\\SensitiveWord\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "nelsonkti",
"email": "nelsons.goole@gmail.com"
}
],
"description": "敏感词",
"keywords": [
"dfa",
"laravel",
"sensitive",
"word",
"敏感词"
],
"support": {
"email": "nelsons.goole@gmail.com",
"issues": "https://github.com/nelsonkti/sensitive-word/issues",
"source": "https://github.com/nelsonkti/sensitive-word/tree/master"
},
"install-path": "../nelsonkti/sensitive-word"
},
{
"name": "overtrue/pinyin",
"version": "3.0.6",

@ -1,12 +1,12 @@
<?php return array (
'root' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'aliases' =>
array (
),
'reference' => '496176963450e4fa6501aa135efa478dc48b560b',
'reference' => '8b86e4171769271cc35afa799854f287892f7216',
'name' => 'karsonzhang/fastadmin',
),
'versions' =>
@ -58,12 +58,12 @@
),
'karsonzhang/fastadmin' =>
array (
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'aliases' =>
array (
),
'reference' => '496176963450e4fa6501aa135efa478dc48b560b',
'reference' => '8b86e4171769271cc35afa799854f287892f7216',
),
'karsonzhang/fastadmin-addons' =>
array (
@ -128,15 +128,6 @@
),
'reference' => '501b52f6fc393a599b44ff348a42740e1eaac7c6',
),
'nelsonkti/sensitive-word' =>
array (
'pretty_version' => 'v1.0.0',
'version' => '1.0.0.0',
'aliases' =>
array (
),
'reference' => '1998cd2c5f0d7091fe6933948224491c01769dbe',
),
'overtrue/pinyin' =>
array (
'pretty_version' => '3.0.6',

@ -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,47 +0,0 @@
# sensitive-word
过滤敏感词,采用 DFA 算法
> 增加包含词的过滤(如:敏感、敏感词)
## Installation
```shell
$ composer require nelsonkti/sensitive-word
```
## Laravel
> 引导服务 config/app.php
```
'providers' => [
Nelsonkti\SensitiveWord\SensitiveWordServiceProvider::class,
],
'aliases' => [
'SensitiveWord' => Nelsonkti\SensitiveWord\SensitiveWord::class,
],
```
## Usage
基本使用:
```
use Nelsonkti\SensitiveWord\Facades\SensitiveWord;
$path = './word.txt'
$content = '敏感,敏感词需要过滤'; #检查内容
$filename = '/txt/sensitive-words.txt'; #敏感词文件路径
SensitiveWord::searchWord($content, $filename);
# 返回: array('敏感', '敏感词');
SensitiveWord::filterWord($content, $filename);
# 返回: **,**词需要过滤
```
## License
sensitive-word is licensed under [The MIT License (MIT)](https://github.com/nelsonkti/sensitive-word/blob/master/LICENSE).

@ -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…
Cancel
Save