12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Modules\Book\Services;
- use App\Modules\Book\Models\Book;
- use App\Modules\Book\Models\BookCategory;
- use App\Modules\Book\Models\BookConfig;
- use App\Modules\Book\Models\NewBookTest;
- use Redis;
- class NewBookTestService
- {
-
- const wait_test = 0;
-
- const testing = 1;
-
- const complete = 2;
-
- const stop = 3;
- const gu_yan = [
- '穿越重生',
- '经商种田',
- '古代虐情',
- ];
- public static function updateTestBook($bid, $status, $plan_push_user_num = 30000)
- {
- $book_config = BookConfig::where('bid', $bid)->first();
- $origin_book = Book::find($bid);
- if ($origin_book) {
- $category = BookCategory::where('id', $origin_book->category_id)->first();
- $sex = $category->channel_name == '男频' ? '1' : '2';
- $user_type = 'ALL';
- return NewBookTest::create([
- 'bid' => $bid,
- 'category' => $category->category_name,
- 'user_type' => $user_type,
- 'book_name' => $book_config->book_name,
- 'sex' => $sex,
- 'status' => 0,
- 'test_weight' => '0',
- 'plan_push_user_num' => $plan_push_user_num,
- ]);
- } else {
- return '';
- }
- }
- public static function newBookTests(array $wheres, $is_page = true)
- {
- $obj = NewBookTest::orderBy('updated_at', 'desc');
- if ($wheres['status'] != '') {
- $obj->where('new_book_tests.status', $wheres['status']);
- }
- if ($wheres['bid']) {
- $obj->where('new_book_tests.bid', $wheres['bid']);
- }
- if ($wheres['sex']) {
- $obj->where('new_book_tests.sex', $wheres['sex']);
- }
- if ($is_page) {
- return $obj->paginate();
- } else {
- return $obj->get();
- }
- }
-
- public static function reNewBookTest(int $bid)
- {
- Redis::hDel('SmartPushBookUserNum', $bid);
- }
- public static function updateNewBookTest(int $bid, array $columns)
- {
- $columns['updated_at'] = now();
- return NewBookTest::where('bid', $bid)->update($columns);
- }
- }
|