累計充值送禮品(有點繞)

活動說明:客戶累計充值1萬送1個蛋蛋碎片,當天累計充值10萬送1個蛋蛋精靈
PC地址:https://www.huijindaicn.com/i...
WAP地址:https://www.huijindaicn.com/w...php

/**
 * @param $user_id 用戶id
 * @param $amount 充值金額
 */
function modify_egg_chip($user_id,$amount)
{
    $base_money = 10000; // 送碎片基數
    $base_money_2 = 100000; // 送精靈基數
    $lock_money = lock_money = $GLOBALS['db']->getOne("SELECT SUM(amount) FROM ".DB_PREFIX."reapal_recharge WHERE user_id = ".$user_id." and is_lock = 1 and code = '0000' and is_callback = 1");
    // 獲取上次未贈送餘額
    $lock_money = $lock_money - $amount;
    $balance_money = $lock_money - intval($lock_money/$base_money)*$base_money; 
    // 獲取贈送碎片數量
    $egg_num = intval(($balance_money + $amount)/$base_money);

    // 更新用戶蛋蛋碎片數量
    if($egg_num >= 1)
    {
        $count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."user_egg WHERE user_id= ".$user_id." AND type=0");
        if($count)
        {
            $update_time = TIME_UTC; 
            $GLOBALS['db']->query("update ".DB_PREFIX."user_egg set num = num+".$egg_num.",update_time= ".$update_time." where user_id = ".$user_id." AND type=0");    
        }
        else
        {
            $ueggs['user_id'] = $user_id;
            $ueggs['name'] = '';
            $ueggs['type'] = 0;
            $ueggs['is_effect'] = 1;
            $ueggs['num'] = $egg_num;
            $ueggs['update_time'] = TIME_UTC;
            $GLOBALS['db']->autoExecute(DB_PREFIX."user_egg", $ueggs, "INSERT"); 
        }
    }

    // 獲取當天累計充值
    $today_start = to_timespan(to_date(TIME_UTC,"Y-m-d"),"Y-m-d");
    $today_lock_money = $GLOBALS['db']->getOne("SELECT SUM(amount) FROM ".DB_PREFIX."reapal_recharge WHERE user_id = ".$user_id." and
       succ_time >= ".$today_start." and is_lock = 1 and code = '0000' and is_callback = 1");
    $today_lock_money = $today_lock_money - $amount;
    $today_balance_money = $today_lock_money - intval($today_lock_money/$base_money_2)*$base_money_2;
    $egg_num_2 = intval(($today_balance_money + $amount)/$base_money_2);

    if($egg_num_2 >= 1)
    {            
        $count = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."user_egg WHERE user_id= ".$user_id." AND type=1");
        if($count)
        {
            $update_time = TIME_UTC;
            $GLOBALS['db']->query("update ".DB_PREFIX."user_egg set num = num+".$egg_num_2.", update_time = ".$update_time." where user_id = ".$user_id." AND type = 1");                         
        }
        else
        {
            $ueggs['user_id'] = $user_id;
            $ueggs['name'] = '';
            $ueggs['type'] = 1;
            $ueggs['is_effect'] = 1;
            $ueggs['num'] = $egg_num_2;
            $ueggs['update_time'] = TIME_UTC;
            $GLOBALS['db']->autoExecute(DB_PREFIX."user_egg", $ueggs, "INSERT");
        } 
    }       
}
相關文章
相關標籤/搜索