赞
踩
公司刚刚做了个三级分销推广,下面总结一下实现原理
数据库设计:
shareid:分享人的本平台id
receiver_tel:参与分销的用户手机号
time:时间戳
today:今天日期
当领取的这个手机号成为平台用户并且购买成功之后,给shareid对应的奖励,这地方直说三级分销
先找上一级,再找上上一级,奖励方式基本类似
代码如下:
//给分销人员奖励
$m_mall_money = M('mall_money'); //资金记录表
$m_common_user = M('common_user'); //用户表
$m_fenxiao = M('fenxiao');
$u['id'] = $uid;
$user_data = $m_common_user->where($u)->field('tel')->find();
$order['order_id'] = $orderIdStr;
$orderInformation = $m_pay_order->where($order)->field('gid,paynums')->find();
$mallInfo['id'] = $orderInformation['gid'];
$mallInformation = $m_mall_content->where($mallInfo)->field('amount')->find();
$totalAmount = $orderInformation['paynums'] * $mallInformation['amount'];
$fenxiaoMap['receiver_tel'] = $user_data['tel'];
$previous = $m_fenxiao->where($fenxiaoMap)->field('shareid')->find();
if ($previous) {
$originUser['id'] = $previous['shareid'];
$thisUser = $m_common_user->where($originUser)->field('id,tel,money')->find();
$moneyMap['uid'] = $previous['shareid'];
$moneyMap['type'] = 1;
$moneyMap['type_value'] = 1;
$moneyMap['begin_money'] = $thisUser['money'];
$moneyMap['money'] = $totalAmount * 0.01;
$moneyMap['paymoney'] = 0.00;
$moneyMap['end_money'] = $moneyMap['begin_money'] + $moneyMap['money'];
$moneyMap['value'] = '一级分销佣金奖励';
$moneyMap['time'] = time();
$moneyMap['ip'] = get_client_ip();
$moneyMap['status'] = 1;
$moneyMap['order_id'] = time();
$m_mall_money->add($moneyMap);
$m_common_user->where($originUser)->setField('money', $moneyMap['begin_money'] + $moneyMap['money']);
//寻找第一分销人
$fenxiaoMap2['receiver_tel'] = $thisUser['tel'];
$previous2 = $m_fenxiao->where($fenxiaoMap2)->field('shareid')->find();
if ($previous2) {
$originUser2['id'] = $previous2['shareid'];
$thisUser2 = $m_common_user->where($originUser2)->field('id,tel,money')->find();
$moneyMap2['uid'] = $previous2['shareid'];
$moneyMap2['type'] = 1;
$moneyMap2['type_value'] = 1;
$moneyMap2['begin_money'] = $thisUser2['money'];
$moneyMap2['money'] = $totalAmount * 0.005;
$moneyMap2['paymoney'] = 0.00;
$moneyMap2['end_money'] = $moneyMap2['begin_money'] + $moneyMap2['money'];
$moneyMap2['value'] = '二级分销佣金奖励';
$moneyMap2['time'] = time();
$moneyMap2['ip'] = get_client_ip();
$moneyMap2['status'] = 1;
$moneyMap2['order_id'] = time().'2';
$m_mall_money->add($moneyMap2);
$m_common_user->where($originUser2)->setField('money', $moneyMap2['begin_money'] + $moneyMap2['money']);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。