GetPetWorkCommand.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/11/23
  6. * Time: 9:11
  7. */
  8. class GetPetWorkCommand extends CConsoleCommand
  9. {
  10. public function run($args)
  11. {
  12. error_reporting(E_ERROR);
  13. ini_set('memory_limit', '256M');
  14. //ini_set('mongo.long_as_object',1);
  15. set_time_limit(0);
  16. self::getPet();
  17. }
  18. public function getPet()
  19. {
  20. $kennels = new Kennel();
  21. $cursor = $kennels->findAll();
  22. foreach ($cursor as $kennel) {
  23. $resources = CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/list?user_id=546b16f50eb9fb494f8b4664&page=1&rows=2000&kennel=" . $kennel['_id']);
  24. $resources = json_decode($resources, true);
  25. if (!empty($resources['data']['list'])) {
  26. $petsList = $resources['data']['list'];
  27. foreach ($petsList as $k => $pet) {
  28. //获取pet详情
  29. $tmp = json_decode(CommonFn::simple_http("http://deal.wozhua.mobi/api/pet/info?user_id=546b16f50eb9fb494f8b4664&pet_id=" . $pet['id']), true);
  30. $tmp = $tmp['data'];
  31. if (!empty($tmp)) {
  32. if (!empty(DealPet::model()->get(new MongoId($tmp['id'])))) {
  33. $dealPet = DealPet::model()->get(new MongoId($tmp['id']));
  34. } else {
  35. $dealPet = new DealPet();
  36. }
  37. $dealPet->_id = new MongoId($tmp['id']);
  38. $dealPet->is_one_pay = 0;
  39. $dealPet->name = $tmp['name'];
  40. $dealPet->status = $tmp['status'];
  41. $dealPet->price = $tmp['price'];
  42. foreach ($tmp['pics'] as $key => $v) {
  43. if (!empty($v['url'])){
  44. $v['url'] = self::getVaildDataPost($v['url']);
  45. }
  46. $dealPet->pics[$key] = $v;
  47. }
  48. $dealPet->root_parent = new MongoId($tmp['root_praent']);
  49. $dealPet->kennel = new MongoId($tmp['kennel']);
  50. $dealPet->pet_type = new MongoId($tmp['pet_type']);
  51. $dealPet->birth_date = intval($tmp['birth_date']);
  52. $dealPet->gender = $tmp['gender'];
  53. foreach ($tmp['tags'] as $key => $v)
  54. $dealPet->tags[$key] = $v;
  55. $tmp['father_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);
  56. var_dump($tmp['father_info']['avatar']);exit;
  57. $dealPet->father_info = (Object)$tmp['father_info'];
  58. $tmp['mather_info']['avatar'] = self::getVaildDataPost($tmp['father_info']['avatar']);;
  59. $dealPet->mother_info = (Object)$tmp['mother_info'];
  60. $dealPet->desc = $tmp['desc'];
  61. foreach ($tmp['vaccine_info'] as $key => $v)
  62. $dealPet->vaccine_info[$key] = $v;
  63. $dealPet->add_time = time();
  64. //$dealPet->sort_weight = $tmp['sort_weight'];
  65. $dealPet->delivery_time = $tmp['delivery_time'];
  66. $dealPet->delivery_date = $tmp['delivery_date'];
  67. //这里改成数组
  68. $dealPet->deworming_info = (Object)$tmp['deworming_info'];
  69. $dealPet->hair_color = $tmp['hair_color'];
  70. $video = array();
  71. foreach($tmp['video'] as $key => $v){
  72. if ($key == 'url'){
  73. $v = self::getVaildDataPost($v);
  74. }
  75. $video[$key] = $v;
  76. }
  77. $dealPet->video = (Object)$video;
  78. $dealPet->carriage = (Object)$tmp['carriage'];
  79. //$dealPet->last_modify = $tmp['last_modify'];
  80. //$dealPet->view_count = $tmp['view_count'];
  81. //$dealPet->contact_count = $tmp['contact_count'];
  82. $dealPet->region = (Object)$tmp['region'];
  83. //$dealPet->last_deny_reason = $tmp['last_deny_reason'];
  84. $dealPet->from = 'wozhua';
  85. $dealPet->save();
  86. sleep(3);
  87. }
  88. }
  89. sleep(3);
  90. }
  91. }
  92. }
  93. public function getVaildDataPost($url){
  94. $tmp[] = str_replace(parse_url($url)['host'],'pics.maiyizhi.cn',$url);
  95. $tmp[] = str_replace(parse_url($url)['host'],'avatars.maiyizhi.cn',$url);
  96. $tmp[] = str_replace(parse_url($url)['host'],'test.maiyizhi.cn',$url);
  97. $tmp[] = str_replace(parse_url($url)['host'],'icons.maiyizhi.cn',$url);
  98. foreach ($tmp as $value){
  99. if (empty(json_decode(CommonFn::simple_http($value),true)['error'])){
  100. $url = $value;break;
  101. }
  102. }
  103. return $url;
  104. }
  105. }