Javascript - 如何保护重复呼叫连接?

时间:2018-03-16 12:53:51

标签: javascript php jquery

我有一个呼叫中心应用程序,其中十个不同计算机中的十个代理登录,他们同时接到一个电话,现在谁先点击,他就得到了这份工作。问题是,如果有10个代理同时点击,则会触发重复操作。

AGENTS点击以下方法。 执行时,在数据库中更改result_status=fail以防止重复的呼叫应答。但由于某种原因,同时所有点击仍然重复发生。

function connect(input1,input2) {

  $.post(root + '/agent', {
      action: 'xyz',
      callerid: 10,

  }, function(msg) {
    if (msg.result == 'fail') {
      console.log('ALREADY --- CONNECTED --- BUSY');
      return false;
    }
    else {
      new_connection();
    }

  });    
}

PHP:

public function agentAction() {
    $this->_response->setHeader('Access-Control-Allow-Origin', '*');       
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender();   

    $this->db = Application_Model_Db::db_load();        

    $sql = "select *from sh_av_users where id='{$_POST['callerid']}' and callstatus='ring' limit 1";  

    $result = $this->db->fetchAll($sql);    
    $json = '';
    if (count($result) > 0) {
      $this->db->update('sh_av_users', 
                        array(
                              'callstatus' => 'busy'), 
                        array('id=?' => $_POST['callerid'] ));
      $json = array(
          'result' =>'ok',
      );      
    }   else {
      $json = array(
          'result' => 'fail',

      );        
    } 

    $this->getResponse()
            ->setHeader('Content-Type', 'application/json')
            ->setBody(Zend_Json::encode($json))
            ->sendResponse();

    exit;
  }

如何处理它只能由一个AGENT回答而不是重复代理?

0 个答案:

没有答案