protected function getMarketOfficeZonesDrivers()
 {
     $marketOfficeHelper = new MarketOfficeHelper();
     $market_office = $marketOfficeHelper->getMarketOffice();
     $delivery_zones = $marketOfficeHelper->getZones($market_office['market_ofc_ids']);
     $zones = $delivery_zones['delivery_zones'];
     foreach ($market_office['market_ofc'] as $key => $val) {
         if (!empty($zones[$key])) {
             $market_office['market_ofc'][$key]['zones'] = $zones[$key];
         } else {
             $market_office['market_ofc'][$key]['zones'] = array();
         }
     }
     return array("market_ofc" => $market_office['market_ofc'], 'total_driver_cnt' => $delivery_zones['count']);
 }
 protected function zoneCntInMrkt($market_office_id)
 {
     $zoneCnt = 0;
     $zoneDetails = array();
     $marketOfcCityIdCnt = MarketOfficeCity::where('market_office_id', $market_office_id)->count();
     if ($marketOfcCityIdCnt > 0) {
         $marketOfcCityIds = MarketOfficeCity::select('id')->where('market_office_id', $market_office_id)->get()->toArray();
         if (count($marketOfcCityIds) > 0) {
             $zoneCnt = MarketOfficeCityDeliveryZones::whereIn('market_office_city_id', $marketOfcCityIds)->count();
             if ($zoneCnt > 0) {
                 $zoneDetails = MarketOfficeCityDeliveryZones::select('id', 'delivery_zone_name', 'wait_time_ratio', 'wait_time_override')->whereIn('market_office_city_id', $marketOfcCityIds)->get();
                 $marketOfficeHelper = new MarketOfficeHelper();
                 $ApiRedis = new ApiRedis();
                 $db = $this->redisDb;
                 foreach ($zoneDetails as $k => $v) {
                     $zoneDetails[$k]['driver_cnt'] = $marketOfficeHelper->getZoneDriverCount($v->id, $market_office_id);
                     $count = $ApiRedis->getOrderCountQueue($v->id, $db);
                     $zoneDetails[$k]['unassigned_orders'] = $count['unassigned'];
                     $zoneDetails[$k]['assigned_orders'] = $count['assigned'];
                     $zoneDetails[$k]['total_orders'] = $zoneDetails[$k]['assigned_orders'] + $zoneDetails[$k]['unassigned_orders'];
                     $wait_time_override = $v->wait_time_override;
                     $wait_time_ratio = $v->wait_time_ratio;
                     if (isset($wait_time_override) && $wait_time_override == 'true') {
                         $wait_time_ratio = $wait_time_override;
                     } else {
                         if ($zoneDetails[$k]['total_orders'] > 0 && $zoneDetails[$k]['driver_cnt'] > 0) {
                             $wait_time_ratio = round($zoneDetails[$k]['total_orders'] / $zoneDetails[$k]['driver_cnt']);
                         } else {
                             $wait_time_ratio = 0;
                         }
                     }
                     if ($wait_time_ratio >= 0 && $wait_time_ratio <= 1.9) {
                         $avgDeliveryTimeMsg = "10-20 Minutes";
                     } else {
                         if ($wait_time_ratio >= 2 && $wait_time_ratio <= 2.9) {
                             $avgDeliveryTimeMsg = "20-30 Minutes";
                         } else {
                             if ($wait_time_ratio >= 3 && $wait_time_ratio <= 3.9) {
                                 $avgDeliveryTimeMsg = "30-40 Minutes";
                             } else {
                                 if ($wait_time_ratio >= 4 && $wait_time_ratio <= 4.9) {
                                     $avgDeliveryTimeMsg = "40-50 Minutes";
                                 } else {
                                     if ($wait_time_ratio == 5) {
                                         $avgDeliveryTimeMsg = "50-60 Minutes";
                                     } else {
                                         if ($wait_time_ratio > 5) {
                                             $avgDeliveryTimeMsg = "1 Hour";
                                         } else {
                                             $avgDeliveryTimeMsg = "1 Hour";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $zoneDetails[$k]['cur_delivery_time'] = $avgDeliveryTimeMsg;
                     unset($avgDeliveryTimeMsg);
                 }
                 //unset($driverHelper);
             }
         }
     }
     return array('zone_cnt' => $zoneCnt, 'zone_details' => $zoneDetails);
 }