GetKennelDetailWorkCommand.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/11/23
  6. * Time: 9:11
  7. */
  8. class GetKennelDetailWorkCommand extends CConsoleCommand {
  9. public function run($args){
  10. //error_reporting(E_ERROR);
  11. ini_set('memory_limit', '256M');
  12. //ini_set('mongo.long_as_object',1);
  13. set_time_limit(0);
  14. self::getKennel();
  15. }
  16. public function getKennel()
  17. {
  18. $ids = array('26737', '19744', '7264', '24762', '26243', '21163', '25702', '26552', '25352', '20506', '26346', '26733', '13358', '26609', '26810', '11641', '26406',
  19. '25053', '26809', '26770', '26205', '24236', '26539', '24955', '15889', '24187', '12154', '26635', '18058', '24727', '26517', '26536', '21612', '26155', '25251',
  20. '25187', '26722', '23874', '16066', '26289', '26731', '18368', '11105', '14849', '16628', '25181', '26489', '25130', '26427', '26245', '22978', '26492',
  21. '8855', '21275', '5526', '12401', '26317', '17554', '25565', '26280', '26530', '26410', '26776', '26412', '10290', '26560', '22937', '26594', '26268', '23248',
  22. '21521', '26240', '26372', '26653', '26261', '20856', '26470', '24999', '26531', '26534', '15783', '26326', '25745', '22007', '26599', '26253', '26545',
  23. '13588', '22358', '26674', '25950', '26474', '22848', '26661', '26555', '26681', '26631', '14496', '26377', '26593', '4113', '26794', '26342', '26696',
  24. '26425', '26759', '26327', '25974', '22718', '26683', '12019', '25849', '25291', '25052', '24803', '26451', '26395', '19333', '14448', '26702', '26348', '26529',
  25. '25296', '26509', '24060', '26633', '17127', '12685', '26475', '24871', '15031', '25241', '26331', '24724', '26394', '26340', '10606', '26757',
  26. '26423', '26026', '23852', '26478', '26133', '19653', '25860', '26668', '26441', '26198', '24083', '26636', '26347', '26226', '26578', '26415', '19249', '24781',
  27. '26535', '25430', '26471', '26351', '26780', '26457', '24927', '26788', '26806', '26646', '24796', '26453', '26484', '26499', '25230', '26416', '25104', '25223', '21627', '26516', '24254',
  28. '23520', '23117', '26357', '26488', '26704', '23685', '26328', '19194', '2145', '26707', '25341', '20746', '59', '4337', '24098', '26726', '10861', '21888',
  29. '24224', '26600', '25090', '15634', '7655', '26504', '26764', '25999', '25967', '26591', '21514', '26184', '19908', '21870', '7927', '26749', '20436', '26361',
  30. '21770', '24730', '22868', '18966', '26246', '26449', '25288', '1850', '2872', '21648', '6740', '26501', '16656', '23552', '26659', '16823', '22362', '23444',
  31. '26565', '24916', '1774', '25263', '23275', '26494', '26306', '26746', '26111', '26665', '26298', '26431', '24395', '19549'
  32. );
  33. $petTypesId = array();
  34. $petTypes = array();
  35. foreach ($ids as $id) {
  36. $url = "http://pet.appcute.im/api/user/get?id=" . $id;
  37. $res = CommonFn::replaceUrl(CommonFn::simple_http($url));
  38. $res = json_decode($res, true);
  39. if ($res['error'] == 10000) {
  40. $value = $res['data'];
  41. $kennel = new Kennel();
  42. $kennel->status = 1;
  43. $kennel->name = $value['nickname'];
  44. if ($value['avatar'] == 'http://pet.appcute.im/bundles/cuteapi/static/no.png') {
  45. $value['avatar'] = 'http://icons.maiyizhi.cn/image_default.png';
  46. }
  47. $kennel->avatar = $value['avatar'];
  48. $kennel->join_time = time();
  49. $kennel->type = 2;
  50. $kennel->address = $value['contact']['address'];
  51. $kennel->desc = $value['desc'];
  52. $kennel->phone = $value['contact']['mobile'];
  53. $kennel->from = 'chongwushichang';
  54. $kennel->save();
  55. $petUrl = "http://pet.appcute.im/api/user/pets?id=".$id."&limit=500&offset=0";
  56. $res_pets = CommonFn::replaceUrl(CommonFn::simple_http($petUrl));
  57. $res_pets = json_decode($res_pets, true);
  58. //获取商家宠物 信息
  59. if ($res_pets['error'] == 10000) {
  60. $tmps = $res_pets['data']['values'];
  61. foreach ($tmps as $key=> $tmp) {
  62. $dealPet = new DealPet();
  63. if(in_array($tmp['cat']['id'],$petTypesId)) {
  64. $pet_type = PetTypes::model()->get(new MongoId($petTypes[$tmp['cat']['id']]));
  65. } else {
  66. $petTypesId[] = $tmp['cat']['id'];
  67. $pet_type = new PetTypes();
  68. $pet_type->name = $tmp['cat']['name'];
  69. if ($tmp['cat']['type'] == 1 ){//猫
  70. $pet_type->parent = new MongoId("546805e40eb9fb32018b45fe");
  71. } else if($tmp['cat']['type'] == 2 ){//狗
  72. $pet_type->parent = new MongoId("54671c4b0eb9fb89048b45f5");
  73. } else {
  74. $pet_type->parent = new MongoId("56a88c7ba84ea0e0478d6d2b");
  75. }
  76. $pet_type->pic = $tmp['cat']['pic'];
  77. $pet_type->level = 2;
  78. $pet_type->save();
  79. $petTypes[$tmp['cat']['id']] = (string)$pet_type->_id;
  80. }
  81. $dealPet->pet_type = new MongoId($pet_type->_id);
  82. $dealPet->name = $tmp['name'];
  83. $dealPet->status = 1;
  84. $dealPet->price = $tmp['price'];
  85. $dealPet->pics = array();
  86. foreach ($tmp['photos'] as $key =>$v) {
  87. $pic = array();
  88. $size = CommonFn::getPicSize($v);
  89. if (isset($size['width']) && isset($size['height'])) {
  90. $pic['width'] = intval($size['width']);
  91. $pic['height'] = intval($size['height']);
  92. }
  93. $pic['url'] = $v;
  94. $dealPet->pics[] = (object)$pic;
  95. }
  96. $dealPet->kennel = $kennel->_id;
  97. //$dealPet->pet_type = new MongoId($tmp['pet_type']);
  98. $dealPet->birth_date = intval($tmp['birthday']);
  99. $dealPet->gender = $tmp['sex'];
  100. /*$dealPet->tags = array();
  101. foreach ($tmp['tags'] as $v){
  102. $dealPet->tags[] = $v;
  103. }*/
  104. $father_info = array();
  105. $mother_info = array();
  106. if (isset($tmp['extra']['parents'][0]['pic']))
  107. $father_info['avatar'] = $tmp['extra']['parents'][0]['pic'];
  108. if (isset($tmp['extra']['parents'][1]['pic']))
  109. $mother_info['avatar'] = $tmp['extra']['parents'][1]['pic'];
  110. $dealPet->father_info = (object)$father_info;
  111. var_dump($dealPet->father_info);exit;
  112. $dealPet->mother_info = (object)$mother_info;
  113. $dealPet->desc = $tmp['desc'];
  114. $dealPet->vaccine_info = array();
  115. if (isset($tmp['extra'])){
  116. foreach ($tmp['extra']['vaccined'] as $v) {
  117. $datetime = date_create($v['date'])->format('U');
  118. $vaccine_info['time'] = intval($datetime);
  119. $vaccine_info['brand'] = $v['value'];
  120. $dealPet->vaccine_info[] = (object)$vaccine_info;
  121. }
  122. }
  123. $dealPet->add_time = time();
  124. //$dealPet->sort_weight = $tmp['sort_weight'];
  125. //$dealPet->delivery_time = $tmp['delivery_time'];
  126. //$dealPet->delivery_date = $tmp['delivery_date'];
  127. $tmp['deworming_info'] = array();
  128. if (!empty($tmp['parasited'])) {
  129. $tmp['deworming_info']['brand'] = $tmp['parasited']['value'];
  130. ;
  131. $tmp['deworming_info']['time'] = intval(date_create($tmp['parasited']['date'])->format('U'));
  132. }
  133. $dealPet->deworming_info = array();
  134. $dealPet->deworming_info[] = (Object)$tmp['deworming_info'];
  135. if (isset($value['videos']['length'])) {
  136. $value['video']['length'] = floatval($value['video']['length']);
  137. }
  138. $dealPet->video = (Object)$tmp['videos'];
  139. //$dealPet->carriage = (Object)$tmp['carriage'];
  140. //$dealPet->last_modify = $tmp['last_modify'];
  141. //$dealPet->view_count = $tmp['view_count'];
  142. //$dealPet->contact_count = $tmp['contact_count'];
  143. if ( $tmp['lat'] != 0 && $tmp['lng'] != 0){
  144. $position = CommonFn::GCJTobaidu($tmp['lat'], $tmp['lng']);
  145. $location = $position['lat'] . ',' . $position['lng'];
  146. $res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&location=' . $location . '&output=json&pois=0');
  147. $info = json_decode($res);
  148. $cityinfo = array();
  149. if ($info || $info->status == 0) {
  150. $info = $info->result->addressComponent;
  151. if (!empty($info->province) && !empty($info->city)) {
  152. $cityinfo['province'] = $info->province;
  153. $cityinfo['city'] = $info->city;
  154. $cityinfo['area'] = $info->district;
  155. }
  156. }
  157. }else {
  158. $cityinfo['province'] = '';
  159. $cityinfo['city'] = '';
  160. $cityinfo['area'] = '';
  161. }
  162. $tmp['region']['province'] = $cityinfo['province'];
  163. $tmp['region']['city'] = $cityinfo['city'];
  164. $tmp['region']['area'] = $cityinfo['area'];
  165. $dealPet->region = (Object)$tmp['region'];
  166. //$dealPet->last_deny_reason = $tmp['last_deny_reason'];
  167. $dealPet->from = 'chongwushichang';
  168. $dealPet->save();
  169. sleep(1);
  170. }
  171. }
  172. sleep(1);
  173. }
  174. }
  175. }
  176. }