$ratio = 0; if ($exchange_amount <= 0) { show_message($_LANG['invalid_points'], $_LANG['transform_points'], 'user.php?act=transform_points'); } if ($exchange_amount > $row[$shop_points[$fromcredits]]) { show_message($_LANG['overflow_points'], $_LANG['transform_points'], 'user.php?act=transform_points'); } foreach ($rule as $credit) { if ($credit['appiddesc'] == $appiddesc && $credit['creditdesc'] == $creditdesc && $credit['creditsrc'] == $fromcredits) { $ratio = $credit['ratio']; break; } } if ($ratio == 0) { show_message($_LANG['exchange_deny'], $_LANG['transform_points'], 'user.php?act=transform_points'); } $netamount = floor($exchange_amount / $ratio); include_once ROOT_PATH . './includes/lib_uc.php'; $result = exchange_points($row['user_id'], $fromcredits, $creditdesc, $appiddesc, $netamount); if ($result === true) { $sql = "UPDATE " . $ecs->table('users') . " SET {$shop_points[$fromcredits]}={$shop_points[$fromcredits]}-'{$exchange_amount}' WHERE user_id='{$row['user_id']}'"; $db->query($sql); $sql = "INSERT INTO " . $ecs->table('account_log') . "(user_id, {$shop_points[$fromcredits]}, change_time, change_desc, change_type)" . " VALUES ('{$row['user_id']}', '-{$exchange_amount}', '" . gmtime() . "', '" . $cfg['uc_lang']['exchange'] . "', '98')"; $db->query($sql); show_message(sprintf($_LANG['exchange_success'], $exchange_amount, $_LANG['exchange_points'][$fromcredits], $netamount, $credit['title']), $_LANG['transform_points'], 'user.php?act=transform_points'); } else { show_message($_LANG['exchange_error_1'], $_LANG['transform_points'], 'user.php?act=transform_points'); } } } }
function action_act_transform_ucenter_points() { $user = $GLOBALS['user']; $_CFG = $GLOBALS['_CFG']; $_LANG = $GLOBALS['_LANG']; $smarty = $GLOBALS['smarty']; $db = $GLOBALS['db']; $ecs = $GLOBALS['ecs']; $user_id = $_SESSION['user_id']; $rule = array(); if ($_CFG['points_rule']) { $rule = unserialize($_CFG['points_rule']); } $shop_points = array(0 => 'rank_points', 1 => 'pay_points'); $sql = "SELECT user_id, user_name, pay_points, rank_points FROM " . $ecs->table('users') . " WHERE user_id='{$user_id}'"; $row = $db->getRow($sql); $exchange_amount = intval($_POST['amount']); $fromcredits = intval($_POST['fromcredits']); $tocredits = trim($_POST['tocredits']); $cfg = unserialize($_CFG['integrate_config']); if (!empty($cfg)) { $_LANG['exchange_points'][0] = empty($cfg['uc_lang']['credits'][0][0]) ? $_LANG['exchange_points'][0] : $cfg['uc_lang']['credits'][0][0]; $_LANG['exchange_points'][1] = empty($cfg['uc_lang']['credits'][1][0]) ? $_LANG['exchange_points'][1] : $cfg['uc_lang']['credits'][1][0]; } list($appiddesc, $creditdesc) = explode('|', $tocredits); $ratio = 0; if ($exchange_amount <= 0) { show_message($_LANG['invalid_points'], $_LANG['transform_points'], 'user.php?act=transform_points'); } if ($exchange_amount > $row[$shop_points[$fromcredits]]) { show_message($_LANG['overflow_points'], $_LANG['transform_points'], 'user.php?act=transform_points'); } foreach ($rule as $credit) { if ($credit['appiddesc'] == $appiddesc && $credit['creditdesc'] == $creditdesc && $credit['creditsrc'] == $fromcredits) { $ratio = $credit['ratio']; break; } } if ($ratio == 0) { show_message($_LANG['exchange_deny'], $_LANG['transform_points'], 'user.php?act=transform_points'); } $netamount = floor($exchange_amount / $ratio); include_once ROOT_PATH . './includes/lib_uc.php'; $result = exchange_points($row['user_id'], $fromcredits, $creditdesc, $appiddesc, $netamount); if ($result === true) { $sql = "UPDATE " . $ecs->table('users') . " SET {$shop_points[$fromcredits]}={$shop_points[$fromcredits]}-'{$exchange_amount}' WHERE user_id='{$row['user_id']}'"; $db->query($sql); $sql = "INSERT INTO " . $ecs->table('account_log') . "(user_id, {$shop_points[$fromcredits]}, change_time, change_desc, change_type)" . " VALUES ('{$row['user_id']}', '-{$exchange_amount}', '" . gmtime() . "', '" . $cfg['uc_lang']['exchange'] . "', '98')"; $db->query($sql); show_message(sprintf($_LANG['exchange_success'], $exchange_amount, $_LANG['exchange_points'][$fromcredits], $netamount, $credit['title']), $_LANG['transform_points'], 'user.php?act=transform_points'); } else { show_message($_LANG['exchange_error_1'], $_LANG['transform_points'], 'user.php?act=transform_points'); } }