//充值订单 拿推广的金额
function rec_bal($uid, $paymoney, $old)
{
$total_top_bal = db('user')->where(['uid' => $uid])->value('total_top_bal');
if ($total_top_bal === NUll) return ['code' => false, 'msg' => '未查到余额或没有该用户'];
//当前充值多少单
$moneyNum = (int)($paymoney / 10000);
$tuid = db('user')->where(['uid' => $uid])->value('tuid');
if ($tuid === NUll) return ['code' => true, 'msg' => '没有推荐人'];
//当前父类充值数总额
$num = (int)(db('user')->where(['tuid' => $tuid])->sum('total_top_bal')) / 10000;
//未充值前的总单数
$old = $num - $moneyNum;
if ($num < 6) return ['code' => true, 'msg' => '没有超过最低单数,推荐人无法获得奖励'];
switch ($num) {
case $num >= 6 && $num <= 10:
$money = $moneyNum * 10;
break;
case $num >= 11 && $num <= 60:
$money = (10 - ($old < 5 ? 5 : $old)) * 10 + ($num - 10) * 20;
break;
case $num >= 61 && $num <= 120:
$money = 0;
$money += (10 - ($old < 5 ? 5 : $old)) * 10 < 0 ? 0 : (10 - ($old < 5 ? 5 : $old)) * 10;
$old >= 0 && $old <= 10 && $money += 1000;
$old >= 11 && $old <= 59 && $money += (60 - $old) * 20;
$money += $old > 60 ? $moneyNum * 30 : ($num - 60) * 30;
break;
case $num >= 121 && $num <= 600:
$money = 0;
$money += (10 - ($old < 5 ? 5 : $old)) * 10 < 0 ? 0 : (10 - ($old < 5 ? 5 : $old)) * 10;
$old >= 0 && $old <= 10 && $money += 1000;
$old >= 11 && $old <= 59 && $money += (60 - $old) * 20;
$old >= 0 && $old <= 60 && $money += 1800;
$old >= 61 && $old <= 120 && $money += (120 - $old) * 30;
$money += $old > 120 ? $moneyNum * 40 : ($num - 120) * 40;
break;
case $num >= 601:
$money = 0;
$money += (10 - ($old < 5 ? 5 : $old)) * 10 < 0 ? 0 : (10 - ($old < 5 ? 5 : $old)) * 10;
$old >= 0 && $old <= 10 && $money += 1000;
$old >= 11 && $old <= 59 && $money += (60 - $old) * 20;
$old >= 0 && $old <= 60 && $money += 1800;
$old >= 61 && $old <= 120 && $money += (120 - $old) * 30;
$old >= 0 && $old <= 120 && $money += 19200;
$old >= 121 && $old <= 600 && $money += (600 - $old) * 40;
$money += $old > 600 ? $moneyNum * 50 : ($num - 600) * 50;
break;
}
$data = Db::name('user')->where(['uid' => $tuid])->field('uid,drwa_bal,daogou')->find();
$data['drwa_bal'] += $money;
$data['daogou'] += $money;
$res = Db::name('user')->update($data);
$code = (int)($res !== false);
return ['code' => $code, 'msg' => ['奖励充值失败', '奖励充值成功'][$code], 'uid' => $tuid, 'money' => $money];
}
第一次写推广算法 记录一下
最新推荐文章于 2023-12-29 22:27:14 发布