NewBookTestData.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Console\Commands\Book;
  3. use Illuminate\Console\Command;
  4. use App\Modules\Statistic\Services\WapVisitStatService;
  5. use DB;
  6. class NewBookTestData extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'new_book_test_data';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '新书测试数据填充';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->oneDayDataFill();
  37. $this->threeDayDataFill();
  38. $this->sixDayDataFill();
  39. $this->sevenDayDataFill();
  40. }
  41. function oneDayDataFill(){
  42. $one_day_before = date('Y-m-d H:i:s',strtotime('-1 day'));
  43. $new_book_tests = DB::table('new_book_tests')
  44. ->where('test_end_time','<=',$one_day_before)
  45. // ->where('status',2)
  46. ->whereNull('uv_in_one_day')
  47. ->whereNull('sub_amount_in_one_day')
  48. ->get();
  49. if(!$new_book_tests){return;}
  50. foreach ($new_book_tests as $item) {
  51. $data = array();
  52. $book_statistics = WapVisitStatService::smartPushTestBookStats($item->bid);
  53. $data['uv_in_one_day'] = $book_statistics['uv'];
  54. $data['sub_amount_in_one_day'] = $book_statistics['book_amount'];
  55. DB::table('new_book_tests')
  56. ->where('id',$item->id)
  57. ->update($data);
  58. }
  59. }
  60. function threeDayDataFill(){
  61. $three_day_before = date('Y-m-d H:i:s',strtotime('-3 day'));
  62. $new_book_tests = DB::table('new_book_tests')
  63. ->where('test_end_time','<=',$three_day_before)
  64. // ->where('status',2)
  65. ->whereNull('uv_in_three_day')
  66. ->whereNull('sub_amount_in_three_day')
  67. ->get();
  68. if(!$new_book_tests){return;}
  69. foreach ($new_book_tests as $item) {
  70. $data = array();
  71. $book_statistics = WapVisitStatService::smartPushTestBookStats($item->bid);
  72. $data['uv_in_three_day'] = $book_statistics['uv'];
  73. $data['sub_amount_in_three_day'] = $book_statistics['book_amount'];
  74. DB::table('new_book_tests')
  75. ->where('id',$item->id)
  76. ->update($data);
  77. }
  78. }
  79. function sevenDayDataFill(){
  80. $seven_day_before = date('Y-m-d H:i:s',strtotime('-7 day'));
  81. $seven_day_before_limit = date('Y-m-d H:i:s',strtotime('-7 day -1hour'));
  82. $new_book_tests = DB::table('new_book_tests')
  83. ->where('test_end_time','<=',$seven_day_before)
  84. ->where('test_end_time','>=',$seven_day_before_limit)
  85. ->whereNull('uv_in_seven_day')
  86. ->whereNull('sub_amount_in_seven_day')
  87. ->get();
  88. if(!$new_book_tests){return;}
  89. foreach ($new_book_tests as $item) {
  90. $data = array();
  91. $book_statistics = WapVisitStatService::smartPushTestBookStats($item->bid);
  92. $data['uv_in_seven_day'] = $book_statistics['uv'];
  93. $data['sub_amount_in_seven_day'] = $book_statistics['book_amount'];
  94. DB::table('new_book_tests')
  95. ->where('id',$item->id)
  96. ->update($data);
  97. }
  98. }
  99. function sixDayDataFill(){
  100. $six_day_before = date('Y-m-d H:i:s',strtotime('-6 day'));
  101. $six_day_before_limit = date('Y-m-d H:i:s',strtotime('-6 day -1hour'));
  102. $new_book_tests = DB::table('new_book_tests')
  103. ->where('test_end_time','<=',$six_day_before)
  104. ->where('test_end_time','>=',$six_day_before_limit)
  105. ->whereNull('uv_in_six_day')
  106. ->whereNull('sub_amount_in_six_day')
  107. ->get();
  108. if(!$new_book_tests){return;}
  109. foreach ($new_book_tests as $item) {
  110. $data = array();
  111. $book_statistics = WapVisitStatService::smartPushTestBookStats($item->bid);
  112. $data['uv_in_six_day'] = $book_statistics['uv'];
  113. $data['sub_amount_in_six_day'] = $book_statistics['book_amount'];
  114. DB::table('new_book_tests')
  115. ->where('id',$item->id)
  116. ->update($data);
  117. }
  118. }
  119. }