/** * 对给定数据进行数据库积分增减操作 * * @param array $setArr 操作数据 array(1 => array('money' => ??, 'rvrc' => ??), 2 => array(), 3 => array(), ...) * @param bool $isAdd 是否实时进行数据库操作 */ function runsql($setArr = null, $isAdd = true) { global $db, $uc_server, $uc_syncredit; $setUser = isset($setArr) ? $setArr : $this->setUser; $retv = array(); if ($uc_server && $uc_syncredit) { require_once R_P . 'uc_client/uc_client.php'; $retv = uc_credit_add($setUser, $isAdd); } $cacheUids = $cacheCredits = array(); $userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */ foreach ($setUser as $uid => $setv) { $updateUser = $increaseUser = array(); foreach ($setv as $cid => $v) { if ($this->check($cid) && ($v != 0 || !$isAdd)) { if (isset($retv[$uid][$cid])) { if ($uc_server == 1) { continue; } $act = 'set'; $v = $retv[$uid][$cid]; } else { $act = $isAdd ? 'add' : 'set'; } if (is_numeric($cid)) { $v = intval($v); /** $db->pw_update( "SELECT uid FROM pw_membercredit WHERE uid=" . S::sqlEscape($uid) . ' AND cid=' . S::sqlEscape($cid), "UPDATE pw_membercredit SET " . ($act == 'add' ? 'value=value+' : 'value=') . S::sqlEscape($v) . ' WHERE uid=' . S::sqlEscape($uid) . ' AND cid=' . S::sqlEscape($cid), "INSERT INTO pw_membercredit SET " . S::sqlSingle(array('uid' => $uid, 'cid' => $cid, 'value' => $v)) ); **/ $db->pw_update("SELECT uid FROM pw_membercredit WHERE uid=" . S::sqlEscape($uid) . ' AND cid=' . S::sqlEscape($cid), pwQuery::buildClause("UPDATE :pw_table SET " . ($act == 'add' ? 'value=value+' : 'value=') . ':value' . ' WHERE uid=:uid AND cid=:cid', array('pw_membercredit', $v, $uid, $cid)), pwQuery::insertClause('pw_membercredit', array('uid' => $uid, 'cid' => $cid, 'value' => $v))); } else { $cid == 'rvrc' && ($v *= 10); if ($act == 'add') { $increaseUser[$cid] = intval($v); } else { $updateUser[$cid] = intval($v); } } } } if ($increaseUser) { $userService->updateByIncrement($uid, array(), $increaseUser); } if ($updateUser) { $userService->update($uid, array(), $updateUser); } unset($this->getUser[$uid]); $cacheUids[] = 'UID_' . $uid; $cacheCredits[] = 'UID_CREDIT_' . $uid; } // if ($cacheUids) { // $_cache = getDatastore(); // $_cache->delete($cacheUids); // $_cache->delete($cacheCredits);/*积分*/ // } $this->writeLog(); !isset($setArr) && ($this->setUser = array()); }
/** * 会员积分兑换 * @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); } }
function credit_add($uid, $point) { $credit = array("{$uid}" => array('credit' => $point)); return uc_credit_add($credit); }
function runsql($setArr = null, $isAdd = true) { global $db, $uc_server, $uc_syncredit; $setUser = isset($setArr) ? $setArr : $this->setUser; $retv = array(); if ($uc_server && $uc_syncredit) { require_once R_P . 'uc_client/uc_client.php'; $retv = uc_credit_add($setUser, $isAdd); } $cacheUids = $cacheCredits = array(); foreach ($setUser as $uid => $setv) { $sql = ''; foreach ($setv as $cid => $v) { $v = intval($v); if ($this->check($cid) && ($v != 0 || !$isAdd)) { if (isset($retv[$uid][$cid])) { if ($uc_server == 1) { continue; } $act = 'set'; $v = $retv[$uid][$cid]; } else { $act = $isAdd ? 'add' : 'set'; } if (is_numeric($cid)) { $db->pw_update("SELECT uid FROM pw_membercredit WHERE uid=" . pwEscape($uid) . ' AND cid=' . pwEscape($cid), "UPDATE pw_membercredit SET " . ($act == 'add' ? 'value=value+' : 'value=') . pwEscape($v) . ' WHERE uid=' . pwEscape($uid) . ' AND cid=' . pwEscape($cid), "INSERT INTO pw_membercredit SET " . pwSqlSingle(array('uid' => $uid, 'cid' => $cid, 'value' => $v))); } else { $cid == 'rvrc' && ($v *= 10); $sql .= ($act == 'add' ? ",{$cid}={$cid}+" : ",{$cid}=") . pwEscape($v); } } } if ($sql) { $db->update("UPDATE pw_memberdata SET " . ltrim($sql, ',') . " WHERE uid=" . pwEscape($uid), 0); } unset($this->getUser[$uid]); $cacheUids[] = 'UID_' . $uid; $cacheCredits[] = 'UID_CREDIT_' . $uid; } if ($cacheUids) { $_cache = getDatastore(); $_cache->delete($cacheUids); $_cache->delete($cacheCredits); /*积分*/ } $this->writeLog(); !isset($setArr) && ($this->setUser = array()); }