BookSpider.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use GuzzleHttp\Client;
  5. use DB;
  6. use Redis;
  7. class BookSpider extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'zytest {--type=} {--bid=}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'zytest';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. $this->client = new Client(['timeout' => 8.0,'allow_redirects'=>true]);
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. //32401811
  39. //$this->cpc();
  40. $type = $this->option('type');
  41. if($type == 'yunqi'){
  42. $bids = $this->option('bid');
  43. $bids = explode(',',$bids);
  44. foreach ($bids as $bid){
  45. $this->newYunQi($bid);
  46. }
  47. }
  48. }
  49. public function cleanRedis()
  50. {
  51. //accurateSendOrder
  52. //$result = Redis::scan($flag,['match'=>'wap:string:chapter:{*','count'=>1000]);
  53. $flag = 0;
  54. /*while (true){
  55. list($flag,$list) = Redis::hscan('push:inner_send_order_id:pv',$flag,['match'=>'*','count'=>100]);
  56. $data = [];
  57. if($list){
  58. foreach ($list as $k=>$item){
  59. $uv = Redis::scard('push:inner_send_order_id:uv:' . $k);
  60. $data[] =
  61. ['stats_type'=>'inner_send_order_id',
  62. 'param'=>$k,'pv'=>$item,'uv'=>$uv,
  63. 'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
  64. }
  65. DB::table('wap_long_visit_stats')->insert($data);
  66. }
  67. if(!$flag){
  68. break;
  69. }
  70. }*/
  71. /*while (true){
  72. list($flag,$list) = Redis::scan($flag,['match'=>'accurateSendOrder*','count'=>1000]);
  73. if($list){
  74. foreach ($list as $item){
  75. Redis::del($item);
  76. }
  77. }
  78. if(!$flag){
  79. break;
  80. }
  81. }*/
  82. /*while (true){
  83. list($flag,$list) = Redis::hscan('specialChannelIdStatsMarkUser:hash:',$flag,['match'=>'*','count'=>100]);
  84. if($list){
  85. $data = [];
  86. foreach ($list as $k=>$send_order_id){
  87. list($uid,$bid) = explode('-',$k);
  88. //$data[] = ['uid'=>$uid,'bid'=>$bid,'send_order_id'=>$send_order_id,
  89. // 'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
  90. Redis::del('specialChannelIdStatsMarkUser:set:'.$uid);
  91. }
  92. //DB::table('special_channel_stats_mark_user')->insert($data);
  93. }
  94. if(!$flag){
  95. break;
  96. }
  97. }*/
  98. ///131359
  99. //$uv = Redis::scard('push:distribution_channel_id:alluv:from:' . $from);
  100. /*$flag = 0;
  101. while (true){
  102. if($flag*1000 >=131359){
  103. break;
  104. //$result = DB::table('wap_long_visit_stats')->where('id','>=',$flag*1000)->select('param')->get();
  105. }
  106. $result = DB::table('wap_long_visit_stats')->where('id','>=',$flag*1000)->select('param')->limit(1000)->get();
  107. foreach ($result as $v){
  108. Redis::del('push:distribution_channel_id:alluv:from:' . $v->param);
  109. }
  110. $flag++;
  111. }*/
  112. $flag = 0;
  113. while (true){
  114. //smartPushTestBookPayPageUv:bid:%s
  115. list($flag,$list) = Redis::scan($flag,['match'=>'smartPushTestBookPaidUv:bid:*','count'=>100]);
  116. if($list){
  117. foreach ($list as $k){
  118. $bid = str_replace('smartPushTestBookPaidUv:bid:','',$k);
  119. //Redis::del($k);
  120. DB::table('test_book_smart_push_stats20190709')->where('bid',$bid)->increment('paid_user_num',Redis::scard($k));
  121. echo $bid .PHP_EOL;
  122. }
  123. }
  124. if(!$flag){
  125. break;
  126. }
  127. }
  128. }
  129. private function newYunQi($bid){
  130. $result = \App\Modules\Book\Services\BookService::newYunQiBook($bid);
  131. if($result == -1){
  132. echo 'yunqi book had collected'.PHP_EOL;
  133. }
  134. if ($result == -2) {
  135. echo 'new_yunqi book not exists'.PHP_EOL;
  136. }
  137. echo "OK!";
  138. }
  139. }