|
@@ -32,7 +32,7 @@ class BookConfigService
|
|
|
*/
|
|
|
public static function getBookById($bid)
|
|
|
{
|
|
|
- return BookConfig::getBookById($bid);
|
|
|
+ return BookConfig::getBookById($bid);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -43,8 +43,8 @@ class BookConfigService
|
|
|
*/
|
|
|
public static function getCombinationInfo($bid)
|
|
|
{
|
|
|
- $info = BookCombinationConfig::where('bid',$bid)->where('is_enable',1)->select('bid_group')->first();
|
|
|
- if($info) return explode(',',$info->bid_group);
|
|
|
+ $info = BookCombinationConfig::where('bid', $bid)->where('is_enable', 1)->select('bid_group')->first();
|
|
|
+ if ($info) return explode(',', $info->bid_group);
|
|
|
return [];
|
|
|
}
|
|
|
|
|
@@ -54,27 +54,27 @@ class BookConfigService
|
|
|
* @param null $order
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public static function getBooksByIds(array $where, $order = [],$is_external_shelf=true)
|
|
|
+ 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);
|
|
|
+ $res = BookConfig::getBooksByIds($where, $order, $is_external_shelf);
|
|
|
else
|
|
|
- $res = BookConfig::getBooksByIds($where,[],$is_external_shelf);
|
|
|
+ $res = BookConfig::getBooksByIds($where, [], $is_external_shelf);
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
- public static function getBookLists(array $where, $order = [],$is_external_shelf=true)
|
|
|
+ public static function getBookLists(array $where, $order = [], $is_external_shelf = true)
|
|
|
{
|
|
|
if (empty($where)) {
|
|
|
return (object)array();
|
|
|
}
|
|
|
if ($order) {
|
|
|
- $res = BookConfig::getBookLists($where,$order,$is_external_shelf);
|
|
|
- } else{
|
|
|
- $res = BookConfig::getBookLists($where,[],$is_external_shelf);
|
|
|
+ $res = BookConfig::getBookLists($where, $order, $is_external_shelf);
|
|
|
+ } else {
|
|
|
+ $res = BookConfig::getBookLists($where, [], $is_external_shelf);
|
|
|
}
|
|
|
|
|
|
return $res;
|
|
@@ -94,7 +94,6 @@ class BookConfigService
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取阅读完的推荐
|
|
|
* @param $category_id
|
|
@@ -127,7 +126,6 @@ class BookConfigService
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
public static function findBookKeywords(bool $is_all = false)
|
|
|
{
|
|
|
$sql = BookKeyword::where('status', 1)->orderBy('sequence');
|
|
@@ -164,10 +162,10 @@ class BookConfigService
|
|
|
public static function findFreeBooks(int $sex)
|
|
|
{
|
|
|
$config = self::findFreeBookConfig($sex);
|
|
|
- \Log::info('return_empty_free_books:'.$sex);
|
|
|
+ \Log::info('return_empty_free_books:' . $sex);
|
|
|
\Log::info($config);
|
|
|
if ($config) {
|
|
|
- $free_books = FreeBook::where('config_id', $config->id)
|
|
|
+ $free_books = FreeBook::where('config_id', $config->id)
|
|
|
->where('is_enabled', 1)
|
|
|
->get();
|
|
|
$bids = $free_books->pluck('bid')->all();
|
|
@@ -215,31 +213,34 @@ class BookConfigService
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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')
|
|
|
+ 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 ;
|
|
|
+ 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);
|
|
|
+ $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);
|
|
|
+ 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();
|
|
|
+ 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();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -251,22 +252,22 @@ class BookConfigService
|
|
|
* @return array
|
|
|
* date 2022/09/20 10:39
|
|
|
*/
|
|
|
- public static function getAvailableBIdsbyBids($bids,$channel_id=0,$is_external_shelf=true)
|
|
|
+ public static function getAvailableBIdsbyBids($bids, $channel_id = 0, $is_external_shelf = true)
|
|
|
{
|
|
|
- if (empty($bids)){
|
|
|
+ if (empty($bids)) {
|
|
|
return [];
|
|
|
}
|
|
|
- $res = BookConfig::whereIn('bid',$bids);
|
|
|
-// if($channel_id == config('qapp_public_package_channel')){
|
|
|
-// $res->whereNotIn('cp_source',getHiddenCp());
|
|
|
-// }else{
|
|
|
-// $res->whereNotIn('cp_source',array_merge(getHiddenCp(),['lianshang']));
|
|
|
-// }
|
|
|
- $res->whereNotIn('cp_source',getHiddenCp());
|
|
|
- if ($is_external_shelf){
|
|
|
- $res->where('is_on_shelf',2);
|
|
|
- }else{
|
|
|
- $res->whereIn('is_on_shelf',[1,2]);
|
|
|
+ $res = BookConfig::whereIn('bid', $bids);
|
|
|
+ // if($channel_id == config('qapp_public_package_channel')){
|
|
|
+ // $res->whereNotIn('cp_source',getHiddenCp());
|
|
|
+ // }else{
|
|
|
+ // $res->whereNotIn('cp_source',array_merge(getHiddenCp(),['lianshang']));
|
|
|
+ // }
|
|
|
+ $res->whereNotIn('cp_source', getHiddenCp());
|
|
|
+ if ($is_external_shelf) {
|
|
|
+ $res->where('is_on_shelf', 2);
|
|
|
+ } else {
|
|
|
+ $res->whereIn('is_on_shelf', [1, 2]);
|
|
|
}
|
|
|
|
|
|
return $res->pluck("bid")->toArray();
|
|
@@ -282,52 +283,80 @@ class BookConfigService
|
|
|
* @return mixed
|
|
|
* date 2022/10/26 10:11
|
|
|
*/
|
|
|
- public static function getCheckBooks($bid_list,$channel,$package,$is_author)
|
|
|
+ public static function getCheckBooks($bid_list, $channel, $package, $is_author)
|
|
|
{
|
|
|
$hidden_cp = getHiddenCp();
|
|
|
-// if(!is_public_package($package)){
|
|
|
-// $hidden_cp = array_merge($hidden_cp,['lianshang']);
|
|
|
-// }
|
|
|
+ // if(!is_public_package($package)){
|
|
|
+ // $hidden_cp = array_merge($hidden_cp,['lianshang']);
|
|
|
+ // }
|
|
|
//获取书本数量
|
|
|
$count = count($bid_list);
|
|
|
- if (!$is_author){
|
|
|
+ if (!$is_author) {
|
|
|
$where = [
|
|
|
- ['book_configs.charge_type','!=','BOOK'],
|
|
|
- ['book_configs.cp_source','=','ycsd'],
|
|
|
+ ['book_configs.charge_type', '!=', 'BOOK'],
|
|
|
+ ['book_configs.cp_source', '=', 'ycsd'],
|
|
|
];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$where = [
|
|
|
- ['book_configs.charge_type','!=','BOOK'],
|
|
|
+ ['book_configs.charge_type', '!=', 'BOOK'],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
//获取书籍交集bid,过滤掉不符合要求的书
|
|
|
$bid_list = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
|
|
|
->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
|
|
|
- ->whereIn('book_configs.bid',$bid_list)
|
|
|
- ->where('book_configs.is_on_shelf',2)
|
|
|
+ ->whereIn('book_configs.bid', $bid_list)
|
|
|
+ ->where('book_configs.is_on_shelf', 2)
|
|
|
->where($where)
|
|
|
- ->whereNotIn('book_configs.cp_source',$hidden_cp)
|
|
|
- ->where('book_categories.pid',$channel)
|
|
|
+ ->whereNotIn('book_configs.cp_source', $hidden_cp)
|
|
|
+ ->where('book_categories.pid', $channel)
|
|
|
->pluck('book_configs.bid')->all();
|
|
|
|
|
|
$book_count = count($bid_list);
|
|
|
- if ($book_count === $count){
|
|
|
- return $bid_list;
|
|
|
+ if ($book_count === $count) {
|
|
|
+ return $bid_list;
|
|
|
}
|
|
|
$supplement_count = $count - $book_count;
|
|
|
//获取随机的有效的书籍bid
|
|
|
$rand_bid = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
|
|
|
->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
|
|
|
- ->where('book_configs.is_on_shelf',2)
|
|
|
+ ->where('book_configs.is_on_shelf', 2)
|
|
|
->where($where)
|
|
|
- ->whereNotIn('book_configs.cp_source',$hidden_cp)
|
|
|
+ ->whereNotIn('book_configs.cp_source', $hidden_cp)
|
|
|
// ->where('book_configs.is_high_quality',1)
|
|
|
- ->where('book_categories.pid',$channel)
|
|
|
- ->orderBy('book_configs.is_high_quality','desc')
|
|
|
+ ->where('book_categories.pid', $channel)
|
|
|
+ ->orderBy('book_configs.is_high_quality', 'desc')
|
|
|
->inRandomOrder()
|
|
|
->limit($supplement_count)
|
|
|
- ->pluck('book_configs.bid')->all();
|
|
|
- return array_filter(array_merge($bid_list,$rand_bid));
|
|
|
+ ->pluck('book_configs.bid')->all();
|
|
|
+ return array_filter(array_merge($bid_list, $rand_bid));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getRecommendBids($package = '', $channel = 1, $is_auth = true, $no_in_bid = [], $limit = 64)
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ ['book_configs.charge_type', '!=', 'BOOK'],
|
|
|
+ ];
|
|
|
+ if (!$is_auth) {
|
|
|
+ $where[] = ['book_configs.cp_source', '=', 'ycsd'];
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取书籍交集bid,过滤掉不符合要求的书
|
|
|
+ $bid_list = BookConfig::join('books', 'book_configs.bid', '=', 'books.id')
|
|
|
+ ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
|
|
|
+ ->where('book_configs.is_on_shelf', 2)
|
|
|
+ ->where($where)
|
|
|
+ ->whereNotIn('book_configs.cp_source', getHiddenCp())
|
|
|
+ ->where('book_categories.pid', $channel);
|
|
|
+ if (!empty($no_in_bid)) {
|
|
|
+ $bid_list->whereNotIn('book_configs.bid', $no_in_bid);
|
|
|
+ }
|
|
|
+
|
|
|
+ $bid_list = $bid_list->orderBy('recommend_index' , 'desc')->limit($limit)->pluck('book_configs.bid');
|
|
|
+
|
|
|
+ echo "<pre><hr>";
|
|
|
+ var_export($bid_list);
|
|
|
+ echo "<hr>";
|
|
|
+ die();
|
|
|
}
|
|
|
}
|