fly před 4 roky
rodič
revize
0a6dbf1f6e

+ 29 - 3
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -97,15 +97,33 @@ class ChapterController extends BaseController
         }
 
         if ($chapter->is_vip == 0) {
-            ReadRecordService::addReadRecord([
-                'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
-                'cid' => $cid, 'chapter_name' => $chapter->name
+            if ($chapter->sequence > 1) {
+                ReadRecordService::addReadRecord([
+                    'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
+                    'cid' => $cid, 'chapter_name' => $chapter->name
+                ]);
+            }
+            ReadRecordService::addReadLog($this->uid, [
+                'distribution_channel_id' => $this->distribution_channel_id,
+                'bid' => $bid,
+                'cid' => $chapter->id,
+                'uid' => $this->uid,
+                'send_order_id' => $this->send_order_id,
+                'sequence' => $chapter->sequence,
             ]);
             return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
         }
 
         //已经付费 或者 书籍是否限免
         if ($this->getOrderRecord($bid, $cid) || BookConfigService::judgeBookIsFree($bid)) {
+            ReadRecordService::addReadLog($this->uid, [
+                'distribution_channel_id' => $this->distribution_channel_id,
+                'bid' => $bid,
+                'cid' => $chapter->id,
+                'uid' => $this->uid,
+                'send_order_id' => $this->send_order_id,
+                'sequence' => $chapter->sequence,
+            ]);
             ReadRecordService::addReadRecord([
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'cid' => $cid, 'chapter_name' => $chapter->name
@@ -147,6 +165,14 @@ class ChapterController extends BaseController
         //付费 不提醒
         if ($this->balancePay($book_info, $cid, $chapter->size, $chapter->name, 0)) {
             UserTaskService::addUserTaskQueue($this->uid, BaseTask::read, UserTaskService::judge_trigger);
+            ReadRecordService::addReadLog($this->uid, [
+                'distribution_channel_id' => $this->distribution_channel_id,
+                'bid' => $bid,
+                'cid' => $chapter->id,
+                'uid' => $this->uid,
+                'send_order_id' => $this->send_order_id,
+                'sequence' => $chapter->sequence,
+            ]);
             ReadRecordService::addReadRecord([
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'cid' => $cid, 'chapter_name' => $chapter->name

+ 30 - 0
app/Modules/User/Models/ReadLog.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Modules\User\Models;
+
+use App\Modules\TableSuffix;
+use Illuminate\Database\Eloquent\Model;
+
+class ReadLog extends Model
+{
+    use TableSuffix;
+
+    protected $table = 'read_logs';
+    protected $fillable = [
+        'distribution_channel_id',
+        'bid',
+        'cid',
+        'uid',
+        'send_order_id',
+        'from',
+        'attach',
+        'sequence',
+    ];
+    protected $connection = 'qapp_log_mysql';
+
+    public static function model(int $uid)
+    {
+        self::suffix($uid % 1024);
+        return new static;
+    }
+}

+ 10 - 0
app/Modules/User/Services/ReadRecordService.php

@@ -14,6 +14,7 @@ use Redis;
 use Hashids;
 use App\Modules\Book\Services\BookConfigService;
 use App\Modules\Book\Models\Chapter;
+use App\Modules\User\Models\ReadLog;
 use DB;
 
 class ReadRecordService
@@ -653,4 +654,13 @@ class ReadRecordService
             }
         }
     }
+
+    /**
+     * 添加用户的阅读记录
+     */
+    public static function addReadLog(int $uid, array $data)
+    {
+        $log = ReadLog::model($uid);
+        $log->create($data);
+    }
 }

+ 13 - 0
config/database.php

@@ -97,6 +97,19 @@ return [
             'strict' => false,
             'engine' => null,
         ],
+        'qapp_log_mysql' => [
+            'driver' => 'mysql',
+            'host' => env('QAPP_LOG_DB_HOST', 'localhost'),
+            'port' => env('QAPP_LOG_DB_PORT', '3306'),
+            'database' => env('QAPP_LOG_DB_DATABASE', 'forge'),
+            'username' => env('QAPP_LOG_DB_USERNAME', 'forge'),
+            'password' => env('QAPP_LOG_DB_PASSWORD', ''),
+            'charset' => 'utf8',
+            'collation' => 'utf8_unicode_ci',
+            'prefix' => '',
+            'strict' => false,
+            'engine' => null,
+        ],
         'new_yunqi' => [
             'driver' => 'mysql',
             'host' => env('NEW_YUNQI_DB_HOST', 'localhost'),