ShortUrl.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use app\admin\service\RedisService;
  5. class ShortUrl extends BaseRwModel
  6. {
  7. // 表名
  8. protected $table = 'short_url';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. ];
  17. //当前链接的user_id分库
  18. protected $connectShortUrlId = null;
  19. //最后一个插入的id
  20. protected $lastId = 0;
  21. /**
  22. * 设置分库链接数据
  23. *
  24. * @param $id int short_url_id
  25. * @return $this
  26. */
  27. public function setConnect($id)
  28. {
  29. if ($this->connectShortUrlId != $id) {
  30. $this->connect(get_db_connect($this->table, $id));
  31. $this->sequence('id');
  32. $this->connectShortUrlId = $id;
  33. }
  34. return $this;
  35. }
  36. public function getInfo($id)
  37. {
  38. //return $this->setConnect($id)->where(['id' => $id])->find();
  39. return $this->where(['id' => $id])->find();
  40. }
  41. }