BookSpider.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Modules\Statistic\Services\WapVisitStatService;
  4. use App\Modules\User\Services\UserService;
  5. use Illuminate\Console\Command;
  6. use GuzzleHttp\Client;
  7. use App\Modules\Book\Models\Book;
  8. use App\Modules\Book\Models\BookConfig;
  9. use DB;
  10. use Redis;
  11. class BookSpider extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'zytest';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = '更新图书列表';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. $this->client = new Client(['timeout' => 8.0,'allow_redirects'=>true]);
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. //return $this->innerSendOrderId();
  43. /*$a = $this->recordFirstIntoPayPage(1148,123,1645454);
  44. print_r($a);*/
  45. $this->getSpecialChannelIdStats();
  46. }
  47. /**
  48. * 更新书籍列表
  49. * @return int
  50. */
  51. public function innerSendOrderId(){
  52. $template = "select CONCAT('template_',id) as id from `wechat_template_msgs` where del_flag=0 and is_show_list=1 and created_at >='2018-11-02' order by id desc limit 1000;
  53. ";
  54. $custom = "select CONCAT('custom_',id) as id from `custom_send_msgs` where del_flag=0 and is_show_list=1 and created_at >='2018-11-02' order by id desc limit 10000;
  55. ";
  56. $t = DB::select($template);
  57. if($t){
  58. foreach ($t as $v){
  59. $uv = Redis::SMEMBERS('push:distribution_channel_id:alluv:from:' . $v->id);
  60. $pv = Redis::hget('push:distribution_channel_id:allpv' , $v->id);
  61. if($uv){
  62. Redis::sadd('push:inner_send_order_id:uv:' . $v->id,$uv);
  63. }
  64. if($uv){
  65. Redis::hset('push:inner_send_order_id:pv' ,$v->id,$pv);
  66. }
  67. }
  68. }
  69. $c = DB::select($custom);
  70. if($c){
  71. foreach ($c as $val){
  72. $uv = Redis::SMEMBERS('push:distribution_channel_id:alluv:from:' . $val->id);
  73. $pv = Redis::hget('push:distribution_channel_id:allpv' , $val->id);
  74. if($uv){
  75. Redis::sadd('push:inner_send_order_id:uv:' . $val->id,$uv);
  76. }
  77. if($pv){
  78. Redis::hset('push:inner_send_order_id:pv' ,$val->id,$pv);
  79. }
  80. }
  81. }
  82. }
  83. private function getSpecialChannelIdStats(){
  84. $result = WapVisitStatService::getSpecialChannelIdStats(168502,'2018-11-24');
  85. print_r($result);
  86. }
  87. private function recordFirstIntoPayPage($bid,$distribution_channel_id,$uid)
  88. {
  89. $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
  90. $template_id = 0;
  91. if ($distribution_channel_id == 123 && $start_time && $uid) {
  92. $user = UserService::getById($uid);
  93. if (strtotime($user->created_at) > $start_time) {
  94. $old = DB::table('user_first_visit_pay_page')->where('uid', $uid)->select('uid', 'template_type')->first();
  95. if ($old) {
  96. $template_id = $old->template_type;
  97. }
  98. if ($bid && $bid == 1148) {
  99. $template_id = $uid % 2 == 0 ? 2 : 1;
  100. if (!$old) {
  101. try {
  102. DB::table('user_first_visit_pay_page')->insert([
  103. 'uid' => $uid,
  104. 'template_type' => $template_id,
  105. 'created_at' => date('Y-m-d H:i:s'),
  106. 'updated_at' => date('Y-m-d H:i:s')
  107. ]);
  108. } catch (\Exception $e) {
  109. }
  110. }
  111. }
  112. }
  113. }
  114. return $template_id;
  115. }
  116. }