示例#1
0
 protected function getStateDropdown()
 {
     $data = array();
     $all_states = array();
     $market_ofc = array();
     $redis = new ApiRedis();
     $states_codes = $redis->getAllStateName();
     $i = 0;
     if ($states_codes) {
         foreach ($states_codes as $each) {
             $states = $redis->getStateLevelInfo($each);
             $all_states[$i]['id'] = $each;
             $all_states[$i]['value'] = $states['full_name'];
             $i++;
         }
     }
     $data['state'] = $all_states;
     $data['selected_state'] = '';
     if (Session::get('current_state_database') && Session::get('current_state_database') != "") {
         $data['selected_state'] = Session::get('current_state_database');
     }
     return $data;
 }
 protected function removeOrder($input)
 {
     $response = array();
     $payResponse = array();
     $menu_item_ids = array();
     $request_time = date('Y-m-d H:i:s');
     $customer_current_credit = 0;
     try {
         $dynamoClass = new DynamoDb();
         $dynamoClass->table(env('DYNAMO_TABLE_PREFIX') . '_customer');
         $orderHelper = new OrderHelper();
         $order_id = $input['order_id'];
         $valid_order = Order::where('id', $order_id)->where('order_status', 'Processing')->count();
         if (isset($order_id) && $order_id != '' && $valid_order > 0) {
             //getting the order information by  order id
             $order_data = $orderHelper->getOrderInfo($order_id);
             list($transaction_id, $order_number, $customer_id, $driver_id, $coupon_id, $market_office_id, $credit, $state_code, $customer_current_credit, $customer_new_credit, $total_amount, $foodjets_meal_plan_id) = $order_data['data'];
             if (count($order_data['data']) > 0 && $transaction_id != '') {
                 try {
                     $order_data = $order_data['order_data'];
                     if (isset($total_amount) && $total_amount > 0) {
                         File::requireOnce(base_path() . '/vendor/heartlandpayment/Hps.php');
                         $configHps = new Hps();
                         $config = new HpsServicesConfig();
                         $config->secretApiKey = $this->heartlandConfig['secretApiKey'];
                         $config->versionNumber = $this->heartlandConfig['versionNumber'];
                         // this is provided to you during the certification process
                         $config->developerId = $this->heartlandConfig['developerId'];
                         // this is provided to you during the certification process
                         $chargeService = new HpsCreditService($config);
                         try {
                             $paymentGatewayVoidResponse = $chargeService->void($transaction_id);
                             $formatter_void = Formatter::make($paymentGatewayVoidResponse, Formatter::XML);
                             $formattedVoidJsonResponse = $formatter_void->toJson();
                             $voidDetails = $formatter_void->toArray();
                             ##store payment response in payment gateway log table
                             $gateway_request = array('transaction_id' => $transaction_id);
                             $orderHelper->paymentLog($gateway_request, $customer_id, $order_id, 'cancel_order', $gateway_request, $voidDetails);
                             ##end
                             if (isset($voidDetails['transactionId'][0]) && $voidDetails['transactionId'][0] != '') {
                                 $data = array($driver_id, $foodjets_meal_plan_id, $order_number, $customer_id, $coupon_id, $credit, $customer_new_credit);
                                 $todays_driver_list_id = $orderHelper->changeOrderStatus($order_id, $data);
                                 $response['status'] = "1";
                                 $response['msg'] = 'Order cancelled successfully.';
                                 ##send cancel order mail
                                 $this->sendCancelOrderMail($order_id);
                                 ##end
                             } else {
                                 $paymentGatewayResponse = $chargeService->refund($total_amount, "usd", $transaction_id, NULL, $order_id);
                                 $formatter = Formatter::make($paymentGatewayResponse, Formatter::XML);
                                 $formattedResponse = $formatter->toJson();
                                 $transectionDetails = $formatter->toArray();
                                 ##store payment response in payment gateway log table
                                 $gateway_request = array('amount' => $total_amount, 'currency' => 'usd', 'cardData' => $transaction_id, 'order_id' => $order_id);
                                 $orderHelper->paymentLog($gateway_request, $customer_id, $order_id, 'cancel_order', $gateway_request, $transectionDetails);
                                 ##end
                                 if (isset($transectionDetails['transactionId'][0]) && $transectionDetails['transactionId'][0] != '') {
                                     $data = array($driver_id, $foodjets_meal_plan_id, $order_number, $customer_id, $coupon_id, $credit, $customer_new_credit);
                                     $todays_driver_list_id = $orderHelper->changeOrderStatus($order_id, $data);
                                     $response['status'] = "1";
                                     $response['msg'] = 'Order cancelled successfully.';
                                     ##send cancel order mail
                                     $this->sendCancelOrderMail($order_id);
                                     ##end
                                 } else {
                                     $response['status'] = "0";
                                     $response['msg'] = 'Transaction not approved.';
                                 }
                             }
                             // else end
                         } catch (\Exception $e) {
                             Log::error($e);
                             $response['status'] = "0";
                             $msg = (array) $e->getMessage();
                             $response['msg'] = $msg[0];
                         }
                     } else {
                         $response['status'] = "0";
                         $response['msg'] = 'Not a valid amount.';
                     }
                 } catch (\Exception $e) {
                     Log::error($e);
                     $response['status'] = "0";
                     $msg = (array) $e->getMessage();
                     $response['msg'] = $msg[0];
                 }
             } else {
                 list($transaction_id, $order_number, $customer_id, $driver_id, $coupon_id, $market_office_id, $credit, $state_code, $customer_current_credit, $customer_new_credit, $total_amount, $foodjets_meal_plan_id) = $order_data['data'];
                 $order_data = $order_data['order_data'];
                 $data = array($driver_id, $foodjets_meal_plan_id, $order_number, $customer_id, $coupon_id, $credit, $customer_new_credit);
                 $todays_driver_list_id = $orderHelper->changeOrderStatus($order_id, $data);
                 $response['status'] = "1";
                 $response['msg'] = 'Order cancelled successfully.';
                 ##send cancel order mail
                 $this->sendCancelOrderMail($order_id);
                 ##end
             }
             ########################## Remove order from redis starts ###############################
             if ($order_id && isset($order_data->market_office_city_delivery_zone_id)) {
                 $redis = new ApiRedis();
                 $db = $this->redisDb;
                 $redis->cancelOrderFromRedis($order_id, $order_data->market_office_city_delivery_zone_id, $db);
             }
             ##########################  Remove order from redis ends  ###############################
         } else {
             $response['status'] = "0";
             $response['msg'] = "Invalid order id or already cancelled or Order not in processing mode.";
         }
         $orderHelper->apiLog($order_id, $request_time, $response);
     } catch (\Exception $e) {
         Log::error($e);
         $response['status'] = "0";
         $msg = (array) $e->getMessage();
         $response['msg'] = $msg[0];
     }
     return $response;
 }
示例#3
0
 public function assignedState($redisDB, $order_id, $zone_id)
 {
     $redis = new ApiRedis();
     $redis->updateOrderQeueOrderState($order_id, $zone_id, 5, $redisDB);
 }
示例#4
0
 public function getAssignedOrders()
 {
     $input = Input::all();
     $response = array();
     try {
         $response['status'] = "1";
         $response['msg'] = "Success";
         $ApiRedis = new ApiRedis();
         $db = $this->redisDb;
         $orderProcessed = $ApiRedis->getOrderSpliceQueue($input['zone_id'], $db);
         $orderIds = array();
         $orders = array();
         foreach ($orderProcessed['assigned'] as $k => $v) {
             if ($k > 0) {
                 $orderHash = $ApiRedis->getOrderFromHash($k, $db);
                 if (empty($orderHash['address'])) {
                     $orderHash['address'] = "";
                 }
                 $order[$k] = $orderHash;
                 $orderIds[] = $k;
             }
         }
         if (count($orderIds) > 0) {
             $orderData = Order::select("order.id", "order.order_number", "order.market_office_city_delivery_zone_id", "customer.full_name", "driver.first_name", "driver.last_name", "order.customer_delivery_address", DB::raw("driver.id AS driver_id"))->join("customer", "customer.id", "=", "order.customer_id")->leftJoin('driver', 'driver.id', '=', 'order.driver_id')->whereIn("order.id", $orderIds)->get();
             foreach ($orderData as $value) {
                 $order[$value["id"]]["id"] = $value["id"];
                 $order[$value["id"]]["order_number"] = $value["order_number"] != "" ? $value["order_number"] : " ";
                 $order[$value["id"]]["customer_name"] = $value["full_name"] != "" ? $value["full_name"] : " ";
                 if ($value['last_name'] != null || $value['first_name'] != null) {
                     $order[$value["id"]]["driver_name"] = $value["first_name"] . " " . $value["last_name"];
                 } else {
                     $order[$value["id"]]["driver_name"] = "";
                 }
                 $order[$value["id"]]["show_driver"] = true;
                 if ($order[$value["id"]]["address"] == "") {
                     $order[$value["id"]]["address"] = $value['customer_delivery_address'] != "" ? $value['customer_delivery_address'] : " ";
                 }
             }
         }
         $response['orders'] = $order;
     } catch (Exception $e) {
         Log::error($e);
         $response['status'] = '0';
         $msg = (array) $e->getMessage();
         $response['msg'] = $msg[0];
     }
     return Response::json($response);
 }
示例#5
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);
 }