12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\common\model;
- use think\Model;
- class BookShelf extends Model
- {
- protected $table = 'book_shelf';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- //当前链接的user_id分库
- protected $connectUserId = null;
- public function setConnect($userId)
- {
- if ($this->connectUserId != $userId) {
- $database = get_db_connect($this->table, $userId);
- $this->setTable($database['table']);
- $this->connect($database);
- $this->sequence('id');
- $this->connectUserId = $userId;
- }
- return $this;
- }
- /**
- * @param array|mixed $userId
- * @param bool $bookId
- * @param bool $insertType
- * @param int $chapterId
- * @param int $idx
- * @return int|string
- */
- public function insert($userId, $bookId, $insertType, $chapterId = 0, $idx = 0)
- {
- $data = [
- 'user_id' => $userId,
- 'book_id' => $bookId,
- 'insert_type' => $insertType,
- 'chapter_id' => $chapterId,
- 'idx' => $idx,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- $res = parent::insert($data);
- return $res;
- }
- }
|