status = 1; $kennel->name = $value['nickname']; if ($value['avatar'] == 'http://pet.appcute.im/bundles/cuteapi/static/no.png') { $value['avatar'] = 'http://icons.maiyizhi.cn/image_default.png'; } $kennel->avatar = $value['avatar']; $kennel->join_time = time(); $kennel->type = 2; $kennel->address = $value['contact']['address']; $kennel->desc = $value['desc']; $kennel->phone = $value['contact']['mobile']; $kennel->from = 'chongwushichang'; $kennel->save(); $petUrl = "http://pet.appcute.im/api/user/pets?id=".$id."&limit=500&offset=0"; $res_pets = CommonFn::replaceUrl(CommonFn::simple_http($petUrl)); $res_pets = json_decode($res_pets, true); //获取商家宠物 信息 if ($res_pets['error'] == 10000) { $tmps = $res_pets['data']['values']; foreach ($tmps as $key=> $tmp) { $dealPet = new DealPet(); if(in_array($tmp['cat']['id'],$petTypesId)) { $pet_type = PetTypes::model()->get(new MongoId($petTypes[$tmp['cat']['id']])); } else { $petTypesId[] = $tmp['cat']['id']; $pet_type = new PetTypes(); $pet_type->name = $tmp['cat']['name']; if ($tmp['cat']['type'] == 1 ){//猫 $pet_type->parent = new MongoId("546805e40eb9fb32018b45fe"); } else if($tmp['cat']['type'] == 2 ){//狗 $pet_type->parent = new MongoId("54671c4b0eb9fb89048b45f5"); } else { $pet_type->parent = new MongoId("56a88c7ba84ea0e0478d6d2b"); } $pet_type->pic = $tmp['cat']['pic']; $pet_type->level = 2; $pet_type->save(); $petTypes[$tmp['cat']['id']] = (string)$pet_type->_id; } $dealPet->pet_type = new MongoId($pet_type->_id); $dealPet->name = $tmp['name']; $dealPet->status = 1; $dealPet->price = $tmp['price']; $dealPet->pics = array(); foreach ($tmp['photos'] as $key =>$v) { $pic = array(); $size = CommonFn::getPicSize($v); if (isset($size['width']) && isset($size['height'])) { $pic['width'] = intval($size['width']); $pic['height'] = intval($size['height']); } $pic['url'] = $v; $dealPet->pics[] = (object)$pic; } $dealPet->kennel = $kennel->_id; //$dealPet->pet_type = new MongoId($tmp['pet_type']); $dealPet->birth_date = intval($tmp['birthday']); $dealPet->gender = $tmp['sex']; /*$dealPet->tags = array(); foreach ($tmp['tags'] as $v){ $dealPet->tags[] = $v; }*/ $father_info = array(); $mother_info = array(); if (isset($tmp['extra']['parents'][0]['pic'])) $father_info['avatar'] = $tmp['extra']['parents'][0]['pic']; if (isset($tmp['extra']['parents'][1]['pic'])) $mother_info['avatar'] = $tmp['extra']['parents'][1]['pic']; $dealPet->father_info = (object)$father_info; var_dump($dealPet->father_info);exit; $dealPet->mother_info = (object)$mother_info; $dealPet->desc = $tmp['desc']; $dealPet->vaccine_info = array(); if (isset($tmp['extra'])){ foreach ($tmp['extra']['vaccined'] as $v) { $datetime = date_create($v['date'])->format('U'); $vaccine_info['time'] = intval($datetime); $vaccine_info['brand'] = $v['value']; $dealPet->vaccine_info[] = (object)$vaccine_info; } } $dealPet->add_time = time(); //$dealPet->sort_weight = $tmp['sort_weight']; //$dealPet->delivery_time = $tmp['delivery_time']; //$dealPet->delivery_date = $tmp['delivery_date']; $tmp['deworming_info'] = array(); if (!empty($tmp['parasited'])) { $tmp['deworming_info']['brand'] = $tmp['parasited']['value']; ; $tmp['deworming_info']['time'] = intval(date_create($tmp['parasited']['date'])->format('U')); } $dealPet->deworming_info = array(); $dealPet->deworming_info[] = (Object)$tmp['deworming_info']; if (isset($value['videos']['length'])) { $value['video']['length'] = floatval($value['video']['length']); } $dealPet->video = (Object)$tmp['videos']; //$dealPet->carriage = (Object)$tmp['carriage']; //$dealPet->last_modify = $tmp['last_modify']; //$dealPet->view_count = $tmp['view_count']; //$dealPet->contact_count = $tmp['contact_count']; if ( $tmp['lat'] != 0 && $tmp['lng'] != 0){ $position = CommonFn::GCJTobaidu($tmp['lat'], $tmp['lng']); $location = $position['lat'] . ',' . $position['lng']; $res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&location=' . $location . '&output=json&pois=0'); $info = json_decode($res); $cityinfo = array(); if ($info || $info->status == 0) { $info = $info->result->addressComponent; if (!empty($info->province) && !empty($info->city)) { $cityinfo['province'] = $info->province; $cityinfo['city'] = $info->city; $cityinfo['area'] = $info->district; } } }else { $cityinfo['province'] = ''; $cityinfo['city'] = ''; $cityinfo['area'] = ''; } $tmp['region']['province'] = $cityinfo['province']; $tmp['region']['city'] = $cityinfo['city']; $tmp['region']['area'] = $cityinfo['area']; $dealPet->region = (Object)$tmp['region']; //$dealPet->last_deny_reason = $tmp['last_deny_reason']; $dealPet->from = 'chongwushichang'; $dealPet->save(); sleep(1); } } sleep(1); } } } }