当前位置:   article > 正文

三级分销原理_三级分销 逻辑

三级分销 逻辑

公司刚刚做了个三级分销推广,下面总结一下实现原理
数据库设计:
这里写图片描述
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']);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/163852
推荐阅读
相关标签
  

闽ICP备14008679号