public static function saveDistrictCityFromLatLng($lat, $lng, $accId, $isCashier)
 {
     $lat = trim($lat);
     $lng = trim($lng);
     if (self::IsNullOrEmptyString($lat) || self::IsNullOrEmptyString($lng)) {
         return;
     }
     $url = "https://maps.googleapis.com/maps/api/geocode/json?latlng={$lat},{$lng}&result_type=administrative_area_level_3&key=" . self::$geoCodingServerKey;
     $json = json_decode(file_get_contents($url), true);
     $addressComponents = $json['results'][0]['address_components'];
     if (count($addressComponents) < 2) {
         return;
     }
     $district = strtoupper($addressComponents[0]['long_name']);
     $city = strtoupper($addressComponents[1]['long_name']);
     $loc = new LocationModel();
     $arrLoc = $loc->getWhere("district='{$district}' AND city='{$city}'");
     if (count($arrLoc) == 0) {
         $l = new LocationModel();
         $l->district = $district;
         $l->city = $city;
         if ($isCashier) {
             $l->cashier_visit_count = 1;
             $l->user_visit_count = 0;
         } else {
             $l->cashier_visit_count = 0;
             $l->user_visit_count = 1;
         }
         $l->visit_count = 1;
         $l->save();
     } else {
         $l = new LocationModel();
         $l->getByID($arrLoc[0]->id_location);
         if ($isCashier) {
             $l->cashier_visit_count = $l->cashier_visit_count + 1;
         } else {
             $l->user_visit_count = $l->user_visit_count + 1;
         }
         $l->save();
     }
     if ($accId != 0 && !$isCashier) {
         $user = new UserModel();
         $user->getByID($accId);
         $user->last_lat = $lat;
         $user->last_long = $lng;
         $user->last_city = $city;
         $user->last_district = $district;
         if (Generic::IsNullOrEmptyString($user->latitude)) {
             $user->latitude = $lat;
         }
         if (Generic::IsNullOrEmptyString($user->longitude)) {
             $user->longitude = $lng;
         }
         if (Generic::IsNullOrEmptyString($user->district)) {
             $user->district = $district;
         }
         if (Generic::IsNullOrEmptyString($user->city)) {
             $user->city = $city;
         }
         $user->save();
     }
 }