php 敏感词过滤高级版

 更新时间:2016年11月25日 17:18  点击:1416
前面介绍过一个过滤了些特殊字符的php程序,下面我们升级一下这个敏感词过滤函数更强大了有了它再也不怕敏感词中间加空格或者其他标点符号了。


只要用户可以发言的地方,就可能出现广告或者其他敏感词,因此必须加入敏感词过滤机制来保持站点的”纯洁”。

过滤机制:加入php关键字正则匹配

//$str 为用户数据
function wordFilter($str)
{
       /*
    获取敏感词列表
    敏感词的存储方法:
    1:存储在txt文件中(一般的方法)
    2:存储在缓存(比较好的方法)
    我是存储在memcachd中。
    */
    $words = getSensitiveWords();

    foreach ($words as $word)
    {
        $preg_letter = '/^[A-Za-z]+$/';
        if (preg_match($preg_letter, $str))
        {//匹配中文
        $str = strtolower($str);
        $pattern_1 = '/([^A-Za-z]+' . $word . '[^A-Za-z]+)|([^A-Za-z]+' . $word . '\s+)|(\s+' . $word . '[^A-Za-z]+)|(^' . $word . '[^A-Za-z]+)|([^A-Za-z]+' . $word.'$)/';
        //敏感词两边不为空
        if (preg_match($pattern_1, $str))
        {
            $flag = TRUE;
        }
        $pattern_2 = '/(^' . $word . '\s+)|(\s+' . $word . '\s+)|(\s+' . $word . '$)|(^' . $word . '$)/';
        //敏感词两边可以为空格
        if (preg_match($pattern_2, $str))
        {
            $flag = TRUE;
        }
        }
        else
        {//匹配英文字符串,大小写不敏感
        $pattern = '/\s*' . $word . '\s*/';
        if (preg_match($pattern, $str))
        {
            $flag = TRUE;
        }
        }
    }
}
存在问题:

如果单纯只加入关键字匹配,用户反过滤的方法五花八门,包括中间加入空格或者其他标点符号。
例子:
敏感词:扣扣

用户处理后:
扣 扣
扣,扣
扣@扣
扣1扣
这时候代码的正则匹配就可能匹配不出来。

解决办法:

先对用户数据去除所有的标点符号和一些特殊字符,然后再进行敏感词判断。

代码:

$flag_arr=array('?','!','¥','(',')',':','‘','’','“','”','《','》',',','…','。','、','nbsp','】','【','~');

        $content_filter=preg_replace('/\s/','',preg_replace("/[[:punct:]]/",'',strip_tags(html_entity_decode(str_replace($flag_arr,'',$content),ENT_QUOTES,'UTF-8'))));
$content_filter 就是处理后的用户数据,然后再进行 wordFilter($content_filter ) 过滤操作

curl函数的强大之处就可以像用户一样的去访问一个网页并且可以是php所能接受的所有数据提交模式了,下面我们来看一个php中curl实现GET和POST请求抓取网页或上传文件的例子并且它还支持跨项目和跨服务器的哦。

一:curl 函数和参数详解

函数库:
1:curl_init 初始化一个curl会话
2:curl_close 关闭一个curl会话
3:curl_setopt 为一个curl设置会话参数
4:curl_error 返回一个包含当前会话错误信息的字符串
5:curl_exec 执行一个curl会话
6:curl_multi_add_handle 向curl批处理会话中添加单独的curl句柄资源
7:curl_multi_close 关闭一个批处理句柄资源
8:curl_multi_exec 解析一个curl批处理句柄
9:curl_multi_getcontent 返回获取的输出的文本流
10:curl_multi_info_read 获取当前解析的curl的相关传输信息
11:curl_multi_init 初始化一个curl批处理句柄资源
12:curl_multi_remove_handle 移除curl批处理句柄资源中的某个句柄资源
13:curl_multi_select 阻塞直到cURL批处理连接中有活动连接
14:curl_setopt_array 以数组的形式为一个curl设置会话参数
15:curl_version 获取curl相关的版本信息
16:curl_getinfo 获取一个curl连接资源句柄的信息
17:curl_copy_handle 拷贝一个curl连接资源的所有内容和参数
18:curl_errno 返回一个包含当前会话错误信息的数字编号

curl_setopt常用可设置参数:
CURLOPT_URL 请求的url地址
CURLOPT_RETURNTRANSFER 设置是否获取数据返回,数据以文件流的形式返回,不是直接输出
CURLOPT_POST 设置是否POST请求,类型为:application/x-www-form-urlencoded,跟表单提交一样
CURLOPT_POSTFIELDS POST请求的数据
CURLOPT_HEADER 启用时会将头文件的信息作为数据流输出
CURLOPT_HTTPGET 启用时会设置HTTP的method为GET,默认是GET

二:curl GET 方式


$ch = curl_init();
//设置选项参数
curl_setopt($ch, CURLOPT_URL, http://www.111cn.net);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置返回数据
curl_setopt($ch, CURLOPT_HEADER, 0);//设置头部不执行
$output = curl_exec($ch);//执行
curl_close($ch);//释放curl句柄
var_dump($output);


三:POST 方式

$url = "http://localhost/ceshi.php";
$post_data = array ("username" => "ceshi","pwd" => "sada&1dsw1","key"=>"ha");
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL, $url);//设置请求地址
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回值
curl_setopt($ch, CURLOPT_POST, 1);//设置请求方式POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//请求所带变量数据
$output = curl_exec($ch);//执行获取返回数据,返回的数据建议json_encode($return_data);
curl_close($ch);
$output =json_decode($output );//解析返回数据

四:curl POST 方式上传文件


$post_data=array("Filedata"=>"@".$image_file);//利用数组传值,image_file为图片地址,@不能少,标明是一个文件
$url = "http://localhost/ceshi.php";
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL, $url);//设置链接
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//设置是否返回信息
curl_setopt($ch, CURLOPT_POST, true);//设置为POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//POST数据
$result = curl_exec($ch);//接收返回信息
if(curl_errno($ch)){//出错则显示错误信息
die(json_encode($ch));
}
curl_close($ch); //关闭curl链接
if (ord($result[0])==239&&ord($result[1])==187&&ord($result[2])== 191){
$result = substr( $result,3);//解决Bom头带来的json_decode为空的bug,Bom头是固定的,可以检测后去除掉
}
$result=json_decode($result);

五:curl POST 文件上传常见问题和解决办法:

1:curl_setopt设置CURLOPT_POSTFIELDS 传值是个数组,后端一直无法获取数据$_POST的值

错误现象:
如果$post_data是数组(包括多维数组)的话会出现”entity is too large”的错误提示,接收数据的receive.php 无法获取curl传过来的数据

原因:
curl POST方法时候,传递一个数组到CURLOPT_POSTFIELDS,curl会把数据编码成 multipart/form-data,如果传递一个URL-encoded字符串时,数据会被编码成 application/x-www-form-urlencoded,对于multipart/form-data的编码方式其实相当于我们直接以”enctype=”multipart/form-data” method=”post” 这样的表单进行操作

解决办法:
a:
对$post_data 数组经 urlencode() 编码后进行字符串连接,
例:$post_data=”&name=urlencode($name)&pwd=usrlencode($pwd)”

b:
直接利用http_build_query()进行参数的拼接。

ps:
“multipart/form-data” 是把表单设置为MIME编码,目的是用来传输二进制文件的,若想上传文件,必须用这个编码(例子见上面的curl POST上传文件的例子);但是普通的url数据使用的是“application/x-www-form-urlencoded” 格式。

2:curl请求返回数据头部多了三个字节,post请求后端是以json_encode 数据格式返回,进行json_decode后返回值始终为空

原因:bom头搞的鬼,bom头:在Windows下用记事本之类的程序将文本文件保存为UTF-8格式时,记事本会在文件头前面加上几个不可见的字符(EF BB BF),就是所谓的BOM(Byte order Mark),就是这前面多了三个字节导致json_decode后返回值为空
对返回值进行bom头检测检测:


echo substr( $result, 0, 1 ); //看到一个乱码
echo substr( $result, 0, 2 ); //看到两个乱码
echo substr( $result, 0, 3 ); //空白
echo substr( $result, 0, 4 ); //看到o
证明确实是bom头的问题

解决办法:


if ( ord( $result[0] ) == 239 && ord( $result[1] ) == 187&& ord( $result[2] ) == 191 ) {
$result = substr( $result, 3 );//Bom头是固定的,可以检测后去除掉
}

如果你网站有评论那么你肯定会发现你网站经常会被一人注入广告了,如会有兼职,QQ号,淘宝兼职,网址信息了,下面我们就来看如何过滤这些内容吧。


用户发表的评论或者其他内容的广告的类型一般有下面的几种:

1:淘宝兼职 加QQ 123456789 群 (带qq号码或者微信号码或者其他数字号码)
2:taobao兼职,加QQ 号码 (带着英文的关键字)
3:淘宝兼职,加QQ ① ① ① ① ① ① (特殊数字的号码)
4:22222222 (全角类型的号码)

过滤的方法:
利用正则来匹配和替换字符串的标点符号,数字,字母,判断是否存在连续的数字或者关键字(支持全角和圆角),因为广告一般都是会带上qq号等联系方式。因此首先要对评论进行”净化”和替换,把全角的转换成半角的,去掉一些”沙子”,比如标点符号,空格,字母等等,只留下中文和数字。

例子:

$comment= “这$%是一个(1)8神器三四的网站,B快来加入④④呵@#呵 qq 1 2 3 4 5 6 7 8″;

1:”净化”内容,去除标点符号

$flag_arr=array('?','!','¥','(',')',':','‘','’','“','”','《','》',',','…','。','、','nbsp','】','【','~');             

$comment=preg_replace('/\s/','',preg_replace("/[[:punct:]]/",'',strip_tags(html_entity_decode(str_replace($flag_arr,'',$comment),ENT_QUOTES,'UTF-8'))));
处理后,$comment 变成了:”这是一个(1)8神器三四的网站B快来加入①④呵呵qqq12345678″

2:其中可能参杂了一些全角的符号或者数字,所以利用下面的代码把全角符号转成正则可以匹配的半角

 $quanjiao = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4','5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E','F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J', 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O','P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T','U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y','Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd','e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i','j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n','o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's', 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x', 'y' => 'y', 'z' => 'z','(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[','】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']','‘' => '[', '\'' => ']', '{' => '{', '}' => '}', '《' => '<','》' => '>','%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.', ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|', '”' => '"', '\'' => '`', '‘' => '`', '|' => '|', '〃' => '"',' ' => ' ');

$comment=strtr($comment, $quanjiao);
php 的strtr 函数是用来转换字符串中特定的字符。
可以使用
strtr(string,from,to)
或者
strtr(string,array)

处理后,$comment变成了:”这是一个18神器三四的网站B快来加入①④呵呵qq12345678″;

3:评论里面可能 还包含有特殊字符(可以自己在下面的数组进行扩展新的特殊字符)

$special_num_char=array('①'=>'1','②'=>'2','③'=>'3','④'=>'4','⑤'=>'5','⑥'=>'6','⑦'=>'7','⑧'=>'8','⑨'=>'9','⑩'=>'10','⑴'=>'1','⑵'=>'2','⑶'=>'3','⑷'=>'4','⑸'=>'5','⑹'=>'6','⑺'=>'7','⑻'=>'8','⑼'=>'9','⑽'=>'10','一'=>'1','二'=>'2','三'=>'3','四'=>'4','五'=>'5','六'=>'6','七'=>'7','八'=>'8','九'=>'9','零'=>'0');
$comment=strtr($comment, $special_num_char);
处理后,$comment变成了:”这是一个18神器的网站B快来加入14呵呵qq12345678″;
如果评论里面出现繁体的数字,例如 ‘零’,’壹’,’贰’,’叁’,’肆’,’伍’,’陆’,’柒’,’捌’,’玖’,’拾’ 这些,一样的在上面的 $special_num_char 添加 和扩展就行。

4:评论里还可能出现正常的数字和汉字的数字混合,一样的用第3点的方法转换成正常的数字即可。

例子:这是一条广告qq 1二贰45六7899
转换后:
这是一条广告qq 1224567899

5:正则处理过滤广告

利用正则匹配 preg_match_all(‘/\d+/’,$comment,$match)
分析获取到的match[0] 匹配数组

foreach($match[0] as $val)//是否存在数字的qq号和微信号
{
    if(strlen($val)>=6)
    {//存在连续的长度超过6位的数字串,广告嫌疑很大
         $is_ad=true;
         break;
    }
}
if(count($match[0])>=10)
{//间断的数字很多,存在广告的嫌疑
    $is_ad=true;
}

ok,这样就可以判断内容是否广告,可以过滤大部分的常见的广告了

留言板基于功能就是数据添加管理修改及数据删除功能了,下面我们就来看一个PHP+MySQL实现简单留言板例子,希望文章能够帮助到大家。

通过php+mysql 实现的简易blog,可以实现增删改查。效果如下图:

micro_blog

一、数据库及表结构

数据库:test

表:micro_blog(仅仅有一个表)字段:id,title,date,content,hits

表结构如下:

CREATE TABLE `micro_blog` (
  `id` int(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL ,
  `content` longtext NOT NULL,
  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `hits` int(20) DEFAULT 0,
   PRIMARY KEY (`ID`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;

二、文件

文件详细描述

文件  描述
default.php  默认主页。显示博文与操作连接。
add.php  添加新博文的功能模块。
edit.php  对已经添加过的博文进行修改操作。
delete.php  删除博文模块。
view.php  显示博文的详细信息(标题|添加日期|浏览次数|内容)。
conn.php  链接数据库操作。在其它文件中被引用。
conn.php

<?php
//连接MySql数据库服务
$conn = @mysql_connect("localhost:3306","root","www.361way.com") or die("连接数据库服务器失败!");
//连接ly_php_base数据库
@mysql_select_db("test",$conn) or die("未能连接到数据库!");
mysql_query("SET NAMES 'UTF8'");
?> 
注:后面的set names utf8,如果不执行,会出现插入数据库中的汉字会变成乱码。

default.php

<?php
include("conn.php");
//搜索关键字的管理
if(!empty($_GET['keys'])){
    $keys = "WHERE title like '%".$_GET['keys']."%'";
} else {
    $keys = "";
}
$sql = "SELECT * FROM micro_blog ".$keys." ORDER BY id DESC LIMIT 10";
$query = mysql_query($sql);
$rs = mysql_fetch_array($query);
?>

<html>
<head>
<title>我的微博客主页</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<a href="add.php">添加内容</a>
<form action="" method="get">
  <input type="text" name="keys"/>
  <input type="submit" name="submit" value="内容搜索"/>
</form>
<hr color="#FF9900" size="3" />
<?php
if(!$rs){
    echo "没有相关内容!";
}
//没有实现分页导航功能
while($rs){
?>
<h2>标题:<?php echo $rs['title'];?>|<a href="edit.php?id=<?php echo $rs['id'];?>">编辑</a>|<a href="delete.php?id=<?php echo $rs['id'];?>">删除</a></h2>
<li>日期:<?php echo $rs['date'];?></li>
<p>内容<?php echo iconv_substr($rs['content'],0,50,"UTF-8");?>...... <a href="view.php?id=<?php echo $rs['id'];?>">|查看详细内容|</a></p>
<hr color="#0033FF" size="5" />
<?php
    $rs = mysql_fetch_array($query);
}
?>
</body>
</html>
 
add.php

<?php
//引入连接数据库文件
include("conn.php");
if(!empty($_POST['submit'])){
    $title = $_POST['title'];
    $content = $_POST['content'];
    $sql = "INSERT INTO micro_blog VALUES(NUll,'$title','$content',now(),0)";
    mysql_query($sql);
}
?>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>发布微博页面</title>
</head>
<body>
<a href="default.php">查看内容</a>
<hr color="#0033CC" size="3px"/>
<form action="add.php" method="post">
  标题:
  <input type="text" name="title"/>
  <br />
  内容:
  <textarea rows="5" cols="50" name="content"></textarea>
  <br />
  <input type="submit" name="submit" value="提交"/>
  <br />
</form>
</body>
</html> 

edit.php

<?php
include("conn.php");
if(!empty($_GET['id'])){
    $id = $_GET['id'];
    $sql = "select * from micro_blog where id = ".$_GET['id'];
    $query = mysql_query($sql);
    $rc = mysql_fetch_array($query);
}
if(!empty($_POST['update'])){
    echo "更新按钮提交成功!";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>编辑页面</title>
</head>
<body>
<form action="edit.php?id=<?php echo $id;?>" method="post">
  标题:
  <input type="text" name="title" value="<?php echo $rc['title'];?>"/>
  <br />
  内容:
  <textarea rows="5" cols="50" name="content"><?php echo $rc['content'];?></textarea>
  <br />
  <input type="submit" name="update" value="更新"/>
  <br />
</form>
</body>
</html> 

delete.php

<?php
include("conn.php");
if(!empty($_GET['id'])){
            mysql_query("delete from micro_blog where id =".$_GET['id']);
} else {
        echo "参数引入失败!";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $rc['title'];?>|我的微博客</title>
</head>
<body>
<a href="default.php">返回主页面</a>
<hr color="#00FFFF" size="5px"/>
<h2><?php echo $rc['title'];?>
  <hr color="#006699" size="3px">
</h2>
<li><?php echo "日期:".$rc['date']."|浏览次数:".$rc['hits'];?></li>
<p><?php echo $rc['content'];?></p>
</body>
</html> 

view.php

<?php
include("conn.php");
if(!empty($_GET['id'])){
    $sql = "SELECT * FROM micro_blog WHERE id = ".$_GET['id'];
    $rc = mysql_fetch_array(mysql_query($sql));
    mysql_query("UPDATE micro_blog SET hits = hits + 1 WHERE id = ".$_GET['id']);
} else {
    echo "参数引入失败!";
}
?>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $rc['title'];?>|我的微博客</title>
</head>
<body>
<a href="default.php">返回主页面</a>
<hr color="#00FFFF" size="5px"/>
<h2><?php echo $rc['title'];?>
  <hr color="#006699" size="3px">
</h2>
<li><?php echo "日期:".$rc['date']."|浏览次数:".$rc['hits'];?></li>
<p><?php echo $rc['content'];?></p>
</body>
</html> 

自动分成功能在ecshop系统自带是没有的,如果我们需要对一单添加分成功能我们是需要进入二次开发的,下面小编来为各位介绍一个例子。

大概逻辑:
后台操作一个订单发货的时候进行自动分成,后台取消发货,退货,改为未发货的时候去掉自动分成部分。
核心代码:lib_common.php

//分成积分计算

function fenchenjifen($usertype=3,$point){

 $affiliate = unserialize($GLOBALS['_CFG']['affiliate']);       

  

if($usertype==3){   //采购

 

                             

                if ($affiliate['config']['level_register_up'])

        {

            $affiliate['config']['level_register_up'] /= 100;

        }

            $point_cg = round($affiliate['config']['level_register_up'] * intval($point), 0);

            return $point_cg;

        }   

if($usertype==1){//经销商

        if ($affiliate['config']['level_money_all'])

        {

            $affiliate['config']['level_money_all'] /= 100;

        }

            $point_cg = round($affiliate['config']['level_money_all'] * intval($point), 0);

            return $point_cg;

        }   

if($usertype==2){//财务

    if ($affiliate['config']['level_register_all'])

        {

            $affiliate['config']['level_register_all'] /= 100;

        }

            $point_cg = round($affiliate['config']['level_register_all'] * intval($point), 0);

            return $point_cg;

        }   

             

         

         

}

 

 

/**

* 

* @param undefined $order  订单信息

* @param undefined $buyuser 购买者信息

* @param undefined $integral 计算积分

* $type = 1 增加  $type=-1 撤销

* 分成log状态99

*/

function fun_fencheng_change($order,$buyuser,$integral=array(),$type=1){//店铺分成计算

    if(intval($order['parent_shopid'])==0) return false;

    if(!is_array($buyuser)) return false;

     

    $order_id=$order['order_id'];

    $separate_by=99;

    switch($buyuser['usertype']){

        case '0'://购买者类型

         $row = $GLOBALS['db']->getRow("SELECT * from " . $GLOBALS['ecs']->table('users') . " u ".

                    " WHERE u.shopid  =".$order['parent_shopid']." and u.usertype=1"

                );//获取pid

         

            $up_uid = $row['user_id'];          

            if(!empty($up_uid) && $up_uid > 0)

            {

                $money=$point=0;    

                $point= fenchenjifen(1,$integral['custom_points']); 

                         

               // $info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $point);

                $info="订单".$order['order_sn']."分成获得积分:".$point;

                log_account_change($up_uid, $money, 0, ($type)*$point, ($type)*$point, $info);

                //var_dump($info);  

                if($type==1){           

                 

                write_affiliate_log1($order_id, $up_uid, $row['user_name'], $money, $point, $separate_by);

                }else{

                    rollback_affiliate_log($order_id);

                }

                $orderupdate['is_separate']=$type==1?$separate_by:0;

                 $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'),

        $orderupdate, 'UPDATE', "order_id = '$order_id'");

            }

        break;

        case '3':

        $row = $GLOBALS['db']->getAll("SELECT u.shopid,u.user_id,u.usertype, u.user_name FROM " . $GLOBALS['ecs']->table('users') . " u ".

                    " WHERE u.shopid= ".$order['parent_shopid']." and u.usertype in (1,2)");

                    foreach($row as $val){ // 经销商和财务获得分成

                        if($val['usertype']==1){

                            $pointf = fenchenjifen(1,$integral['custom_points']);   

                            }

                        if($val['usertype']==2){

                            $pointf = fenchenjifen(2,$integral['custom_points']);   

                            }   

                            $up_uid = $val['user_id'];

                            //$info = sprintf($GLOBALS['_LANG']['separate_info'], $order['order_sn'], $money, $pointf);

                            $info="订单".$order['order_sn']."分成获得积分:".$pointf;

                log_account_change($up_uid, $money, 0, ($type)*$pointf, ($type)*$pointf, $info);

                 

                if($type==1){           

                      write_affiliate_log1($order_id, $up_uid, $val['user_name'], $money, $pointf, $separate_by);

                }else{

                    rollback_affiliate_log($order_id);

                }

                 $orderupdate['is_separate']=$type==1?$separate_by:0;

                 $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'),

        $orderupdate, 'UPDATE', "order_id = '$order_id'");      

                    }

         

        break;

    }

    return true;

}

 

/**

* 

* @param undefined $oid

* @param undefined $uid

* @param undefined $username

* @param undefined $money

* @param undefined $point

* @param undefined $separate_by

* 写入订单分成 log

*/

function write_affiliate_log1($oid, $uid, $username, $money, $point, $separate_by)

{

    $time = gmtime();

    $sql = "INSERT INTO " . $GLOBALS['ecs']->table('affiliate_log') . "( order_id, user_id, user_name, time, money, point, separate_type)".

                                                              " VALUES ( '$oid', '$uid', '$username', '$time', '$money', '$point', $separate_by)";

    if ($oid)

    {

        $GLOBALS['db']->query($sql);

    }

}

 

//撤销订单分成

function rollback_affiliate_log($order_id,$falg=-2){

      $sql = "UPDATE " . $GLOBALS['ecs']->table('affiliate_log') .

               " SET separate_type = '$falg'" .

               " WHERE order_id = '$order_id'";

         $GLOBALS['db']->query($sql);

}


需要注意的点:
后台发货程序在admin/order.php
需要修改的地方有: 发货 866行 ,取消发货 1035行 改为未发货 3961行 退货4132行。
本代码只计算分成部分。自己下单部分另外。
这个代码是按照店铺ID分成,多商户的。为ecshop二次开发版。无法用于原版。
调用分成: fun_fencheng_change($order,$user,$integral,1);
取消分成: fun_fencheng_change($order,$user,$integral,-1);

[!--infotagslink--]

相关文章