예제 #1
0
파일: Trade.php 프로젝트: krisrita/udo
 function getTopOrder()
 {
     $tblCoin = new DB_Udo_CoinInfo();
     $tblCredit = new DB_Udo_CreditInfo();
     $orderCoin = $tblCoin->scalar("`order`", "where isValid = 1", "order by `order` desc");
     $orderCredit = $tblCredit->scalar("max(`order`)", "where isValid = 1");
     return array("orderCoin" => $orderCoin['order'] + 1, "orderCredit" => $orderCredit['max(`order`)'] + 1);
 }
예제 #2
0
파일: Account.php 프로젝트: krisrita/udo
 function coinScore($id, $uid)
 {
     $tblCoinLog = new DB_Udo_CoinLog();
     $tblCreditLog = new DB_Udo_UserCreditLog();
     $tblCreditInfo = new DB_Udo_CreditInfo();
     $tblAccount = new DB_Pay_Account();
     //先找到兑换的汇率和额度
     $creditInfo = $tblCreditInfo->scalar("id,amt,price", "where isValid = 1 and id = {$id}");
     //首先更新账户信息
     //获取账户余额
     $id = $tblAccount->scalar("id,amt,score", "where sso_id = {$uid}");
     if ($id['amt'] < $creditInfo['price']) {
         return Common_Error::ERROR_SHORT_BALANCE;
     }
     //print_r($id);
     //更新账户信息,如果失败再重试三次
     $retry = 0;
     $updateAccount = 0;
     while (!$updateAccount && $retry <= 3) {
         $amt = $id['amt'] - $creditInfo['price'];
         $score = $id['score'] + $creditInfo['amt'];
         $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;
     }
     //账户更新成功,插入学分和U币变动日支
     $tblCoinLog->insert(array("userId" => $uid, "amt" => 0 - $creditInfo['price'], "info" => "U币兑换学分", "createTime" => time()));
     $tblCreditLog->insert(array("userId" => $uid, "creditSource" => Common_Config::CREDIT_COIN_EXCHANGE, "info" => "U币兑换获得学分", "amt" => $creditInfo['amt'], "status" => Common_Config::CREDIT_SUCCESS, "createTime" => time()));
     return Common_Error::ERROR_SUCCESS;
 }