Example #1
0
 public function UnPackExchangeResult($buff, $uType)
 {
     $oSocketType = @(include __APP_ROOT_DIR__ . "/etc/SocketType.php");
     $oExchange = new Lm_Exchange();
     $TypeInfo = $oSocketType[$uType];
     if ($TypeInfo['Type']) {
         $format = $TypeInfo['UnPackFormat'];
         $unpackArr = @unpack($TypeInfo['UnPackFormat'], $buff);
         $ExchangeInfo = $oExchange->getQueuedExchange(trim($unpackArr['uExchangeID']));
         if ($unpackArr['uResultID'] == 0) {
             if ($ExchangeInfo['ExchangeStatus'] == 1) {
                 $EndExchange = $oExchange->endExchange($ExchangeInfo['ExchangeId'], $unpackArr['uSN']);
             }
         } else {
             if ($ExchangeInfo['ReTryCount'] < 3) {
                 $reTry = $oExchange->updateExchangeQueue($ExchangeInfo['ExchangeId'], array('RetryCount' => $ExchangeInfo['ReTryCount'] + 1));
                 $addQueue = $oExchange->convertExchangeToSocket($ExchangeInfo['ExchangeId']);
             } else {
                 $oExchange->ExchangeFail($unpackArr['uExchangeID']);
             }
         }
     }
 }
Example #2
0
 public function convertProductToSocket($ProductInfo)
 {
     //订单状态为尚未通知服务器
     if ($ProductInfo['SendStatus'] == 0) {
         $oSocketType = @(include __APP_ROOT_DIR__ . "/etc/SocketType.php");
         $oSocketQueue = new Config_SocketQueue();
         //发放英雄
         if ($ProductInfo['ProductType'] == "hero") {
             $uType = 60227;
             $TypeInfo = $oSocketType[$uType];
             if ($TypeInfo['Type']) {
                 $DataArr = array('PackFormat' => $TypeInfo['PackFormat'], 'Length' => $TypeInfo['Length'], 'Length2' => 0, 'uType' => $uType, 'MsgLevel' => 0, 'Line' => 0, 'UserID' => $ProductInfo['UserId'], 'HeroID' => $ProductInfo['ProductId'], 'Serial' => $ProductInfo['SendId']);
             }
             $DataArr = array('ServerId' => $ProductInfo['ServerId'], 'uType' => $uType, 'UserId' => $DataArr['UserID'], 'MessegeContent' => serialize($DataArr), 'QueueTime' => time(), 'SendTime' => 0);
             $this->db->begin();
             $addQueue = $oSocketQueue->insert($DataArr);
             $updateStatus = $this->updateProductQueue($ProductInfo['SendId'], $ProductInfo['ProductId'], array('SendStatus' => 1));
             if ($addQueue && updateStatus) {
                 $this->db->commit();
                 return true;
             } else {
                 $this->db->rollback();
                 return false;
             }
         }
         //发放时装
         if ($ProductInfo['ProductType'] == "skin") {
             $uType = 60229;
             $TypeInfo = $oSocketType[$uType];
             if ($TypeInfo['Type']) {
                 $ServerList = @(include __APP_ROOT_DIR__ . "/etc/Server.php");
                 $ServerInfo = $ServerList[$ProductInfo['ServerId']];
                 $oSkin = new Config_Skin();
                 $SkinInfo = $oSkin->getRow($ProductInfo['ProductId'], $ServerInfo['AppId']);
                 $DataArr = array('PackFormat' => $TypeInfo['PackFormat'], 'Length' => $TypeInfo['Length'], 'Length2' => 0, 'uType' => $uType, 'MsgLevel' => 0, 'Line' => 0, 'UserID' => $ProductInfo['UserId'], 'HeroID' => $SkinInfo['HeroId'], 'HeroEquip' => $ProductInfo['ProductId'], 'Serial' => $ProductInfo['SendId']);
             }
             $DataArr = array('ServerId' => $ProductInfo['ServerId'], 'uType' => $uType, 'UserId' => $DataArr['UserID'], 'MessegeContent' => serialize($DataArr), 'QueueTime' => time(), 'SendTime' => 0);
             $this->db->begin();
             $addQueue = $oSocketQueue->insert($DataArr);
             $updateStatus = $this->updateProductQueue($ProductInfo['SendId'], $ProductInfo['ProductId'], array('SendStatus' => 1));
             if ($addQueue && updateStatus) {
                 $this->db->commit();
                 return true;
             } else {
                 $this->db->rollback();
                 return false;
             }
         }
         //发放金钱
         if ($ProductInfo['ProductType'] == "money") {
             $uType = 60223;
             $TypeInfo = $oSocketType[$uType];
             if ($TypeInfo['Type']) {
                 $ServerList = @(include __APP_ROOT_DIR__ . "/etc/Server.php");
                 $ServerInfo = $ServerList[$ProductInfo['ServerId']];
                 $oSkin = new Config_Skin();
                 $SkinInfo = $oSkin->getRow($ProductInfo['ProductId'], $ServerInfo['AppId']);
                 $DataArr = array('PackFormat' => $TypeInfo['PackFormat'], 'Length' => $TypeInfo['Length'], 'Length2' => 0, 'uType' => $uType, 'MsgLevel' => 0, 'Line' => 0, 'UserID' => $ProductInfo['UserId'], 'MoneyChanged' => $ProductInfo['ProductCount'], 'MoneyType' => $ProductInfo['ProductId'], 'Serial' => $ProductInfo['SendId']);
             }
             $DataArr = array('ServerId' => $ProductInfo['ServerId'], 'uType' => $uType, 'UserId' => $DataArr['UserID'], 'MessegeContent' => serialize($DataArr), 'QueueTime' => time(), 'SendTime' => 0);
             $this->db->begin();
             $addQueue = $oSocketQueue->insert($DataArr);
             $updateStatus = $this->updateProductQueue($ProductInfo['SendId'], $ProductInfo['ProductId'], array('SendStatus' => 1));
             if ($addQueue && updateStatus) {
                 $this->db->commit();
                 return true;
             } else {
                 $this->db->rollback();
                 return false;
             }
         }
         //发放游戏币
         if ($ProductInfo['ProductType'] == "appcoin") {
             $oProductPack = new Config_Product_Pack();
             $CodeInfo = $oProductPack->getUserProductPackCode($ProductInfo['SendId'], $ProductInfo['UserId']);
             $Comment = json_decode($CodeInfo['Comment'], true);
             if (!isset($Comment['ExchangeId'])) {
                 $oExchange = new Lm_Exchange();
                 $createExchange = $oExchange->createExchangeQueueByCode($ProductInfo['UserId'], $ProductInfo['ServerId'], $ProductInfo['ProductCount'], $ProductInfo['SendId']);
                 $this->db->begin();
                 if ($createExchange) {
                     $updateStatus = $this->updateProductQueue($ProductInfo['SendId'], $ProductInfo['ProductId'], array('SendStatus' => 1));
                     $Comment['ExchangeId'] = $createExchange;
                     $updateCode = $oProductPack->updatePackCode($ProductInfo['SendId'], array('Comment' => json_encode($Comment)));
                     if ($updateStatus && $updateCode) {
                         $this->db->commit();
                         return true;
                     } else {
                         $this->db->rollback();
                         return false;
                     }
                 } else {
                     $this->db->rollback();
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
 }