Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 function testAccount()
 {
     $tblAccount = new DB_Pay_Account();
     $tblUser = new DB_Sso_User();
     $userIds = $tblUser->fetchAll("id,name");
     foreach ($userIds as $k => $value) {
         $tblAccount->insert(array("sso_id" => $value['id'], "user_name" => $value['name'], "score" => 500, "amt" => 50, "created_time" => date('Y-m-d H:i:s')));
     }
 }
Ejemplo n.º 3
0
 function updateAccount($score, $amt, $id)
 {
     $tblAccount = new DB_Pay_Account();
     //首先更新账户信息
     //更新账户信息,如果失败再重试三次
     $retry = 0;
     $updateAccount = 0;
     while (!$updateAccount && $retry <= 3) {
         $updateAccount = $tblAccount->query("update account set amt = {$amt},score = {$score} where id = {$id['id']}");
         //$updateAccount = $tblAccount->update($id['id'],array("amt"=>$id['amt']-$creditInfo['price'],"score"=>$id['score']+$creditInfo['amt']));
         $retry++;
     }
     //账户更新失败返回失败信息
     if (!$updateAccount) {
         return Common_Error::ERROR_UPDATE_BALANCE;
     }
 }