function getCredit($userId, $actionId, $schoolId) { $tblCredit = new DB_Udo_CreditAction(); $tblAccount = new DB_Pay_Account(); $tblCreditLog = new DB_Udo_UserCreditLog(); $rand = new Common_Char(); //获取该动作的基础信息 $result = $tblCredit->scalar("creditAmount,name,outputInput,ratio,times,isSynthesized,actionType", "where actionId = {$actionId} and isValid = 1"); if (!$result) { return Common_Error::ERROR_ACTION; } $upTimes = $result['times']; //接下来获取用户当日的同action的操作 $today = strtotime("today"); $tomorrow = strtotime("tomorrow"); $statusSuccess = Common_Config::CREDIT_SUCCESS; $sameTimes = $tblCreditLog->queryCount("where actionId = {$actionId} and userId = {$userId} and createTime between {$today} and {$tomorrow}\r\n and status = {$statusSuccess}"); //如果今日增长已经超出限额 if ($sameTimes >= $upTimes) { return Common_Error::ERROR_OVER_TIMES; } //否则更新账户信息,如果失败再重试三次 $retry = 0; $updateAccount = 0; $id = $tblAccount->scalar("id,amt,score", "where sso_id = {$userId}"); //print_r($id); //$testUpdate = $tblAccount->query("update account set score = 1895 where id = {$id['id']}"); //print_r($testUpdate); while (!$updateAccount && $retry <= 3) { $score = $id['score'] + $result['creditAmount']; //print_r($score); //$updateAccount = $tblAccount->query("update account set score = {$score} where id = {$id['id']}"); $remark = "日常活动"; $random = $rand->getRandChar(8); $sign = md5(Common_Config::PAY_OSID . $userId . $result['creditAmount'] . $remark . $random . Common_Config::PAY_SECRET); //print_r(Common_Config::PAY_OSID.(string)$userId.(string)$score.$remark.$random.Common_Config::PAY_SECRET); $url = Common_Config::CREDIT_UPDATE; $post_data = array("osid" => Common_Config::PAY_OSID, "ssoId" => $userId, "score" => $result['creditAmount'], "remark" => $remark, "random" => $random, "sign" => $sign); $cl = new Common_Curl(); $updateAccount = $cl->request($url, $post_data); $retry++; //print_r($updateAccount); } //账户更新失败返回失败信息 if (!$updateAccount) { return Common_Error::ERROR_UPDATE_BALANCE; } //账户更新成功,插入学分和U币变动日支 $tblCreditLog->insert(array("userId" => $userId, "creditSource" => Common_Config::DAILY_CREDIT_ACTION, "actionId" => $actionId, "info" => $result['name'] . "获得学分", "amt" => $result['creditAmount'], "status" => Common_Config::CREDIT_SUCCESS, "schoolId" => $schoolId, "createTime" => time())); return Common_Error::ERROR_SUCCESS; }
function insertTransLog($uid, $amount, $info, $type, $ssotoken = "", $schoolId = 0) { //print_r($type); //print_r($amount); $tblCoinLog = new DB_Udo_CoinLog(); $tblCreditLog = new DB_Udo_UserCreditLog(); $isAuth = 0; if ($ssotoken && $schoolId) { $userModel = new UserModel(); $isAuth = $userModel->getUserAuth($uid, $schoolId, $ssotoken); } //print_r($isAuth); switch ($type) { case Common_Config::COIN_LOG: $tblCoinLog->insert(array("userId" => $uid, "amt" => $amount, "info" => $info, "createTime" => time(), "isAuthorized" => $isAuth)); break; case Common_Config::CREDIT_LOG: $tblCreditLog->insert(array("userId" => $uid, "creditSource" => Common_Config::CREDIT_BUY, "info" => $info, "amt" => $amount, "status" => Common_Config::CREDIT_SUCCESS, "createTime" => time(), "isAuthorized" => $isAuth)); break; } }