首頁  >  問答  >  主體

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粉618358260223 天前398

全部回覆(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
  • 取消回覆