欢迎光临景诺科技软件开发淘宝店

进店请收藏,谢谢

用户支付后多级分销自动分成代码

代码是注册分级分成。
必须传入的订单信息,订单号,用户id,订单id,是否分成,分成金额。如下:

/**
* $order['order_sn']='123456789';
	$order['user_id']='39';
	$order['order_id']='19';
	$order['is_separate']='0';
	$order['fencheng']='500';
* @param undefined $order
* @param undefined $money
* 自动分成   $separate_by=99
* @return
*/
function autofenchen($order){//自动分成 by shanmao.me
	if($order['is_separate']!=0) return false;
	 $affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
    empty($affiliate) && $affiliate = array();

    $separate_by = 99;
	$level_register_up = (float)$affiliate['config']['level_register_up'];
	
	$order_sn = $order['order_sn'];
	$buyuserid = $order['user_id'];
	$oid = $order['order_id'];
	$money = round($order['fencheng'],2);
	
	$row['user_id']=$buyuserid;
	
            //推荐注册分成
            $num = count($affiliate['item']);
            for ($i=0; $i < $num; $i++)
            {
                $affiliate['item'][$i]['level_point'] = (float)$affiliate['item'][$i]['level_point'];
                $affiliate['item'][$i]['level_point1'] = (float)$affiliate['item'][$i]['level_point1'];
                $affiliate['item'][$i]['level_money'] = (float)$affiliate['item'][$i]['level_money'];
                if ($affiliate['item'][$i]['level_point'])
                {
                    $affiliate['item'][$i]['level_point'] /= 100;
                }
                if ($affiliate['item'][$i]['level_point1'])
                {
                    $affiliate['item'][$i]['level_point1'] /= 100;
                }
                if ($affiliate['item'][$i]['level_money'])
                {
                    $affiliate['item'][$i]['level_money'] /= 100;
                }
                 $setpoint = round($money * $affiliate['item'][$i]['level_point'], 2); // 普通会员
                 $setpoint1 = round($money * $affiliate['item'][$i]['level_point1'], 2); //分销第一次
                $setmoney = round($money * $affiliate['item'][$i]['level_money'], 2);    //分销第二次以上   http://shanmao.me 修改           
                
                $row = $GLOBALS['db']->getRow("SELECT o.parent_id as user_id,u.user_name FROM " . $GLOBALS['ecs']->table('users') . " o" .
                        " LEFT JOIN" . $GLOBALS['ecs']->table('users') . " u ON o.parent_id = u.user_id".
                        " WHERE o.user_id = '$row[user_id]'"
                    );
                $up_uid = $row['user_id'];
                $z_user_rank = uid_re_rank($buyuserid);
                if (empty($up_uid) || empty($row['user_name']))
                {
                    break;
                }
                else
                {                	 
                	if($z_user_rank!=102){//自己不是分销商
                		$info = "订单分成".$order_sn.",金额:".$setpoint;
						 log_account_change($up_uid, $setpoint, 0, 0, 0, $info);
						 write_affiliate_log1($oid, $up_uid, $row['user_name'], $setpoint, 0, $separate_by);
					}else{
						$info = "订单分成".$order_sn.",金额:".$setpoint1;
						if(uid_re_ordertimes_b600($buyuserid)==1 && uid_re_orderendbuy($buyuserid)>=$level_register_up){ //判断第一次成为分销商							
						log_account_change($up_uid, $setpoint1, 0, 0, 0, $info);
						 write_affiliate_log1($oid, $up_uid, $row['user_name'], $setpoint1, 0, $separate_by);
						}else{
							$info = "订单分成".$order_sn.",金额:".$setmoney;
							 log_account_change($up_uid, $setmoney, 0, 0, 0, $info);
						 write_affiliate_log1($oid, $up_uid, $row['user_name'], $setmoney, 0, $separate_by);
						}	
						
						
					}           	
                	
                
                }
            }
	
	
}

更多

本文固定链接: http://shanmao.me/web-system/ecshop-web-system/yong-hu-zhi-fu-hou-duo-ji-fen-xiao-zi-dong-fen-cheng-dai-ma | 山猫的博客

该日志由 admin 于2015年05月22日发表在 ECSHOP二次开发 分类下,
原创文章转载请注明: 用户支付后多级分销自动分成代码 | 山猫的博客