示例#1
0
文件: Credit.php 项目: krisrita/udo
 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;
 }
示例#2
0
文件: Account.php 项目: krisrita/udo
 function getOrderResult($uid, $transNo)
 {
     $tblTrans = new DB_Udo_TransNotify();
     $isSolid = Common_Config::NOTIFY_SOLID;
     //计算超时时间
     //其实计算点
     $startMicroTime = time();
     do {
         $result = $tblTrans->scalar("statusValue", "where transNo = {$transNo} and isSolid = {$isSolid}");
         //终止计算点
         $endMicroTime = time();
         //时间间隔
         $interval = $endMicroTime - $startMicroTime;
     } while (!$result && $interval < 3);
     //如果timeout结束还没有接到通知,去公共云主动查询,如果查询没有结果返回失败状态
     if (!$result) {
         $rand = new Common_Char();
         $random = $rand->getRandChar(8);
         $sign = md5(Common_Config::PAY_OSID . $transNo . $random . Common_Config::PAY_SECRET);
         $post_data = array("osid" => Common_Config::PAY_OSID, "transNo" => $transNo, "random" => $random, "sign" => $sign);
         $url = Common_Config::TRANS_QUERY;
         $cl = new Common_Curl();
         $result = $cl->request($url, $post_data);
         if (!$result) {
             return Common_Error::ERROR_TRANS_UNKNOWN;
         }
     }
     //$result['status'] = 0;
     //如果查到了交易的信息,判断交易的状态
     $notifyUncertain = Common_Config::NOTIFY_UNCERTAIN;
     $updateId = $tblTrans->scalar("id", "where transNo = '{$transNo}' and isSolid = {$notifyUncertain}");
     //print_r($result);
     switch ($result['statusValue']) {
         case Common_Config::ORDER_SUCCESS:
             //如果获取到了支付成功的通知信息,更新U币交易日志和order的状态
             //先从order表获取交易的coinId
             $tblOrder = new DB_Udo_Order();
             $tblCoinInfo = new DB_Udo_CoinInfo();
             $coin = $tblOrder->scalar("id,coinId", "where transNo = '{$transNo}'");
             $coinId = $coin['coinId'];
             $coinInfo = $tblCoinInfo->scalar("amt,price", "where id = {$coinId}");
             $info = "充值" . $coinInfo['amt'] . "U币";
             //将U币充值信息写入coinLog
             $this->insertTransLog($uid, $coinInfo['amt'], $info, Common_Config::COIN_LOG);
             //$tblOrder->update($coin['id'],array("status"=>Common_Config::ORDER_SUCCESS));
             $statusSuccess = Common_Config::ORDER_SUCCESS;
             $tblOrder->query("update udo_order set status = {$statusSuccess} where id = {$coin['id']}");
             //更新通知的状态为可靠
             if ($updateId) {
                 $notifySolid = Common_Config::NOTIFY_SOLID;
                 $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}");
                 //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID));
             }
             return Common_Error::ERROR_ORDER_SUCCESS;
             //如果订单是未支付的状态,那么将订单信息写入transNotify
         //如果订单是未支付的状态,那么将订单信息写入transNotify
         case Common_Config::ORDER_NOT_PAY:
             //如果没有写入,则写入信息
             if (!$updateId) {
                 $tblTrans->insert(array("transNo" => $transNo, "isSolid" => Common_Config::NOTIFY_UNCERTAIN, "createTime" => time()));
             }
             return Common_Error::ERROR_TRANS_UNKNOWN;
             //如果接收到订单失败的消息,
         //如果接收到订单失败的消息,
         case Common_Config::ORDER_FAIL:
             if ($updateId) {
                 $notifySolid = Common_Config::NOTIFY_SOLID;
                 $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}");
                 //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID));
             }
             return Common_Error::ERROR_TRANS_FAIL;
         case Common_Config::ORDER_CLOSED:
             if ($updateId) {
                 $notifySolid = Common_Config::NOTIFY_SOLID;
                 $tblTrans->query("update udo_trans_notify set isSolid = {$notifySolid} where id = {$updateId['id']}");
                 //$tblTrans->update($updateId['id'],array("isSolid"=>Common_Config::NOTIFY_SOLID));
             }
             return Common_Error::ERROR_TRANS_CLOSED;
         default:
             return Common_Error::ERROR_TRANS_UNKNOWN;
     }
 }