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; } } } }
/** *使用礼包码 */ public function useProductPackCodeAction() { //基础元素,必须参与验证 $User['UserId'] = abs(intval($this->request->UserId)); $User['ProductPackCode'] = $this->request->ProductPackCode; $User['Time'] = abs(intval($this->request->Time)); $User['ServerId'] = $this->request->ServerId; $User['ReturnType'] = $this->request->ReturnType ? $this->request->ReturnType : 2; //URL验证码 $sign = $this->request->sign; //私钥,以后要移开到数据库存储 $p_sign = 'lm'; $sign_to_check = base_common::check_sign($User, $p_sign); //不参与验证的元素 //验证URL是否来自可信的发信方 if ($sign_to_check == $sign) { if ($User['UserId']) { //验证时间戳,时差超过600秒即认为非法 if (abs($User['Time'] - time()) <= 600) { if ($User['ServerId']) { //查询用户 $UserInfo = $this->oUser->GetUserById($User['UserId']); if ($UserInfo['UserId']) { unset($User['ReturnType']); //判断用户所选服务器大区是否存在 $ServerInfo = $this->oServer->getRow($User['ServerId']); if ($ServerInfo['ServerId']) { $oProductPack = new Config_Product_Pack(); $ProductPackCode = $oProductPack->getUserProductPackCode($User['ProductPackCode'], $User['UserId']); if (!$ProductPackCode['ProductPackCode']) { $ProductPackCode = $oProductPack->getProductPackCode($User['ProductPackCode']); } if ($ProductPackCode['ProductPackCode']) { if (($ProductPackCode['AppId'] = $ServerInfo['AppId']) && ($ProductPackCode['PartnerId'] = $ServerInfo['PartnerId'])) { if (!$ProductPackCode['UsedUser']) { $GenInfo = $oProductPack->GetGenPackCodeLogById($ProductPackCode['GenId']); if ($GenInfo['GenId']) { if ($User['Time'] <= $GenInfo['EndTime']) { if ($GenInfo['needBind'] == 2) { $ProductPack = $oProductPack->getRow($ProductPackCode['ProductPackId']); if ($ProductPack['ProductPackId']) { if ($ProductPack['UseCountLimit']) { $GenLog = $oProductPack->getGenLog(0, 0, $ProductPackCode['ProductPackId'], 2, 0, 0, 0); $UseLog = $oProductPack->getUserPackUserLog(0, 0, $UserInfo['UserId'], $ProductPackCode['ProductPackId'], Base_Common::getArrList($GenLog['GenLog']), 0); $Count = count($UseLog); //获取该用户该礼包使用次数 if ($Count >= $ProductPack['UseCountLimit']) { $result = array('return' => 0, 'comment' => "您的该礼包使用次数已经超过上限"); } else { $Use = $oProductPack->usePackCode($ProductPackCode['ProductPackCode'], $ServerInfo['ServerId'], $UserInfo['UserId'], $User['Time']); if ($Use) { $result = array('return' => 1, 'comment' => "礼包已经在发送中,请稍后登陆游戏查收"); } else { $result = array('return' => 2, 'comment' => "礼包发送失败,请稍后重试"); } } } else { $Use = $oProductPack->usePackCode($ProductPackCode['ProductPackCode'], $ServerInfo['ServerId'], $UserInfo['UserId'], $User['Time']); if ($Use) { $result = array('return' => 1, 'comment' => "礼包已经在发送中,请稍后登陆游戏查收"); } else { $result = array('return' => 2, 'comment' => "礼包发送失败,请稍后重试"); } } } else { $result = array('return' => 0, 'comment' => "无此礼包"); } } else { if ($ProductPackCode['AsignUser'] == $UserInfo['UserId']) { $Use = $oProductPack->usePackCode($ProductPackCode['ProductPackCode'], $ServerInfo['ServerId'], $UserInfo['UserId'], $User['Time']); if ($Use) { $result = array('return' => 1, 'comment' => "礼包已经在发送中,请稍后登陆游戏查收"); } else { $result = array('return' => 2, 'comment' => "礼包发送失败,请稍后重试"); } } else { $result = array('return' => 0, 'comment' => "该礼包的指定使用用户不是您"); } } } else { $result = array('return' => 0, 'comment' => "礼包已经过期"); } } else { $result = array('return' => 0, 'comment' => "无此批次"); } } else { if ($ProductPackCode['UsedUser'] == $UserInfo['UserId']) { if ($ProductPackCode['CodeStatus'] == 1) { $ProductPack = $oProductPack->getRow($ProductPackCode['ProductPackId']); if (time() - $ProductPack['UseTimeLag'] >= $ProductPackCode['UsedTime']) { $errorList = $this->oCharacter->getSendErrorList($UserInfo['UserId'], $ProductPackCode['ProductPackCode']); $addLog = 0; $oProduct = new Config_Product_Product(); foreach ($errorList as $key => $errorLog) { $insert = $oProduct->insertIntoProductSendList($ProductPackCode['ProductPackCode'], 'ProductPack', $errorLog['ProductId'], $errorLog['ProductType'], $errorLog['ProductCount'], $errorLog['UserId'], $errorLog['ServerId'], time()); if ($insert) { $addLog++; } } if ($addLog) { $oProductPack->updatePackCode($ProductPackCode['ProductPackCode'], array('UsedTime' => time())); $result = array('return' => 1, 'comment' => $addLog . "个道具重新加入发放队列"); } else { $result = array('return' => 1, 'comment' => "礼包码已于 " . date("Y-m-d H:i:s", $ProductPackCode['UsedTime']) . " 被您使用"); } } else { $result = array('return' => 0, 'comment' => "您的操作过于频繁," . $ProductPack['UseTimeLag'] . "秒内只允许操作一次,请稍后再试"); } } } else { $result = array('return' => 0, 'comment' => "礼包码已于 " . date("Y-m-d H:i:s", $ProductPackCode['UsedTime']) . " 被其他用户使用"); } } } else { $result = array('return' => 0, 'comment' => "您所输入的礼包码不允许在此服务器使用"); } } else { $result = array('return' => 0, 'comment' => "无此礼包码"); } } else { $result = array('return' => 0, 'comment' => "您所选择的服务器不存在"); } } else { $result = array('return' => 2, 'comment' => "无此用户"); } } else { $result = array('return' => 2, 'comment' => "请选择服务器"); } } else { $result = array('return' => 2, 'comment' => "时间有误"); } } else { $result = array('return' => 0, 'comment' => "请选择用户"); } } else { $result = array('return' => 2, 'comment' => "验证失败,请检查URL"); } $User['ReturnType'] = $this->request->ReturnType ? $this->request->ReturnType : 2; if ($User['ReturnType'] == 1) { echo json_encode($result); } }