function uc_credit_note($username, $amount = 0, $credits = 'scores') { list($uid) = uc_get_user($username); if ($uid < 1 || !$amount) { return 0; } include DEDEDATA . '/credits.inc.php'; $arr = array('scores' => 1, 'money' => 2); $credit = isset($arr[$credits]) ? $arr[$credits] : 1; if (isset($_CACHE['credit']) && is_array($_CACHE['credit'])) { foreach ($_CACHE['credit'] as $appid => $creditsItems) { if ($creditsItems['creditdesc'] != $credit) { continue; } $amount = $amount * $creditsItems['ratio']; uc_credit_exchange_request($uid, $creditsItems['creditdesc'], $creditsItems['creditsrc'], $appid, $amount); } } }
if (!$outexange && !$extcredits[$fromcredits]['allowexchangeout']) { showmessage('extcredits_disallowexchangeout'); } if (!$outexange && !$extcredits[$tocredits]['allowexchangein']) { showmessage('extcredits_disallowexchangein'); } if (!$outexange) { $creditsarray[$fromcredits] = -$netamount; $creditsarray[$tocredits] = $amount; updatecredits($discuz_uid, $creditsarray); } else { if (!array_key_exists($fromcredits, $outextcredits[$tocredits]['creditsrc'])) { showmessage('extcredits_dataerror', NULL, 'HALTED'); } list($toappid, $tocredits) = explode('|', $tocredits); $ucresult = uc_credit_exchange_request($discuz_uid, $fromcredits, $tocredits, $toappid, $amount); if (!$ucresult) { showmessage('extcredits_dataerror', NULL, 'HALTED'); } $creditsarray[$fromcredits] = -$netamount; updatecredits($discuz_uid, $creditsarray); $netamount = $amount; $amount = $tocredits = 0; } $db->query("INSERT INTO {$tablepre}creditslog (uid, fromto, sendcredits, receivecredits, send, receive, dateline, operation)\r\n\t\t\t\t\tVALUES ('{$discuz_uid}', '{$discuz_user}', '{$fromcredits}', '{$tocredits}', '{$netamount}', '{$amount}', '{$timestamp}', 'EXC')"); showmessage('credits_transaction_succeed', '', 1); } } else { showmessage('action_closed', NULL, 'HALTED'); } } elseif (submitcheck('addfundssubmit')) {
if($amount <= 0) { showmessage('credits_transaction_amount_invalid'); } @include_once(S_ROOT.'./uc_client/client.php'); $ucresult = uc_user_login($_SGLOBAL['supe_username'], $_POST['password']); list($tmp['uid']) = saddslashes($ucresult); if($tmp['uid'] <= 0) { showmessage('credits_password_invalid'); } elseif($space['credit']-$amount < 0) { showmessage('credits_balance_insufficient'); } $netamount = floor($amount * 1/$_CACHE['creditsettings'][$tocredits]['ratio']); list($toappid, $tocredits) = explode('|', $tocredits); $ucresult = uc_credit_exchange_request($_SGLOBAL['supe_uid'], $_CACHE['creditsettings'][$tocredits]['creditsrc'], $tocredits, $toappid, $netamount); if(!$ucresult) { showmessage('extcredits_dataerror'); } $_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit-$amount WHERE uid='$_SGLOBAL[supe_uid]'"); showmessage('do_success', 'cp.php?ac=credit&op=exchange'); } elseif(empty($_CACHE['creditsettings'])) { showmessage('integral_convertible_unopened'); } } elseif ($_GET['op'] == 'rule') { $wherearr = array(); $wheresql = '';
/** * 会员积分兑换 * @author Vimhui Develop Team * @param * @return bool */ public function userCreditExchange($uid, $creditsrc, $to_credit, $to_appid, $net_amount) { if ($GLOBALS['setting_config']['ucenter_type'] == 'phpwind') { $credit = array("{$uid}" => array('credit' => $net_amount)); return uc_credit_add($credit); } else { return uc_credit_exchange_request($uid, $creditsrc, $to_credit, $to_appid, $net_amount); } }
showmessage('credits_exchange_balance_insufficient', '', array('title' => $_G['setting']['extcredits'][$fromcredits]['title'], 'minbalance' => $minbalance), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true)); } loaducenter(); $ucresult = uc_user_login(addslashes($_G['username']), $_GET['password']); list($tmp['uid']) = $ucresult; if ($tmp['uid'] <= 0) { showmessage('credits_password_invalid', '', array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true)); } if (!$outexange) { updatemembercount($_G['uid'], array($fromcredits => -$netamount, $tocredits => $exchangeamount), 1, 'CEC', $_G['uid']); } else { if (!array_key_exists($fromcredits, $_CACHE['creditsettings'][$tocredits]['creditsrc'])) { showmessage('extcredits_dataerror', NULL); } list($toappid, $tocredits) = explode('|', $tocredits); $ucresult = uc_credit_exchange_request($_G['uid'], $fromcredits, $tocredits, $toappid, $exchangeamount); if (!$ucresult) { showmessage('extcredits_dataerror', NULL); } updatemembercount($_G['uid'], array($fromcredits => -$netamount), 1, 'ECU', $_G['uid']); $netamount = $amount; $amount = $tocredits = 0; } showmessage('credits_transaction_succeed', 'home.php?mod=spacecp&ac=credit&op=exchange', array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true)); } } else { $wheresql = ''; $list = array(); $rid = intval($_GET['rid']); if ($_GET['rid']) { $wheresql = " AND rid='{$rid}'";
function submenu_credit_exchange() { echo '<div class=wrap>'; echo '<h2>' . __('Credit Exchange', 'ucenter') . '</h2>'; global $current_user; wp_get_current_user(); list($uid, $_, $_) = uc_get_user($current_user->user_login); $credit = intval(get_usermeta($current_user->ID, 'ucenter_credit')); if (empty($credit)) { $credit = 0; } echo __('Current Credits : ', 'ucenter') . $credit . ' ' . $this->integration_settings['ucenter_credit_unit'] . '<br />'; echo '<br />'; $apps = uc_app_ls(); $ratio_array = array(); foreach ($this->integration_settings['ucenter_credit_exchange_setting'] as $appid => $appsettings) { if ($appid == UC_APPID) { foreach ($appsettings as $appsetting) { foreach ($apps as $app) { if ($app['appid'] == $appsetting['appiddesc']) { echo '<form action="" method="post">'; printf(__('Exchange %s <input type="text" name="amount" size=5 value="0"> %s to %s %s with ratio %s', 'ucenter'), $this->integration_settings['ucenter_credit_name'], $this->integration_settings['ucenter_credit_unit'], $app['name'], $appsetting['title'], $appsetting['ratio']); echo "<input type='hidden' name='to' value='{$appsetting['creditdesc']}'>"; echo "<input type='hidden' name='toappid' value='{$appsetting['appiddesc']}'>"; echo '<input type="submit"><br />'; echo '</form>'; $ratio_array[implode(',', array($appsetting['creditdesc'], $appsetting['appiddesc']))] = $appsetting['ratio']; } } } } } if (!empty($_POST['to']) && !empty($_POST['toappid'])) { if (intval($_POST['amount']) >= 0 && intval($_POST['amount']) <= $credit) { $ratio = $ratio_array[implode(',', array($_POST['to'], $_POST['toappid']))]; if (uc_credit_exchange_request($uid, 0, $_POST['to'], $_POST['toappid'], $_POST['amount'] / $ratio)) { $credit -= $_POST['amount']; update_usermeta($current_user->ID, 'ucenter_credit', $credit); _e('Exchange Success!', 'ucenter'); } } else { _e('Invalid Credit Amount!', 'ucenter'); } } echo '</div>'; }
function send_credit($uid, $credit, $outextcredits) { if ((bool) $outextcredits) { foreach ($outextcredits as $outextcredit) { $credit = intval($credit / $outextcredit["ratio"]); uc_credit_exchange_request($uid, $outextcredit["creditsrc"], $outextcredit["creditdesc"], $outextcredit["appiddesc"], $credit); return $uid; } } }
/** * 兑换积分 * @param integer $uid 用户ID * @param integer $fromcredits 原积分 * @param integer $tocredits 目标积分 * @param integer $toappid 目标应用ID * @param integer $amount 积分数额 * @return boolean */ function exchange($uid, $fromcredits, $tocredits, $toappid, $amount) { $ucresult = uc_credit_exchange_request($uid, $fromcredits, $tocredits, $toappid, $amount); return $ucresult; }
/** * 积分兑换请求 * * @param integer $uid 用户 ID * @param integer $from 原积分 * @param integer $to 目标积分 * @param integer $toappid 目标应用ID * @param integer $amount 积分数额 * @return bool 1:请求成功 0:请求失败 */ public function uc_credit_exchange_request($uid, $from, $to, $toappid, $amount) { return uc_credit_exchange_request($uid, $from, $to, $toappid, $amount); }
$num = floor($exchangesource / $crproject['scurrency']); $curuser->updatecrids(array($crproject['scrid'] => -$crproject['scurrency'] * $num), 0, lang('currencyexcurrency')); $curuser->updatecrids(array($crproject['ecrid'] => $crproject['ecurrency'] * $num), 0, lang('currencyexcurrency')); $curuser->updatedb(); mcmessage('currencyexfinish', "?action=crexchange"); } else { empty($outextcredits[$ocrpid]) && mcmessage('uccurrencyexitem'); $exchangesource = max(0, intval($exchangesource)); !$exchangesource && mcmessage('inputexamount'); $outcredit = $outextcredits[$ocrpid]; $exchangesource < $outcredit['ratiosrc'] && mcmessage('examountsmall'); if ($exchangesource > $curuser->info['currency' . $outcredit['creditsrc']]) { mcmessage('examountlarge'); } $num = floor($exchangesource / $outcredit['ratiosrc']); require_once M_ROOT . './include/ucenter/config.inc.php'; require_once M_ROOT . './uc_client/client.php'; $ucresult = uc_get_user($curuser->info['mname']); if (!is_array($ucresult)) { mcmessage('noucuser'); } $uid = $ucresult[0]; $ucresult = uc_credit_exchange_request($uid, $outcredit['creditsrc'], $outcredit['creditdesc'], $outcredit['appiddesc'], $outcredit['ratiodesc'] * $num); if (!$ucresult) { mcmessage('currencyexfailed', "?action=crexchange"); } $curuser->updatecrids(array($outcredit['creditsrc'] => -$outcredit['ratiosrc'] * $num), 0, lang('currency exchange currency')); $curuser->updatedb(); mcmessage('currencyexfinish', "?action=crexchange"); } }