Wang Chen преди 4 години
родител
ревизия
7e96a87ae5
променени са 1 файла, в които са добавени 77 реда и са изтрити 77 реда
  1. 77 77
      app/Http/Controllers/QuickApp/Book/ChapterController.php

+ 77 - 77
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -30,8 +30,8 @@ class ChapterController extends BaseController
 
     public function getCatalog(Request $request, $bid)
     {
-        $bid = BookService::decodeBidStatic($bid);
-        $lists = ChapterService::getChapterLists($bid);
+        $bid       = BookService::decodeBidStatic($bid);
+        $lists     = ChapterService::getChapterLists($bid);
         $book_info = BookConfigService::getBookById($bid);
         if (!$book_info) {
             return response()->error('PARAM_ERROR');
@@ -42,14 +42,14 @@ class ChapterController extends BaseController
 
     public function getCatalogPerPage(Request $request, $bid)
     {
-        $bid = BookService::decodeBidStatic($bid);
+        $bid       = BookService::decodeBidStatic($bid);
         $book_info = BookConfigService::getBookById($bid);
         if (!$book_info) {
             return response()->error('PARAM_ERROR');
         }
         $page_size = $request->input('page_size', 15);
         if ($page_size >= 100) $page_size = 100;
-        $res = ChapterService::getChapterListsPage($bid, $page_size);
+        $res   = ChapterService::getChapterListsPage($bid, $page_size);
         $lists = $this->getChapterCatalog($bid, $res, $book_info);
         return response()->pagination(new ChapterListTransformer, $lists);
     }
@@ -58,16 +58,16 @@ class ChapterController extends BaseController
     {
         switch ($book_info->charge_type) {
             case 'BOOK':
-                $price = $this->getPrice($book_info);
+                $price          = $this->getPrice($book_info);
                 $is_need_charge = $this->isBookNeedCharge($bid, $price);
                 foreach ($chapters as $v) {
                     $v->is_need_charge = $v->is_vip ? $is_need_charge : false;
-                    $v->price = $price;
+                    $v->price          = $price;
                 }
                 break;
             default:
                 foreach ($chapters as $v) {
-                    $v->price = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
+                    $v->price          = $v->is_vip ? $this->getPrice($book_info, $v->size) : 0;
                     $v->is_need_charge = $v->is_vip ? $this->isChapterNeedCharge($bid, $v->id, $v->price) : false;
                 }
                 break;
@@ -78,9 +78,9 @@ class ChapterController extends BaseController
     public function index(Request $request, $bid, $cid)
     {
         $oldbid = $bid;
-        $bid = BookService::decodeBidStatic($bid);
+        $bid    = BookService::decodeBidStatic($bid);
         //获取图书信息
-        $book_info  = BookConfigService::getBookById($bid);
+        $book_info = BookConfigService::getBookById($bid);
         if (empty($book_info))
             return response()->error('QAPP_SYS_ERROR');
         $this->book_info = $book_info;
@@ -96,11 +96,13 @@ class ChapterController extends BaseController
             dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
         }
 
-        if ($chapter->is_vip == 0 && $chapter->sequence > 1) {
-            ReadRecordService::addReadRecord([
-                'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
-                'cid' => $cid, 'chapter_name' => $chapter->name
-            ]);
+        if ($chapter->is_vip == 0) {
+            if ($chapter->sequence > 1) {
+                ReadRecordService::addReadRecord([
+                    'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
+                    'cid' => $cid, 'chapter_name' => $chapter->name
+                ]);
+            }
             return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
         }
 
@@ -117,21 +119,21 @@ class ChapterController extends BaseController
         //未付费 要提醒
         $user_info = $this->user_info;
         //未付费 余额不足
-        $fee = $this->getPrice($book_info, $chapter->size);
+        $fee  = $this->getPrice($book_info, $chapter->size);
         $data = [
-            'book_id' => $oldbid,
-            'book_name' => $book_info->book_name,
-            'chapter_name' => $chapter->name,
-            'chapter_id' => $cid,
-            'pay_type' => $book_info->charge_type,
-            'fee' => $fee,
-            'user_balance' => $user_info->balance,
-            'product_id' => $book_info->product_id,
-            'uid' => $this->uid,
+            'book_id'                 => $oldbid,
+            'book_name'               => $book_info->book_name,
+            'chapter_name'            => $chapter->name,
+            'chapter_id'              => $cid,
+            'pay_type'                => $book_info->charge_type,
+            'fee'                     => $fee,
+            'user_balance'            => $user_info->balance,
+            'product_id'              => $book_info->product_id,
+            'uid'                     => $this->uid,
             'distribution_channel_id' => $this->distribution_channel_id,
-            'is_discount' => 0,
-            'discount_fee' => '',
-            'discount' => ''
+            'is_discount'             => 0,
+            'discount_fee'            => '',
+            'discount'                => ''
 
         ];
 
@@ -165,12 +167,11 @@ class ChapterController extends BaseController
     }
 
 
-
     public function pay(Request $request, $bid, $cid)
     {
-        $remind = (int) $request->input('remind');
-        $oldbid = $bid;
-        $bid = BookService::decodeBidStatic($bid);
+        $remind    = (int)$request->input('remind');
+        $oldbid    = $bid;
+        $bid       = BookService::decodeBidStatic($bid);
         $book_info = BookConfigService::getBookById($bid);;
         if (empty($book_info)) response()->error('QAPP_SYS_ERROR');
 
@@ -197,19 +198,19 @@ class ChapterController extends BaseController
             $fee = $this->getPrice($book_info, $chapter->size);
 
             $data = [
-                'book_id' => $oldbid,
-                'book_name' => $book_info->book_name,
-                'chapter_name' => $chapter->name,
-                'chapter_id' => $cid,
-                'pay_type' => $book_info->charge_type,
-                'fee' => $fee,
-                'user_balance' => $this->user_info['balance'],
-                'product_id' => $book_info->product_id,
-                'uid' => $this->uid,
+                'book_id'                 => $oldbid,
+                'book_name'               => $book_info->book_name,
+                'chapter_name'            => $chapter->name,
+                'chapter_id'              => $cid,
+                'pay_type'                => $book_info->charge_type,
+                'fee'                     => $fee,
+                'user_balance'            => $this->user_info['balance'],
+                'product_id'              => $book_info->product_id,
+                'uid'                     => $this->uid,
                 'distribution_channel_id' => $this->distribution_channel_id,
-                'is_discount' => 0,
-                'discount_fee' => '',
-                'discount' => ''
+                'is_discount'             => 0,
+                'discount_fee'            => '',
+                'discount'                => ''
             ];
             if ($book_info->charge_type == 'BOOK') {
                 return response()->error('QAPP_BOOK_INSUFFICIENT_BALANCE', $data);
@@ -222,7 +223,6 @@ class ChapterController extends BaseController
     }
 
 
-
     /**
      * 余额支付
      * @param $book_info
@@ -233,7 +233,7 @@ class ChapterController extends BaseController
     protected function balancePay($book_info, $chapter_id, $chapter_size, $chapter_name, $is_remind)
     {
         $fee = $this->getPrice($book_info, $chapter_size);
-        if ((int) $this->user_info['balance'] >= $fee) {
+        if ((int)$this->user_info['balance'] >= $fee) {
             if ($this->bookOrderOrChapterOrder($book_info, $chapter_id, $fee, $chapter_name, $is_remind)) {
                 return true;
             }
@@ -256,12 +256,12 @@ class ChapterController extends BaseController
         if (!$chapter_content) return false;
         $chapter->content = trim(str_replace($chapter_content->name, '', $chapter_content->content));
         //统计点击率
-        $key = 'book_click_num_bid_' . $bid;
+        $key   = 'book_click_num_bid_' . $bid;
         $field = date('Y-m-d');
-        $old = Redis::hget($key, $field);
-        if (!$old)  $old = 0;
+        $old   = Redis::hget($key, $field);
+        if (!$old) $old = 0;
         Redis::hset($key, $field, $old + 1);
-        $force_add_desk_type = $this->addDesktopType($bid, $chapter->sequence);
+        $force_add_desk_type          = $this->addDesktopType($bid, $chapter->sequence);
         $chapter->force_add_desk_type = $force_add_desk_type;
         //统计
         $this->stats();
@@ -279,26 +279,26 @@ class ChapterController extends BaseController
     {
         if ($book_info['charge_type'] == 'BOOK') {
             $data = [
-                'uid' => $this->uid,
-                'fee' => $fee,
-                'u' => $this->send_order_id,
+                'uid'                     => $this->uid,
+                'fee'                     => $fee,
+                'u'                       => $this->send_order_id,
                 'distribution_channel_id' => $this->distribution_channel_id,
-                'bid' => $book_info->bid,
-                'book_name' => $book_info->book_name,
-                'send_order_id' => $this->send_order_id,
+                'bid'                     => $book_info->bid,
+                'book_name'               => $book_info->book_name,
+                'send_order_id'           => $this->send_order_id,
             ];
             return BookOrderService::addOrderRecodeAndDecrUserBalance($data, $this->uid);
         } else {
             $data = [
-                'uid' => $this->uid,
-                'fee' => $fee,
-                'cid' => $chapter_id,
-                'bid' => $book_info->bid,
+                'uid'                     => $this->uid,
+                'fee'                     => $fee,
+                'cid'                     => $chapter_id,
+                'bid'                     => $book_info->bid,
                 'distribution_channel_id' => $this->distribution_channel_id,
-                'book_name' => $book_info->book_name,
-                'chapter_name' => $chapter_name,
-                'send_order_id' => $this->send_order_id,
-                'is_remind' => $is_remind
+                'book_name'               => $book_info->book_name,
+                'chapter_name'            => $chapter_name,
+                'send_order_id'           => $this->send_order_id,
+                'is_remind'               => $is_remind
             ];
             if ($is_remind) {
                 $this->addOrderRemind($book_info->bid);
@@ -308,7 +308,7 @@ class ChapterController extends BaseController
     }
 
 
-    protected  function  addOrderRemind($bid)
+    protected function addOrderRemind($bid)
     {
         if (ChapterReminderService::checkIsNoReminder($this->uid, $bid)) {
             return true;
@@ -317,6 +317,7 @@ class ChapterController extends BaseController
             return true;
         }
     }
+
     /**
      * 是否订购提醒
      * @param $chapter_id
@@ -333,7 +334,7 @@ class ChapterController extends BaseController
      * @param $uid
      * @return bool
      */
-    protected  function getSubscribe()
+    protected function getSubscribe()
     {
         $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
         if ($res) return true;
@@ -363,7 +364,7 @@ class ChapterController extends BaseController
         //章节订购记录
         $chapterOrder = new ChapterOrderService();
 
-        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id))  return true;
+        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
 
         return false;
     }
@@ -383,7 +384,7 @@ class ChapterController extends BaseController
                 return 1399;
             } else {
                 $this->is_first_book_order = 1;
-                return  899;
+                return 899;
             }
         } else {
             $fee = BookService::getPrice($book_info, $this->distribution_channel_id, $chapter_size);
@@ -392,7 +393,6 @@ class ChapterController extends BaseController
     }
 
 
-
     /**
      * 用户添加标签
      * @param $book_info
@@ -402,14 +402,14 @@ class ChapterController extends BaseController
         if (!UserDeepReadTagService::isAddTag($this->uid, $book_info->bid)) {
             try {
                 UserDeepReadTagService::addTag([
-                    'uid' => $this->uid,
-                    'bid' => $book_info->bid,
-                    'book_name' => $book_info->book_name,
-                    'category_id' => $book_info->category_id,
-                    'category_name' => $book_info->category_name,
-                    'sex_preference' => $book_info->channel_name ? $book_info->channel_name : '',
+                    'uid'                     => $this->uid,
+                    'bid'                     => $book_info->bid,
+                    'book_name'               => $book_info->book_name,
+                    'category_id'             => $book_info->category_id,
+                    'category_name'           => $book_info->category_name,
+                    'sex_preference'          => $book_info->channel_name ? $book_info->channel_name : '',
                     'distribution_channel_id' => $this->distribution_channel_id ? $this->distribution_channel_id : '0',
-                    'send_order_id' => $this->send_order_id,
+                    'send_order_id'           => $this->send_order_id,
                 ]);
             } catch (\Exception  $e) {
             }
@@ -467,10 +467,10 @@ class ChapterController extends BaseController
     private function addDesktopType($bid, $sequence)
     {
         $force_add_desk_type = 0;
-        $send_order_id = ReadRecordService::getSendOrderId($this->uid);
+        $send_order_id       = ReadRecordService::getSendOrderId($this->uid);
         if (!$send_order_id) return $force_add_desk_type;
         $send_order_info = SendOrderService::getById($send_order_id);
-        if (!$send_order_info)  return $force_add_desk_type;
+        if (!$send_order_info) return $force_add_desk_type;
         if ($send_order_info->book_id == $bid) {
             if ($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_seq) {
                 if ($sequence >= $send_order_info->force_add_desk_seq) {