Example #1
0
 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);
 }
Example #2
0
 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;
     }
 }