Esempio n. 1
0
 /**
  *使用礼包码
  */
 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);
     }
 }