123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Created by PhpStorm.
- * User: PHP
- * Date: 2016/11/23
- * Time: 9:11
- */
- class GetPetWorkCommand extends CConsoleCommand
- {
- public function run($args)
- {
- error_reporting(E_ERROR);
- ini_set('memory_limit', '256M');
- //ini_set('mongo.long_as_object',1);
- set_time_limit(0);
- self::getPet();
- }
- public function getPet()
- {
- $kennels = new Kennel();
- $cursor = $kennels->findAll();
- foreach ($cursor as $kennel) {
- $resources = CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/list?user_id=546b16f50eb9fb494f8b4664&page=1&rows=2000&kennel=" . $kennel['_id']);
- $resources = json_decode($resources, true);
- if (!empty($resources['data']['list'])) {
- $petsList = $resources['data']['list'];
- foreach ($petsList as $k => $pet) {
- //获取pet详情
- $tmp = json_decode(CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/info?user_id=546b16f50eb9fb494f8b4664&pet_id=" . $pet['id']), true);
- $tmp = $tmp['data'];
- if (!empty($tmp)) {
- if (!empty(DealPet::model()->get(new MongoId($tmp['id'])))) {
- $dealPet = DealPet::model()->get(new MongoId($tmp['id']));
- } else {
- $dealPet = new DealPet();
- }
- $dealPet->_id = new MongoId($tmp['id']);
- $dealPet->is_one_pay = 0;
- $dealPet->name = $tmp['name'];
- $dealPet->status = $tmp['status'];
- $dealPet->price = $tmp['price'];
- foreach ($tmp['pics'] as $key => $v) {
- if (!empty($v['url'])){
- $v['url'] = self::getVaildDataPost($v['url']);
- }
- $dealPet->pics[$key] = $v;
- }
- $dealPet->root_parent = new MongoId($tmp['root_praent']);
- $dealPet->kennel = new MongoId($tmp['kennel']);
- $dealPet->pet_type = new MongoId($tmp['pet_type']);
- $dealPet->birth_date = intval($tmp['birth_date']);
- $dealPet->gender = $tmp['gender'];
- foreach ($tmp['tags'] as $key => $v)
- $dealPet->tags[$key] = $v;
- $tmp['father_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);
- var_dump($tmp['father_info']['avatar']);exit;
- $dealPet->father_info = (Object)$tmp['father_info'];
- $tmp['mather_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);;
- $dealPet->mother_info = (Object)$tmp['mother_info'];
- $dealPet->desc = $tmp['desc'];
- foreach ($tmp['vaccine_info'] as $key => $v)
- $dealPet->vaccine_info[$key] = $v;
- $dealPet->add_time = time();
- //$dealPet->sort_weight = $tmp['sort_weight'];
- $dealPet->delivery_time = $tmp['delivery_time'];
- $dealPet->delivery_date = $tmp['delivery_date'];
- //这里改成数组
- $dealPet->deworming_info = (Object)$tmp['deworming_info'];
- $dealPet->hair_color = $tmp['hair_color'];
- $video = array();
- foreach($tmp['video'] as $key => $v){
- if ($key == 'url'){
- $v = self::getVaildDataPost($v);
- }
- $video[$key] = $v;
- }
- $dealPet->video = (Object)$video;
- $dealPet->carriage = (Object)$tmp['carriage'];
- //$dealPet->last_modify = $tmp['last_modify'];
- //$dealPet->view_count = $tmp['view_count'];
- //$dealPet->contact_count = $tmp['contact_count'];
- $dealPet->region = (Object)$tmp['region'];
- //$dealPet->last_deny_reason = $tmp['last_deny_reason'];
- $dealPet->from = 'wozhua';
- $dealPet->save();
- sleep(3);
- }
- }
- sleep(3);
- }
- }
- }
- public function getVaildDataPost($url){
- $tmp[] = str_replace(parse_url($url)['host'],'pics.maiyizhi.cn',$url);
- $tmp[] = str_replace(parse_url($url)['host'],'avatars.maiyizhi.cn',$url);
- $tmp[] = str_replace(parse_url($url)['host'],'test.maiyizhi.cn',$url);
- $tmp[] = str_replace(parse_url($url)['host'],'icons.maiyizhi.cn',$url);
- foreach ($tmp as $value){
- if (empty(json_decode(CommonFn::simple_http($value),true)['error'])){
- $url = $value;break;
- }
- }
- return $url;
- }
- }
|