Exemplo n.º 1
0
 private function _getRowData($row)
 {
     $cityName = trim(keepOnlyChineseWord(array_get($row, 0)));
     $stateName = trim(keepOnlyChineseWord(array_get($row, 1)));
     $city = City::findByName($cityName)->first();
     $state = NULL !== $city ? State::findByName($stateName)->first() : NULL;
     $zipcode = NULL !== $state ? $state->zipcode : '';
     return '' !== $zipcode ? [$cityName, $stateName, $zipcode] : [array_get($row, 0), array_get($row, 1), ''];
 }
Exemplo n.º 2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function showHotel($hotelId)
 {
     $photoList = [];
     $facilities = [];
     $hotelInfo = Model\Hotel_master::where('id', '=', $hotelId)->first();
     $city = Model\City::where('id', '=', $hotelInfo->city)->first()->name;
     $province = Model\province::where('id', '=', $hotelInfo->province)->first()->name;
     //获得酒店图片路径
     $destinationPath = 'uploads/image/hotel/' . $hotelId . '/';
     if (is_dir($destinationPath)) {
         if ($dh = opendir($destinationPath)) {
             while (($file = readdir($dh)) !== false) {
                 if ($file != '.' && $file != '..') {
                     $photoList[] = '/uploads/image/hotel/' . $hotelId . '/' . $file;
                 }
             }
             closedir($dh);
         }
     }
     //获得酒店的设施清单
     if (sizeof($hotelInfo) != 0) {
         $facList = array_filter(explode(' ', $hotelInfo->hotel_facility_list));
         $hoteFacility = Model\Hotel_Facility::all();
         $facIds = [];
         $tmpFacIds = [];
         $facSubIds = array();
         $facIndex = 0;
         $tmpIndex = '0';
         for ($i = 0; $i < sizeof($facList); $i++) {
             $ids = explode('_', $facList[$i]);
             if ($tmpIndex != $ids[0]) {
                 $facIds[$ids[0]] = ['id' => $ids[0]];
                 $tmpFacIds[] = $ids[0];
                 $tmpIndex = $ids[0];
                 $facIndex++;
                 $facSubIds = array();
             }
             $facSubIds[] = $ids[1];
             $facIds[$ids[0]]['subIds'] = $facSubIds;
         }
         for ($i = 0; $i < sizeof($hoteFacility); $i++) {
             if (in_array($hoteFacility[$i]->id, $tmpFacIds)) {
                 $hotelFacilitySub = Model\Hotel_Facility_Sub::where('facility_id', '=', $hoteFacility[$i]->id)->whereIn('id', array_values($facIds[$hoteFacility[$i]->id]['subIds']))->get();
                 //                  $pointsInfo =[ 'points' =>$points->points,'score'=>$points->score];
                 //
                 $obj = ['id' => $hoteFacility[$i]->id, 'name' => $hoteFacility[$i]->name, 'sub' => $hotelFacilitySub];
                 $facilities[] = $obj;
             }
         }
     }
     $hotel = ['hotelInfo' => $hotelInfo, 'hotelPhoto' => $photoList, 'hotelFacilities' => $facilities, 'city' => $city, 'province' => $province];
     return view('hotel.show', compact('hotel'));
 }
 /**
  * 内容资源列表数据
  */
 public function index()
 {
     //$city = $this->city->all();
     $city = City::with('childrenCities')->get();
     $cities = $city->each(function ($c) {
         if ($c->pid == 0) {
             $c->pname = "顶级城市";
         } else {
             $p_name = $this->city->findOrFail($c->pid)->name;
             /* $s_ = '----';
                $c->name = $s_.$c->name;*/
             $c->pname = $p_name;
         }
     });
     return $cities;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $delimiter = ',';
     $csvFile = public_path() . '/gtd_70to91_0615dist.csv';
     if (($handle = fopen($csvFile, 'r')) !== FALSE) {
         $i = 0;
         while (($row = fgetcsv($handle, 8192, $delimiter)) !== FALSE) {
             if ($i != 0) {
                 /* Creating the where entry */
                 $when = new When();
                 $when->year = $row[1];
                 $when->month = $row[2];
                 $when->day = $row[3];
                 $when->approxdate = $row[4];
                 $when->extended = $row[5];
                 $when->resolution = $row[6];
                 $when->save();
                 /* Check if Countyr, provstate and city exist.
                  * If no, creating them */
                 $country = Country::where('txt', $row[8])->first();
                 if ($country == null) {
                     $country = new Country();
                     $country->txt = $row[8];
                     $country->save();
                 }
                 $provstate = Provstate::where('txt', $row[11])->first();
                 if ($provstate == null) {
                     $provstate = new Provstate();
                     $provstate->txt = $row[11];
                     $provstate->save();
                 }
                 $city = City::where('txt', $row[12])->first();
                 if ($city == null) {
                     $city = new City();
                     $city->txt = $row[12];
                     $city->save();
                 }
                 /* Creating the where entry */
                 $where = new Where();
                 $where->country_id = $country->id;
                 $where->provstate_id = $provstate->id;
                 $where->city_id = $city->id;
                 $where->latitude = $row[13];
                 $where->longitude = $row[14];
                 $where->specificity_id = $row[15];
                 $where->vicinity = $row[16];
                 $where->txt = $row[17];
                 $where->save();
                 /* Creating the what entry */
                 $what = new What();
                 $what->crit1 = $row[19];
                 $what->crit2 = $row[20];
                 $what->crit3 = $row[21];
                 $what->success = $row[26];
                 $what->suicide = $row[27];
                 $what->attacktype1 = $row[28];
                 $what->attacktype2 = $row[30];
                 $what->attacktype3 = $row[32];
                 $what->save();
                 /* Creating the target entry */
                 $target = new Target();
                 $target->targettype1 = $row[34];
                 $target->targetsubtype1 = $row[36];
                 $target->corp1 = $row[38];
                 $target->target1 = $row[39];
                 $target->natlty1 = $row[40];
                 $target->targettype2 = $row[42];
                 $target->targetsubtype2 = $row[44];
                 $target->corp2 = $row[46];
                 $target->target2 = $row[47];
                 $target->natlty2 = $row[48];
                 $target->targettype3 = $row[50];
                 $target->targetsubtype3 = $row[52];
                 $target->corp3 = $row[54];
                 $target->target3 = $row[55];
                 $target->natlty3 = $row[56];
                 $target->save();
                 /* Check if perpetrator groups and sub groups exist.
                  * If no, creating them */
                 $perpetrator_group1 = PerpetratorGroup::where('txt', $row[58])->first();
                 if ($perpetrator_group1 == null) {
                     $perpetrator_group1 = new PerpetratorGroup();
                     $perpetrator_group1->txt = $row[58];
                     $perpetrator_group1->save();
                 }
                 $perpetrator_sub_group1 = PerpetratorSubGroup::where('txt', $row[59])->first();
                 if ($perpetrator_sub_group1 == null) {
                     $perpetrator_sub_group1 = new PerpetratorSubGroup();
                     $perpetrator_sub_group1->txt = $row[59];
                     $perpetrator_sub_group1->save();
                 }
                 $perpetrator_group2 = PerpetratorGroup::where('txt', $row[60])->first();
                 if ($perpetrator_group2 == null) {
                     $perpetrator_group2 = new PerpetratorGroup();
                     $perpetrator_group2->txt = $row[60];
                     $perpetrator_group2->save();
                 }
                 $perpetrator_sub_group2 = PerpetratorSubGroup::where('txt', $row[61])->first();
                 if ($perpetrator_sub_group2 == null) {
                     $perpetrator_sub_group2 = new PerpetratorSubGroup();
                     $perpetrator_sub_group2->txt = $row[61];
                     $perpetrator_sub_group2->save();
                 }
                 $perpetrator_group3 = PerpetratorGroup::where('txt', $row[62])->first();
                 if ($perpetrator_group3 == null) {
                     $perpetrator_group3 = new PerpetratorGroup();
                     $perpetrator_group3->txt = $row[62];
                     $perpetrator_group3->save();
                 }
                 $perpetrator_sub_group3 = PerpetratorSubGroup::where('txt', $row[63])->first();
                 if ($perpetrator_sub_group3 == null) {
                     $perpetrator_sub_group3 = new PerpetratorSubGroup();
                     $perpetrator_sub_group3->txt = $row[63];
                     $perpetrator_sub_group3->save();
                 }
                 /* Creating the who entry */
                 $who = new Who();
                 $who->perpetrator_group1 = $perpetrator_group1->id;
                 $who->perpetrator_sub_group1 = $perpetrator_sub_group1->id;
                 $who->perpetrator_group2 = $perpetrator_group2->id;
                 $who->perpetrator_sub_group2 = $perpetrator_sub_group2->id;
                 $who->perpetrator_group3 = $perpetrator_group3->id;
                 $who->perpetrator_sub_group3 = $perpetrator_sub_group3->id;
                 $who->motive = $row[64];
                 $who->perpetrator_1confirmed = $row[65];
                 $who->perpetrator_2confirmed = $row[66];
                 $who->perpetrator_3confirmed = $row[67];
                 $who->nperps = $row[68];
                 $who->nperpscap = $row[69];
                 $who->claimed1 = $row[70];
                 $who->claimed_mode1 = $row[71];
                 $who->claimed2 = $row[73];
                 $who->claimed_mode2 = $row[74];
                 $who->claimed3 = $row[76];
                 $who->claimed_mode3 = $row[77];
                 $who->compclaim = $row[79];
                 $who->save();
                 /* Creating the how entry */
                 $how = new How();
                 $how->weaptype1 = $row[80];
                 $how->weapsubtype1 = $row[82];
                 $how->weaptype2 = $row[84];
                 $how->weapsubtype2 = $row[86];
                 $how->weaptype3 = $row[88];
                 $how->weapsubtype3 = $row[90];
                 $how->weaptype4 = $row[92];
                 $how->weapsubtype4 = $row[94];
                 $how->weapdetail = $row[96];
                 $how->save();
                 /* Creating the victim entry */
                 $victims = new Victims();
                 $victims->total_killed = $row[97];
                 $victims->us_killed = $row[98];
                 $victims->perpetrators_killed = $row[99];
                 $victims->total_injured = $row[100];
                 $victims->us_injured = $row[101];
                 $victims->perpetrators_injured = $row[102];
                 $victims->property_damage = $row[103];
                 $victims->property_damage_id = $row[104];
                 $victims->property_value = $row[106];
                 $victims->property_comment = $row[107];
                 $victims->hostages_kidnapping = $row[108];
                 $victims->hostages_kidnapping_victims = $row[109];
                 $victims->us_hostages_kidnapping_victims = $row[110];
                 $victims->hours_of_kidnapping = $row[111];
                 $victims->days_of_kidnapping = $row[112];
                 $victims->divert = $row[113];
                 $victims->kidhijcountry = $row[114];
                 $victims->ransom_demanded = $row[115];
                 $victims->ransom_amount = $row[116];
                 $victims->ransom_us_amount = $row[117];
                 $victims->ransom_paied = $row[118];
                 $victims->ransom_us_paied = $row[119];
                 $victims->ransom_note = $row[120];
                 $victims->kidnapping_hostage_outcome = $row[121];
                 $victims->nb_released = $row[122];
                 $victims->save();
                 /* Creating the event */
                 $event = new Event();
                 $event->where_id = $where->id;
                 $event->when_id = $when->id;
                 $event->what_id = $what->id;
                 $event->who_id = $who->id;
                 $event->how_id = $how->id;
                 $event->target_id = $target->id;
                 $event->victims_id = $victims->id;
                 $event->alternative_id = $row[23];
                 $event->summary = $row[18];
                 $event->multiple = $row[25];
                 $event->related = $row[133];
                 $event->add_informations = $row[124];
                 $event->INT_LOG = $row[129];
                 $event->INT_IDEO = $row[130];
                 $event->INT_MISC = $row[131];
                 $event->INT_ANY = $row[132];
                 $event->source1 = $row[125];
                 $event->source2 = $row[126];
                 $event->source3 = $row[127];
                 $event->db_source = $row[128];
                 $event->doubtter = $row[22];
                 $event->save();
                 /* Updating the event id into the several fields */
                 $where->event_id = $event->id;
                 $where->save();
                 $when->event_id = $event->id;
                 $when->save();
                 $what->event_id = $event->id;
                 $what->save();
                 $who->event_id = $event->id;
                 $who->save();
                 $how->event_id = $event->id;
                 $how->save();
                 $target->event_id = $event->id;
                 $target->save();
                 $victims->event_id = $event->id;
                 $victims->save();
                 dd([$event, $when, $where, $what, $who, $how, $target, $victims]);
             }
             $i++;
         }
         fclose($handle);
     }
     return $data;
 }
 /**
  * 删除内容
  *
  * @param  int $id
  * @param  string $type 内容模型类型
  * @return void
  */
 public function destroy($id)
 {
     $city = $this->city->findOrFail($id);
     $city->delete();
 }
Exemplo n.º 6
0
 public function _guessAddressTypeB($address)
 {
     $city = City::findByName(mb_substr($address, 0, 3, Import::DOC_ENCODE))->first();
     return NULL !== $city ? $this->_findBelongState($city->states, $address) : NULL;
 }
Exemplo n.º 7
0
 public function loadCityProvince()
 {
     $cities = City::all()->toArray();
     $provinces = Province::all()->toArray();
     return response()->json(array('cities' => $cities, 'provinces' => $provinces));
 }