NewBookTestService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Modules\Book\Services;
  3. use App\Modules\Book\Models\Book;
  4. use App\Modules\Book\Models\BookCategory;
  5. use App\Modules\Book\Models\BookConfig;
  6. use App\Modules\Book\Models\NewBookTest;
  7. use Redis;
  8. class NewBookTestService
  9. {
  10. /**
  11. * 待测试
  12. */
  13. const wait_test = 0;
  14. /**
  15. * 测试中
  16. */
  17. const testing = 1;
  18. /**
  19. * 测试完毕
  20. */
  21. const complete = 2;
  22. /**
  23. * 手动停止
  24. */
  25. const stop = 3;
  26. const gu_yan = [
  27. '穿越重生',
  28. '经商种田',
  29. '古代虐情',
  30. ];
  31. public static function updateTestBook($bid, $status, $plan_push_user_num = 30000)
  32. {
  33. $book_config = BookConfig::where('bid', $bid)->first();
  34. $origin_book = Book::find($bid);
  35. if ($origin_book) {
  36. $category = BookCategory::where('id', $origin_book->category_id)->first();
  37. $sex = $category->channel_name == '男频' ? '1' : '2';
  38. $user_type = 'ALL';//in_array($category->category_name, self::gu_yan) ? 'GUYAN' :'ALL';
  39. return NewBookTest::create([
  40. 'bid' => $bid,
  41. 'category' => $category->category_name,
  42. 'user_type' => $user_type,
  43. 'book_name' => $book_config->book_name,
  44. 'sex' => $sex,
  45. 'status' => 0,
  46. 'test_weight' => '0',
  47. 'plan_push_user_num' => $plan_push_user_num,
  48. ]);
  49. } else {
  50. return '';
  51. }
  52. }
  53. public static function newBookTests(array $wheres, $is_page = true)
  54. {
  55. $obj = NewBookTest::orderBy('updated_at', 'desc');
  56. if ($wheres['status'] != '') {
  57. $obj->where('new_book_tests.status', $wheres['status']);
  58. }
  59. if ($wheres['bid']) {
  60. $obj->where('new_book_tests.bid', $wheres['bid']);
  61. }
  62. if ($wheres['sex']) {
  63. $obj->where('new_book_tests.sex', $wheres['sex']);
  64. }
  65. if ($is_page) {
  66. return $obj->paginate();
  67. } else {
  68. return $obj->get();
  69. }
  70. }
  71. /**
  72. * 重新开始新书测试
  73. */
  74. public static function reNewBookTest(int $bid)
  75. {
  76. Redis::hDel('SmartPushBookUserNum', $bid);
  77. }
  78. public static function updateNewBookTest(int $bid, array $columns)
  79. {
  80. $columns['updated_at'] = now();
  81. return NewBookTest::where('bid', $bid)->update($columns);
  82. }
  83. }