BookShelf.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class BookShelf extends Model
  5. {
  6. protected $table = 'book_shelf';
  7. // 自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. //当前链接的user_id分库
  13. protected $connectUserId = null;
  14. public function setConnect($userId)
  15. {
  16. if ($this->connectUserId != $userId) {
  17. $database = get_db_connect($this->table, $userId);
  18. $this->setTable($database['table']);
  19. $this->connect($database);
  20. $this->sequence('id');
  21. $this->connectUserId = $userId;
  22. }
  23. return $this;
  24. }
  25. /**
  26. * @param array|mixed $userId
  27. * @param bool $bookId
  28. * @param bool $insertType
  29. * @param int $chapterId
  30. * @param int $idx
  31. * @return int|string
  32. */
  33. public function insert($userId, $bookId, $insertType, $chapterId = 0, $idx = 0)
  34. {
  35. $data = [
  36. 'user_id' => $userId,
  37. 'book_id' => $bookId,
  38. 'insert_type' => $insertType,
  39. 'chapter_id' => $chapterId,
  40. 'idx' => $idx,
  41. 'createtime' => time(),
  42. 'updatetime' => time(),
  43. ];
  44. $res = parent::insert($data);
  45. return $res;
  46. }
  47. }