Ver Fonte

解决冲突

wangzq há 2 anos atrás
pai
commit
30079104c2

+ 3 - 1
app/Http/Controllers/QuickApp/BaseController.php

@@ -39,7 +39,9 @@ class BaseController extends Controller
                 $this->field[$name] = $qapp_user->phone;
             }
             if ($name == 'distribution_channel_id') {
-                $this->field[$name] = $qapp_user->user->distribution_channel_id;
+//                \Log::info('user:');
+//                \Log::info(json_encode($qapp_user,true));
+                $this->field[$name] = (isset($qapp_user->user)  && !empty($qapp_user->user))? $qapp_user->user->distribution_channel_id : $qapp_user->distribution_channel_id;
             }
             if ($name == 'send_order_id') {
                 //$this->field[$name] = $qapp_user->send_order_id;

+ 34 - 16
app/Http/Controllers/QuickApp/Book/BookController.php

@@ -143,8 +143,8 @@ class BookController extends BaseController
                 $price = $this->getPrice($book_info);
                 return $this->isBookNeedCharge($bid, $price);
             default:
-                $price = $last_chapter->is_vip ? $this->getPrice($book_info, $last_chapter->size) : 0;
-                return $last_chapter->is_vip ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
+                $price = isset($last_chapter->is_vip) ? $this->getPrice($book_info, $last_chapter->size) : 0;
+                return isset($last_chapter->is_vip) ? $this->isChapterNeedCharge($bid, $last_chapter->id, $price) : false;
         }
     }
 
@@ -222,11 +222,11 @@ class BookController extends BaseController
         if(isset($user->uid) && !empty($user->uid)){
             if(!$this->send_order_id || $this->send_order_id == 0 ){
                 \Log::info('un_send_order_book:uid:'.$this->uid.' $package:'.$package);
-                $result = $this->getCheckBids($channel,$books,$package_id);
+                $result = $this->getCheckBids($channel,$books,$package_id,$package);
                 if(isset($result[1]['books']) && count((array)$result[1]['books']) > 1){
                     return response()->success($result);
                 }
-                $result = $this->getCheckBids($channel,$books,0);
+                $result = $this->getCheckBids($channel,$books,0,$package);
                 return response()->success($result);
             }else{
                 $package_id = 0;
@@ -236,7 +236,7 @@ class BookController extends BaseController
             $package_id = 0;
         }
         \Log::info('un_send_order_book:package_id3:'.$package_id.' $package:'.$package);
-        $result = $this->getCheckBids($channel,$books,$package_id);
+        $result = $this->getCheckBids($channel,$books,$package_id,$package);
         return response()->success($result);
 
     }
@@ -248,13 +248,14 @@ class BookController extends BaseController
      * @param $package_id
      * @return array
      */
-    private function getCheckBids($channel,$books,$package_id)
+    private function getCheckBids($channel,$books,$package_id,$package)
     {
         $isAuthor = check_qapp_auth($package_id,1);
-        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$isAuthor);
-        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$isAuthor);
-        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$isAuthor);
-        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$isAuthor);
+        $hotBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'hot',$package_id),$channel,$package,$isAuthor);
+        $liveBids  = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'live',$package_id),$channel,$package,$isAuthor);
+        $recomBids = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'recom',$package_id),$channel,$package,$isAuthor);
+        $newBids   = $this->getCheckBooks(QappRecommendService::getRecommendByPacketId($channel, 'new_recom',$package_id),$channel,$package,$isAuthor);
+
 
         return array_filter([
             ['type' => 'reco_banner', 'lable' => '首页banner', 'books' => $books],
@@ -270,11 +271,16 @@ class BookController extends BaseController
      * 检测并补充不满足条件的书籍id
      * @param $bid_list
      * @param $channel : 频道
+     * @param $package : 频道
      * @return array
      */
-    private function getCheckBooks($bid_list,$channel,$is_author)
-    {
 
+    private function getCheckBooks($bid_list,$channel,$package,$is_author)
+    {
+        $hidden_cp = getHiddenCp();
+        if($package !== 'com.beidao.kuaiying.zsy'){
+            $hidden_cp = array_merge($hidden_cp,['lianshang']);
+        }
         //获取书本数量
         $count = count($bid_list);
         if (!$is_author){
@@ -293,8 +299,9 @@ class BookController extends BaseController
             ->whereIn('book_configs.bid',$bid_list)
             ->where('book_configs.is_on_shelf',2)
             ->where('book_configs.charge_type','!=','BOOK')
-            ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
             ->where($where)
+
             ->where('book_categories.pid',$channel)
             ->count();
 
@@ -312,7 +319,7 @@ class BookController extends BaseController
             ->whereIn('book_configs.bid',$bid_list)
             ->where('book_configs.is_on_shelf',2)
             ->where($where)
-            ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
             ->where('book_categories.pid',$channel)
             ->pluck('book_configs.bid')->all();
         $bid_list = array_intersect($bid_list,$bids);
@@ -323,7 +330,8 @@ class BookController extends BaseController
             ->where('book_configs.is_on_shelf',2)
             // ->where('book_configs.charge_type','!=','BOOK')
             ->where($where)
-            ->whereNotIn('book_configs.cp_source',getHiddenCp())
+            ->whereNotIn('book_configs.cp_source',$hidden_cp)
+
             ->where('book_categories.pid',$channel)
             ->inRandomOrder()
             ->limit($supplement_count)
@@ -412,6 +420,7 @@ class BookController extends BaseController
         }
 
         $page_size = $request->input('page_size', 15);
+        $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
         $books     = BookConfigService::getBooks($where, $order, $page_size);
         return response()->pagination(new BookTransformer, $books);
     }
@@ -427,15 +436,20 @@ class BookController extends BaseController
         $package     = $request->header('x-package', '');
         $category_id = $request->input('category_id');
         $bid         = $request->input('bid');
+        $package     = $request->header('x-package', '');
         if (empty($bid) || (empty($category_id) && $category_id != 0)) {
             return response()->error('PARAM_ERROR');
         }
         $isAuth = check_qapp_auth($package ,0);
         $bid   = BookService::decodeBidStatic($bid);
         $where = ['category_id' => $category_id, 'is_on_shelf' => [2]];
+
         if (!$isAuth){
             $where['cp_source'] = "ycsd";
         }
+
+        $where['channel_id'] = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
+
         $books = BookConfigService::getBooks($where, [], 4);
         $data  = [];
         foreach ($books as $v) {
@@ -516,6 +530,7 @@ class BookController extends BaseController
                 $bids = [159, 2439, 6276, 10074, 5409, 9379, 10323, 9078, 3603, 487];
             }
         }
+        
         $isAuth = check_qapp_auth($package,0);
         if (!$isAuth){
             $rank = config('home.rank');
@@ -524,7 +539,10 @@ class BookController extends BaseController
                 $bids =  $rank['female'];;
             }
         }
-        $books = collectionTransform(new BookTransformer, BookConfigService::getBooksByIds($bids));
+
+        $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
+        $books = collectionTransform(new BookTransformer, BookConfigService::getBookLists(compact('bids','channel_id')));
+
         return response()->success($books);
     }
 

+ 20 - 1
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -165,7 +165,26 @@ class ChapterController extends BaseController
         }
 
         if (!in_array($book_info->is_on_shelf, [1,2])) {
-            return response()->error('QAPP_OFF_SHELF');
+            //补充操作:如果该用户未订阅该下架的书籍则删除其阅读记录(书架不予显示)
+            //判断是否属于包年用户
+            $year_account = YearOrderService::getRecord($this->uid);
+            if(!$year_account){
+                //获取书籍充值类型
+                $charge_type = $book_info->charge_type;
+                if($charge_type == 'BOOK'){
+                    //是否购买过该书,购买过则不删除
+                    $res = BookOrderService::getRecordByuidBid($this->uid,$bid);
+                }elseif($charge_type == 'CHAPTER'){
+                    //是否购买过该书章节,购买过则不删除
+                    $res = ChapterOrderService::checkBookIsOrdered($this->uid,$bid);
+                }else{
+                    $res = false;
+                }
+                if (!$res) {
+                    ReadRecordService::delReadRecordStatic($this->uid,[$bid]);
+                    return response()->error('QAPP_OFF_SHELF');
+                }
+            }
         }
 
         //wutong,wutong2,wutong3下所有内容都不放快应用

+ 28 - 7
app/Http/Controllers/QuickApp/User/ReadRecordController.php

@@ -3,6 +3,9 @@
 namespace App\Http\Controllers\QuickApp\User;
 
 use App\Consts\SysConsts;
+use App\Modules\Subscribe\Services\BookOrderService;
+use App\Modules\Subscribe\Services\ChapterOrderService;
+use App\Modules\Subscribe\Services\YearOrderService;
 use Illuminate\Http\Request;
 use App\Http\Controllers\QuickApp\BaseController;
 use App\Modules\Book\Services\BookConfigService;
@@ -63,15 +66,16 @@ class ReadRecordController extends BaseController
      */
     public function index(Request $request)
     {
-        $user = $this->user_info;
         $res  = ReadRecordService::getReadRecord($this->uid);
-        if ($res) {
-            $id_arr = [];
-            foreach ($res as $key => $value) {
-                $id_arr[] = $value['bid'];
-            }
+        $package = $request->header('x-package', '');
+        //补充操作:如果该用户未订阅该下架的书籍则删除其阅读记录(书架不予显示)
+        //判断是否属于包年用户
+        $year_account = YearOrderService::getRecord($this->uid);
 
-            $book = BookConfigService::getBooksByIds($id_arr, [], false);//下架图书最近阅读可看到
+        if ($res) {
+            $bids = array_column($res,'bid');
+            $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
+            $book = BookConfigService::getBookLists(compact('bids','channel_id'), [], false);//下架图书最近阅读可看到
             foreach ($res as $key => &$value) {
                 $value['cover']        = '';
                 $value['last_chapter'] = 0;
@@ -88,6 +92,23 @@ class ReadRecordController extends BaseController
                         $value['status'] = $val->status;
                         $value['size'] = $val->size;
                         $value['author'] = $val->author;
+                        if(!$year_account &&  !in_array($val->is_on_shelf,[1,2]) ){
+                            //获取书籍充值类型
+                            $charge_type = $val->charge_type;
+                            if($charge_type == 'BOOK'){
+                                //是否购买过该书,购买过则不删除
+                                $result = BookOrderService::getRecordByuidBid($this->uid,$val->bid);
+                            }elseif($charge_type == 'CHAPTER'){
+                                //是否购买过该书章节,购买过则不删除
+                                $result = ChapterOrderService::checkBookIsOrdered($this->uid,$val->bid);
+                            }else{
+                                $result = false;
+                            }
+                            if (!$result) {
+                                unset($res[$key]);
+                                ReadRecordService::delReadRecordStatic($this->uid,[$val->bid]);
+                            }
+                        }
                         break;
                     }
                 }

+ 73 - 1
app/Modules/Book/Models/BookConfig.php

@@ -165,7 +165,12 @@ class BookConfig extends Model
                 }
             }
         }
-        $res->whereNotIn('book_configs.cp_source',getHiddenCp());
+        if(isset($where['channel_id']) && $where['channel_id'] == 7477){
+            $res->whereNotIn('book_configs.cp_source',getHiddenCp());
+        }else{
+            $res->whereNotIn('book_configs.cp_source',array_merge(getHiddenCp(),['lianshang']));
+        }
+
         return $res->orderBy($order[0], $order[1])->orderBy('book_configs.updated_at', 'desc')->paginate($page_size);
     }
 
@@ -232,6 +237,73 @@ class BookConfig extends Model
         return $res->limit(30)->get();
     }
 
+    public static function getBookLists(array $where, array $order = [], $is_external_shelf = true)
+    {
+        if (empty($where)) {
+            return [];
+        }
+
+        $res = self::join('books', 'book_configs.bid', '=', 'books.id')
+            ->leftjoin('book_categories', 'books.category_id', 'book_categories.id')
+            ->select(
+                'book_configs.bid',
+                'book_configs.force_subscribe_chapter_seq',
+                'book_configs.vip_seq',
+                'book_configs.price',
+                'book_configs.is_on_shelf',
+                'book_configs.cover',
+                'book_configs.book_name',
+                'book_configs.copyright',
+                'book_configs.charge_type',
+                'book_configs.is_on_shelf',
+                'books.author',
+                'books.intro',
+                'book_categories.category_name',
+                'category_id',
+                'status',
+                'chapter_count',
+                'book_configs.click_count',
+                'first_cid',
+                'last_cid',
+                'size',
+                'last_chapter',
+                'books.keyword',
+                'book_configs.recommend_index',
+                'book_configs.is_show_index_content',
+                'book_configs.product_id',
+                'book_categories.channel_name',
+                'books.last_cid',
+                'books.last_chapter',
+                'book_configs.product_id',
+                'books.updated_at as last_update_time',
+                'book_configs.copyright_limit_data',
+                'book_configs.promotion_domain',
+                'books.name as old_name',
+                'book_configs.recommend_cid'
+            );
+        if(isset($where['bids']) && !empty($where['bids'])){
+            $res->whereIn('book_configs.bid', $where['bids']);
+        }
+
+        if($is_external_shelf) $res->where('is_on_shelf',2);// 默认外部上架
+
+        if ($order) {
+            $res->orderBy($order[0], $order[1]);
+        } else {
+            $str = implode(',', $where['bids']);
+            $field = 'bid,' . $str;
+            $res->orderBy(DB::raw('field(' . $field . ')'));
+        }
+        if(isset($where['channel_id']) && $where['channel_id'] == 7477){
+            $res->whereNotIn('book_configs.cp_source',getHiddenCp());
+        }else{
+            $res->whereNotIn('book_configs.cp_source',array_merge(getHiddenCp(),['lianshang']));
+        }
+
+
+        return $res->limit(30)->get();
+    }
+
 
     /**
      * 根据bid获取图书信息

+ 2 - 1
app/Modules/Book/Services/BookAuditService.php

@@ -36,7 +36,8 @@ class BookAuditService
 
         // 一次性获取书籍列表
         $bids  = array_merge($hotBids, $liveBids, $recomBids, $newBids);
-        $books = BookConfigService::getBooksByIds($bids);
+        $channel_id = ($package === 'com.beidao.kuaiying.zsy') ? 7477 : 0;
+        $books = BookConfigService::getBookLists(compact('bids','channel_id'));
 
         return [
             [

+ 14 - 0
app/Modules/Book/Services/BookConfigService.php

@@ -65,6 +65,20 @@ class BookConfigService
         return $res;
     }
 
+    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);
+        }
+
+        return $res;
+    }
+
     /**
      *
      * 根据条件获取图书