|
@@ -15,6 +15,7 @@ use App\Modules\Product\Services\ProductService;
|
|
use App\Modules\Book\Models\Book;
|
|
use App\Modules\Book\Models\Book;
|
|
use App\Modules\Book\Models\BookKeyword;
|
|
use App\Modules\Book\Models\BookKeyword;
|
|
use App\Modules\Book\Models\FreeBook;
|
|
use App\Modules\Book\Models\FreeBook;
|
|
|
|
+use App\Modules\Book\Models\FreeBookConfig;
|
|
use App\Modules\Book\Models\QappUserSearchBookLog;
|
|
use App\Modules\Book\Models\QappUserSearchBookLog;
|
|
use Redis;
|
|
use Redis;
|
|
use DB;
|
|
use DB;
|
|
@@ -469,42 +470,60 @@ class BookConfigService
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @return FreeBookConfig
|
|
|
|
+ */
|
|
|
|
+ public static function findFreeBookConfig(int $sex)
|
|
|
|
+ {
|
|
|
|
+ return FreeBookConfig::firstWhere(['sex' => $sex, 'is_enable' => 1])->orderBy('end_time');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 查找限免书籍
|
|
* 查找限免书籍
|
|
|
|
+ * @return array
|
|
*/
|
|
*/
|
|
public static function findFreeBooks(int $sex)
|
|
public static function findFreeBooks(int $sex)
|
|
{
|
|
{
|
|
- $free_books = FreeBook::where('start_time', '<=', now())->where('end_time', '>=', now())
|
|
|
|
- ->where('sex', $sex)
|
|
|
|
- ->where('is_enabled', 1)
|
|
|
|
- ->get();
|
|
|
|
- $bids = $free_books->pluck('bid')->all();
|
|
|
|
- $book_configs = BookConfig::whereIn('bid', $bids)
|
|
|
|
- ->where('is_on_shelf', 2)
|
|
|
|
- ->select('bid', 'book_name', 'cover')
|
|
|
|
- ->get();
|
|
|
|
- $books = Book::whereIn('id', $bids)->select('id', 'intro')->get();
|
|
|
|
- return $book_configs->transform(function ($item) use ($books, $free_books) {
|
|
|
|
- $free_book = $free_books->where('bid', $item->bid)->first();
|
|
|
|
- $book = $books->where('id', $item->bid)->first();
|
|
|
|
- return [
|
|
|
|
- 'bid' => Hashids::encode($item->bid),
|
|
|
|
- 'cover' => $item->cover,
|
|
|
|
- 'book_name' => $item->book_name,
|
|
|
|
- 'intro' => $book->intro,
|
|
|
|
- 'start_time' => $free_book->start_time,
|
|
|
|
- 'end_time' => $free_book->end_time,
|
|
|
|
- ];
|
|
|
|
- })->all();
|
|
|
|
|
|
+ $config = self::findFreeBookConfig($sex);
|
|
|
|
+ if ($config) {
|
|
|
|
+ $free_books = FreeBook::where('config_id', $config->id)
|
|
|
|
+ ->where('is_enabled', 1)
|
|
|
|
+ ->get();
|
|
|
|
+ $bids = $free_books->pluck('bid')->all();
|
|
|
|
+ $book_configs = BookConfig::whereIn('bid', $bids)
|
|
|
|
+ ->where('is_on_shelf', 2)
|
|
|
|
+ ->select('bid', 'book_name', 'cover')
|
|
|
|
+ ->get();
|
|
|
|
+ $books = Book::whereIn('id', $bids)->select('id', 'intro')->get();
|
|
|
|
+ return $book_configs->transform(function ($item) use ($books, $free_books) {
|
|
|
|
+ $free_book = $free_books->where('bid', $item->bid)->first();
|
|
|
|
+ $book = $books->where('id', $item->bid)->first();
|
|
|
|
+ return [
|
|
|
|
+ 'bid' => Hashids::encode($item->bid),
|
|
|
|
+ 'cover' => $item->cover,
|
|
|
|
+ 'book_name' => $item->book_name,
|
|
|
|
+ 'intro' => $book->intro,
|
|
|
|
+ 'start_time' => $free_book->start_time,
|
|
|
|
+ 'end_time' => $free_book->end_time,
|
|
|
|
+ ];
|
|
|
|
+ })->all();
|
|
|
|
+ }
|
|
|
|
+ return [];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断书籍是否限免
|
|
* 判断书籍是否限免
|
|
|
|
+ * @return bool
|
|
*/
|
|
*/
|
|
public static function judgeBookIsFree(int $bid)
|
|
public static function judgeBookIsFree(int $bid)
|
|
{
|
|
{
|
|
- return FreeBook::where('start_time', '<=', now())->where('end_time', '>=', now())
|
|
|
|
- ->where('bid', $bid)
|
|
|
|
- ->where('is_enabled', 1)
|
|
|
|
- ->exists();
|
|
|
|
|
|
+ $free_book = FreeBook::where('bid', $bid)
|
|
|
|
+ ->where('is_enabled', 1)->first();
|
|
|
|
+ if ($free_book) {
|
|
|
|
+ $config = self::findFreeBookConfig($free_book->sex);
|
|
|
|
+ if ($config) {
|
|
|
|
+ return $free_book->config_id == $config->id;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
}
|
|
}
|