Esempio n. 1
0
 public function getMarketOfficeCity($zone_id)
 {
     $mrkt_office = MarketOfficeCity::select('market_office_city.market_office_id')->leftJoin('market_office_city_delivery_zone', 'market_office_city_delivery_zone.market_office_city_id', '=', 'market_office_city.id')->where('market_office_city_delivery_zone.id', '=', $zone_id)->first();
     if (!empty($mrkt_office) && $mrkt_office->market_office_id != '') {
         $market_office_id = $mrkt_office->market_office_id;
     } else {
         $market_office_id = NULL;
     }
     return $market_office_id;
 }
Esempio n. 2
0
 protected function driverAndLocationInfo($input)
 {
     $response['delivery_zone'] = array();
     //getting the driver information based on current meal plan
     $driverHelper = new DriverHelper();
     $drivers = $driverHelper->getDriver();
     //getting all the delivery zone in a market office
     $market_city_ids_arr = array();
     $market_city_ids = MarketOfficeCity::select('id')->where('market_office_id', '=', Session::get('admin_market_ofc'))->get();
     foreach ($market_city_ids as $eachCT) {
         if ($eachCT->id) {
             array_push($market_city_ids_arr, $eachCT->id);
         }
     }
     if (isset($market_city_ids_arr) && is_array($market_city_ids_arr) && count($market_city_ids_arr) > 0) {
         $delivery_zone = MarketOfficeCityDeliveryZones::select("id", "delivery_zone_name")->whereIn('market_office_city_id', $market_city_ids_arr)->get();
         $key = 1;
         foreach ($delivery_zone as $val) {
             $response['delivery_zone'][$val["id"]] = $val;
             if (empty($drivers['data'][$val["id"]])) {
                 $drivers['data'][$val["id"]] = array();
             }
             if (empty($drivers['each_driver_count'][$val["id"]])) {
                 $drivers['each_driver_count'][$val["id"]] = 0;
             }
         }
     }
     $response['data'] = $drivers['data'];
     $response['count'] = $drivers['count'];
     $response['meal_cat_name'] = $drivers['meal_cat_name'];
     $response['each_driver_count'] = $drivers['each_driver_count'];
     return $response;
 }
Esempio n. 3
0
 public function createDummyOrders()
 {
     $this->syncDeliveryZones(3);
     exit;
     //static data
     $input = array("meal_plan_id" => 254, "zone_id" => 1, "state_code" => "CA");
     echo "<pre>";
     //input data randomized
     $recipient = array("lr3nRmFE50bWm0dGdPH8rfeZ", "64r7AdG6q7oLmhvsVXGBIhZN", "K4M1OGiMkopR~fBSdiDKjJ6*");
     $rand = rand(0, 2);
     $input['recipient_id'] = $recipient[$rand];
     $db_exists = $this::setCurrentDatabase($input['state_code']);
     $OrderHelper = new OrderHelper();
     $market_office_id = $OrderHelper->getMarketOfficeCity($input['zone_id']);
     $mrkt_ofc_data = $OrderHelper->getMarketOfficeData($market_office_id);
     $customer = Customer::orderBy(DB::raw("RAND()"))->first();
     $food = $OrderHelper->getMenuItems($input['meal_plan_id']);
     $gross_amount = 0;
     //to be added to database
     $order = array();
     $order['state_code'] = $input['state_code'];
     $order['market_office_id'] = $market_office_id;
     $order['market_office_name'] = $mrkt_ofc_data['office_name'];
     $order['market_office_city_id'] = MarketOfficeCityDeliveryZones::where('id', '=', $input['zone_id'])->pluck('market_office_city_id');
     $order['market_office_city_name'] = MarketOfficeCity::where('id', '=', $order['market_office_city_id'])->pluck('city_name');
     $order['market_office_city_delivery_zone_id'] = $input['zone_id'];
     $order['market_office_city_delivery_zone_name'] = MarketOfficeCityDeliveryZones::where('id', '=', $input['zone_id'])->pluck('delivery_zone_name');
     $order['customer_id'] = $customer->id;
     $order['customer_delivery_address'] = $customer->address;
     $order['meal_plan_id'] = $input['meal_plan_id'];
     $order['meal_plan_name'] = $OrderHelper->getCurrentMealCategory($input['meal_plan_id']);
     $order['tax_percentage'] = $mrkt_ofc_data['tax_percentage'];
     $order['tax_amount'] = 0;
     $order['gross_amount'] = 0;
     $order['coupon_id'] = 0;
     $order['coupon_code'] = NULL;
     $order['coupon_amount'] = "0.00";
     $order['credit'] = "0.00";
     $order['tips_percentage'] = "0";
     $order['tips_amount'] = "0.00";
     $order['total_amount'] = $gross_amount + $order['tax_amount'];
     $order['note'] = "";
     $order['phone'] = $customer->phone;
     $order['order_status'] = "Processing";
     $order['created_at'] = date('Y-m-d H:i:s');
     $lastOrderId = Order::insertGetId($order);
     echo $lastOrderId . "\n";
     $orderDetails = $OrderHelper->insertOrderDetails($food, $lastOrderId);
     print_r($orderDetails);
     $menu_food = array();
     foreach ($orderDetails as $val) {
         $obj['food_id'] = $val['menu_item_id'];
         $obj['food_qty'] = $val['quantity'];
         $menu_food[] = (object) $obj;
         $gross_amount += $val['amount'];
     }
     $hash = sha1($lastOrderId . uniqid(mt_rand()));
     $order_number = sha1($lastOrderId . uniqid(mt_rand()));
     $transactionId = 0;
     $card_number = "NDI0Mg==";
     $cardType = "Visa";
     $order_number = $input['state_code'] . '00' . $lastOrderId;
     $tax_amount = round($gross_amount * ($order['tax_percentage'] / 100), 2);
     $total_amount = $gross_amount + $tax_amount;
     Order::where('id', '=', $lastOrderId)->update(array('transaction_id' => $transactionId, 'card_number' => $card_number, 'card_type' => $cardType, 'hash' => $hash, 'order_number' => $order_number, 'payment_status' => 'Charged', 'gross_amount' => $gross_amount, 'tax_amount' => $tax_amount, 'total_amount' => $total_amount));
     $order['order_id'] = $lastOrderId;
     $order['food'] = $menu_food;
     $order['recipient_id'] = $input['recipient_id'];
     #$ApiRedis = new ApiRedis();
     $b = $this->syncDeliveryZones(1);
     $c = $this->pushOrderIntoQueue($lastOrderId, 0);
     $d = $this->pushOrderIntoHash($lastOrderId, $order);
     var_dump($b);
     var_dump($c);
     var_dump($d);
     print_r($order);
     echo $order_number . "\n" . $transactionId . "\n" . $hash . "\n" . $card_number . "\n" . $cardType . "\n" . $gross_amount . "\n" . $tax_amount;
     // $ApiRedis->pushOrderIntoQueue($order);
 }
Esempio n. 4
0
 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);
 }