( 目前正有 102 位朋友陪你一起在逛超市!) 注册 | 登录 | 合作网站账号登录

ecshop自动分成程序代码升级版

来源网站:源码购吧网 发布时间:2016-12-11 阅读:177 评价:177次

大概逻辑:

后台操作一个订单发货的时候进行自动分成,后台取消发货,退货,改为未发货的时候去掉自动分成部分。

核心代码: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(!emptyempty($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);
 

下一篇:ECSHOP后台给文章加上日期时间修改
上一篇:关于微信中分享到朋友圈代码今日热门话题,最近火爆源代码

用户评论

用户名: 匿名用户
E-mail:
评价等级:
评论内容:
验证码: captcha
点此将本站加入收藏,方便下次访问 ICP备案证书号:10008743号-1
© 2005-2018 源码购吧网 版权所有,并保留所有权利。 北京市朝阳区朝来科技园 客服邮箱: mku8@qq.com
程序由新源代 gouba8.cn提供 QQ 1220462776 淘宝旺旺sss8811