Example #1
0
 /**
  * 根据APP与Partner获取区服列表
  * @return unknown_type
  */
 public function serverByAppPartnerAction()
 {
     $app = $this->request->AppId;
     $partner = $this->request->PartnerId;
     $rows = $this->oServer->getByAppPartner($app, $partner);
     echo "<option value=''>--全部--</option>";
     foreach ($rows as $k => $v) {
         echo "<option value='{$v['ServerId']}'>{$v['name']}:{$v['server_url']}</option>";
     }
 }
 /**
  * 将数据入库
  * @return unknown_type
  */
 public function insertQueueAction()
 {
     //检查权限
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $bind = $this->request->from('ServerId', 'AppId', 'PartnerId', 'StartTime', 'Lag', 'Count', 'CountDown', 'MessegeContent', 'uType');
     $bind['StartTime'] = strtotime($this->request->StartTime);
     //起始时间
     if ($bind['StartTime'] < time() - 600) {
         $response = array('errno' => 1);
         echo json_encode($response);
         return false;
     }
     //发送次数
     if ($bind['Count'] <= 0) {
         $response = array('errno' => 2);
         echo json_encode($response);
         return false;
     }
     //倒记数
     if ($bind['CountDown'] < 0) {
         $response = array('errno' => 3);
         echo json_encode($response);
         return false;
     }
     //间隔
     if ($bind['Count'] > 1) {
         if ($bind['Lag'] < 0) {
             $response = array('errno' => 5);
             echo json_encode($response);
             return false;
         }
     }
     //倒记数
     if (trim($bind['MessegeContent']) == "") {
         $response = array('errno' => 4);
         echo json_encode($response);
         return false;
     }
     $ServerList = $this->oServer->getByAppPartner($bind['AppId'], $bind['PartnerId']);
     $socketType = $this->oSocketType->getRow($bind['uType']);
     $total_log = 0;
     foreach ($ServerList as $Server => $ServerInfo) {
         if ($bind['ServerId'] > 0) {
             if ($Server == $bind['ServerId']) {
                 $start_time = $bind['StartTime'];
                 for ($i = 1; $i <= $bind['Count']; $i++) {
                     $CountDown = 0;
                     if ($bind['Count'] == $i && !empty($bind['CountDown']) && $bind['CountDown'] > 0) {
                         $CountDown = $bind['CountDown'];
                     }
                     $bind['PackFormat'] = $socketType['PackFormat'];
                     $bind['Length'] = $socketType['Length'];
                     $bind['Length2'] = 0;
                     $bind['uType'] = $bind['uType'];
                     $bind['MsgLevel'] = 0;
                     $bind['Line'] = 0;
                     $bind['CountDown'] = $CountDown;
                     $bind['MessegeContent'] = $bind['MessegeContent'];
                     $QueueTime = $bind['Count'] > 0 ? $start_time + ($i - 1) * $bind['Lag'] : $start_time;
                     $queueArr = array('ServerId' => $bind['ServerId'], 'MessegeContent' => serialize($bind), 'uType' => $bind['uType'], 'UserId' => $QueueTime, 'QueueTime' => $QueueTime);
                     $insert_log = $this->oSocketQueue->insert($queueArr);
                     if ($insert_log) {
                         $total_log++;
                     }
                 }
             }
         } else {
             $start_time = $bind['StartTime'];
             for ($i = 1; $i <= $bind['Count']; $i++) {
                 $QueueTime = $bind['Count'] > 0 ? $start_time + ($i - 1) * $bind['Lag'] : $start_time;
                 $queueArr = array('ServerIp' => $ServerInfo['ServerIp'], 'SocketPort' => $ServerInfo['SocketPort'], 'MessegeContent' => $bind['MessegeContent'], 'QueueTime' => $start_time, 'UserId' => $QueueTime, 'CountDown' => $bind['CountDown']);
                 $insert_log = $this->oSocketQueue->insert($queueArr);
                 if ($insert_log) {
                     $total_log++;
                 }
             }
         }
     }
     $response = array('errno' => 0, 'success' => $total_log);
     echo json_encode($response);
     return true;
 }