where('is_enable',1)->select('bid_group')->first(); if($info) return explode(',',$info->bid_group); return []; } /** * 根据bid数组获取多本图书 * @param $where * @param null $order * @return mixed */ public static function getBooksByIds(array $where, $order = [],$is_external_shelf=true) { if (empty($where)) { return (object)array(); } if ($order) $res = BookConfig::getBooksByIds($where,$order,$is_external_shelf); else $res = BookConfig::getBooksByIds($where,[],$is_external_shelf); return $res; } /** * * 根据条件获取图书 * @param array $where ['key'=>'根据关键词查询','category_id'=>'根据分类id查询','is_on_shelf'=>上下架查询,'channel_name'=>'频道查询(男频女频)'] * @param array $order 排序 默认是bid排序 * @param int $page_size * @return mixed */ public static function getBooks(array $where, array $order = [], $page_size = 15) { return BookConfig::getBooks($where, $order, $page_size); } /** * 获取阅读完的推荐 * @param $category_id * @param int $num * @return mixed */ public static function getRecommendBooks($bid, $category_id, $num = 4) { return BookConfig::getRecommendBooks($bid, $category_id, $num); } /** * 获取阅读完的推荐(快应用) * @param $category_id * @param int $num * @return mixed */ public static function getQuickAppRecommendBooks($bid, $category_id, $num = 4) { return BookConfig::getQuickAppRecommendBooks($bid, $category_id, $num); } public static function getSimpleBooksByIds(array $ids) { $str = implode(',', $ids); $field = 'bid,' . $str; return BookConfig::whereIn('bid', $ids)->select('bid', 'book_name')->orderBy(DB::raw('field(' . $field . ')'))->get(); } public static function findBookKeywords(bool $is_all = false) { $sql = BookKeyword::where('status', 1)->orderBy('sequence'); if ($is_all) { return $sql->get(); } else { return $sql->paginate(10); } } public static function saveUserSearchLog(string $words, int $uid) { QappUserSearchBookLog::create([ 'uid' => $uid, 'words' => $words, ]); } /** * @return FreeBookConfig */ public static function findFreeBookConfig(int $sex) { return FreeBookConfig::where(['sex' => $sex, 'is_enabled' => 1]) ->where('end_time', '>=', now()) ->orderBy('end_time') ->first(); } /** * 查找限免书籍 * @return array */ public static function findFreeBooks(int $sex) { $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(); if(empty($bids)){ return []; } $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(); $book_list = $book_configs->transform(function ($item) use ($books) { $book = $books->where('id', $item->bid)->first(); return [ 'book_id' => Hashids::encode($item->bid), 'cover_url' => $item->cover, 'book_name' => $item->book_name, 'intro' => $book->intro, ]; })->all(); return [ 'title' => $config->name, 'end_time' => $config->end_time, 'list' => $book_list, ]; } return []; } /** * 判断书籍是否限免 * @return bool */ public static function judgeBookIsFree(int $bid) { $ids = []; foreach ([1, 2] as $sex) { $config = self::findFreeBookConfig($sex); if ($config) { $ids[] = $config->id; } } return FreeBook::where('bid', $bid) ->whereIn('config_id', $ids) ->where('is_enabled', 1)->select('id')->first(); } public static function getByBidNoFilter($bid){ return FreeBook::join('free_book_config','free_book_config.id','=','free_books.config_id') ->where('bid',$bid) ->select('free_books.id','end_time') ->where('end_time','<',date('Y-m-d H:i:s')) ->orderBy('free_book_config.end_time','desc') ->first(); } public static function chargeStats($id,$amount,$uid){ if(!Redis::Sismember('qapp:free:virtual:uids'.$id,$uid)){ return ; } $now = date('Y-m-d'); $amount = $amount*100; Redis::hincrby('qapp:book:free:charge:'.$id,$now,$amount); #Redis::sadd('qapp:free:charge'.$now,$id); Redis::sadd('qapp:free:actuality' . $now, $id); Redis::sadd('qapp:free:charge:uids'.$now.$id,$uid); } public static function getBookByField($bids,$field){ if(!$bids || !$field) return null; return BookConfig::join('books','books.id','=','book_configs.bid')-> whereIn('bid',$bids)->select($field)->get(); } }