GetKennelDetailWorkCommand.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. var_dump($id);
  37. $url = "http://pet.appcute.im/api/user/get?id=" . $id;
  38. $res = CommonFn::replaceUrl(CommonFn::simple_http($url));
  39. $res = json_decode($res, true);
  40. if ($res['error'] == 10000) {
  41. $value = $res['data'];
  42. $kennel = new Kennel();
  43. $kennel->status = 1;
  44. $kennel->name = $value['nickname'];
  45. if ($value['avatar'] == 'http://pet.appcute.im/bundles/cuteapi/static/no.png') {
  46. $value['avatar'] = 'http://icons.maiyizhi.cn/image_default.png';
  47. }
  48. $kennel->avatar = $value['avatar'];
  49. $kennel->join_time = time();
  50. $kennel->type = 2;
  51. $kennel->address = $value['contact']['address'];
  52. $kennel->desc = $value['desc'];
  53. $kennel->phone = $value['contact']['mobile'];
  54. $kennel->from = 'chongwushichang';
  55. $kennel->save();
  56. $petUrl = "http://pet.appcute.im/api/user/pets?id=".$id."&limit=500&offset=0";
  57. $res_pets = CommonFn::replaceUrl(CommonFn::simple_http($petUrl));
  58. $res_pets = json_decode($res_pets, true);
  59. //获取商家宠物 信息
  60. if ($res_pets['error'] == 10000) {
  61. $tmps = $res_pets['data']['values'];
  62. foreach ($tmps as $key=> $tmp) {
  63. $dealPet = new DealPet();
  64. if(in_array($tmp['cat']['id'],$petTypesId)) {
  65. var_dump($petTypes[$tmp['cat']['id']]);
  66. $pet_type = PetTypes::model()->get(new MongoId($petTypes[$tmp['cat']['id']]));
  67. var_dump($pet_type);
  68. exit;
  69. } else {
  70. $petTypesId[] = $tmp['cat']['id'];
  71. $pet_type = new PetTypes();
  72. $pet_type->name = $tmp['cat']['name'];
  73. if ($tmp['cat']['type'] == 1 ){//猫
  74. $pet_type->parent = new MongoId("546805e40eb9fb32018b45fe");
  75. } else if($tmp['cat']['type'] == 2 ){//狗
  76. $pet_type->parent = new MongoId("54671c4b0eb9fb89048b45f5");
  77. } else {
  78. $pet_type->parent = new MongoId("56a88c7ba84ea0e0478d6d2b");
  79. }
  80. $pet_type->pic = $tmp['cat']['pic'];
  81. $pet_type->level = 2;
  82. $pet_type->save();
  83. $petTypes[$tmp['cat']['id']] = (string)$pet_type->_id;
  84. }
  85. $dealPet->pet_type = new MongoId($pet_type->_id);
  86. $dealPet->name = $tmp['name'];
  87. //$dealPet->status = $tmp['status'];
  88. $dealPet->price = $tmp['price'];
  89. $dealPet->pics = array();
  90. foreach ($tmp['photos'] as $v) {
  91. $size = CommonFn::getPicSize($v);
  92. if (isset($size['width']) && isset($size['height'])) {
  93. $dealPet->pics['width'] = intval($size['width']);
  94. $dealPet->pics['height'] = intval($size['height']);
  95. }
  96. $dealPet->pics['url'] = $v;
  97. }
  98. $dealPet->kennel = $kennel->_id;
  99. //$dealPet->pet_type = new MongoId($tmp['pet_type']);
  100. $dealPet->birth_date = intval($tmp['birthday']);
  101. $dealPet->gender = $tmp['sex'];
  102. /*$dealPet->tags = array();
  103. foreach ($tmp['tags'] as $v){
  104. $dealPet->tags[] = $v;
  105. }*/
  106. $tmp['father_info'] = array();
  107. $tmp['mother_info'] = array();
  108. if (isset($tmp['extra']['parents'][0]['pic']))
  109. $tmp['father_info']['avatar'] = $tmp['extra']['parents'][0]['pic'];
  110. if (isset($tmp['extra']['parents'][1]['pic']))
  111. $tmp['mother_info']['avatar'] = $tmp['extra']['parents'][1]['pic'];
  112. $dealPet->father_info = (Object)$tmp['father_info'];
  113. $dealPet->mother_info = (Object)$tmp['mother_info'];
  114. $dealPet->desc = $tmp['desc'];
  115. $dealPet->vaccine_info = array();
  116. if (isset($tmp['extra'])){
  117. foreach ($tmp['extra']['vaccined'] as $v) {
  118. $datetime = date_create($v['date'])->format('U');
  119. $dealPet->vaccine_info['time'] = intval($datetime);
  120. $dealPet->vaccine_info['brand'] = $v['value'];
  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. $_deworming_info = (Object)$tmp['deworming_info'];
  134. $dealPet->deworming_info = array();
  135. $dealPet->deworming_info[] = $_deworming_info;
  136. if (isset($value['videos']['length'])) {
  137. $value['video']['length'] = floatval($value['video']['length']);
  138. }
  139. $dealPet->video = (Object)$tmp['videos'];
  140. //$dealPet->carriage = (Object)$tmp['carriage'];
  141. //$dealPet->last_modify = $tmp['last_modify'];
  142. //$dealPet->view_count = $tmp['view_count'];
  143. //$dealPet->contact_count = $tmp['contact_count'];
  144. if ( $tmp['lat'] != 0 && $tmp['lng'] != 0){
  145. $position = CommonFn::GCJTobaidu($tmp['lat'], $tmp['lng']);
  146. $location = $position['lat'] . ',' . $position['lng'];
  147. $res = CommonFn::simple_http('http://api.map.baidu.com/geocoder/v2/?ak=B349f0b32ef6e78b2e678f45cb9fddaf&location=' . $location . '&output=json&pois=0');
  148. $info = json_decode($res);
  149. $cityinfo = array();
  150. if ($info || $info->status == 0) {
  151. $info = $info->result->addressComponent;
  152. if (!empty($info->province) && !empty($info->city)) {
  153. $cityinfo['province'] = $info->province;
  154. $cityinfo['city'] = $info->city;
  155. $cityinfo['area'] = $info->district;
  156. }
  157. }
  158. }else {
  159. $cityinfo['province'] = '';
  160. $cityinfo['city'] = '';
  161. $cityinfo['area'] = '';
  162. }
  163. $tmp['region']['province'] = $cityinfo['province'];
  164. $tmp['region']['city'] = $cityinfo['city'];
  165. $tmp['region']['area'] = $cityinfo['area'];
  166. $dealPet->region = (Object)$tmp['region'];
  167. //$dealPet->last_deny_reason = $tmp['last_deny_reason'];
  168. $dealPet->from = 'chongwushichang';
  169. $dealPet->save();
  170. sleep(1);
  171. }
  172. }
  173. sleep(1);
  174. }
  175. }
  176. }
  177. }