搜索

首页  >  问答  >  正文

php 使用 NOT 运算符评估条件

我有 4 个销售办事处,一旦所有 4 个销售办事处均收到 20 个销售线索,则只有 4 号销售办事处应该收到当天剩余的销售线索。我需要一些帮助来创建条件,以基本上检查销售办公室 1-4 是否均已收到 20 个潜在客户,然后显然按照说明继续进行

首先,我查询数据库来检查我的计数器(是的,我知道这可以更紧凑,并且可以在循环内完成)

$sales_office= 1;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office1_count = $result['LeadsReceivedToday'];

$sales_office= 2;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office2_count = $result['LeadsReceivedToday'];

$sales_office= 3;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office3_count = $result['LeadsReceivedToday'];

$sales_office= 4;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office4_count = $result['LeadsReceivedToday'];

当我执行这个逻辑时,它没有按预期工作?一旦 sales_office = 1 达到 20 个销售线索,它就会直接转移到销售办公室 4?

if ($sales_office1_count != 20 && $sales_office2_count != 20 && $sales_office3_count != 20)
{
    //distribute leads to sales office 1-4 in order of 1-4
    
}
else
{
   //only send leads to sales office no 4
}

P粉618358260P粉618358260225 天前407

全部回复(1)我来回复

  • P粉792673958

    P粉7926739582024-04-03 09:03:57

    您当前对所有办公室计数的逻辑检查,您必须分别检查每个办公室。

    if ($sales_office1_count < 20 || $sales_office2_count < 20 || $sales_office3_count < 20)
    {
        //distribute leads to sales office 1-4 in order of 1-4
        
    }
    else
    {
       //only send leads to sales office no 4
    }

    此外,您可以通过使用数组来提高代码的可读性:

    $officesLeadsCount = [1 => 0, 2 => 0, 3 => 0, 4 => 0];
    
    foreach ($officesLeadsCount as $number => $value) {
      $sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
      $sql->execute([$number]);
      $result = $sql->fetch();
      $officesLeadsCount[$number] = $result['LeadsReceivedToday'];    
    }
    
    
    if ($officesLeadsCount[1] < 20 || $officesLeadsCount[2] < 20 || $officesLeadsCount[3] < 20)
    {
        //distribute leads to sales office 1-4 in order of 1-4
    
    }
    else
    {
       //only send leads to sales office no 4
    }

    回复
    0
  • 取消回复