ShareSource.php 838 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ShareSource extends Model
  5. {
  6. // 表名
  7. protected $table = 'user.share_source';
  8. // 自动写入时间戳字段
  9. // protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'created_at';
  12. protected $updateTime = 'updated_at';
  13. //当前链接的user_id分库
  14. protected $connectUserId = null;
  15. /**
  16. * 设置分库链接数据
  17. * @param $userId
  18. * @return $this
  19. */
  20. public function setConnect($userId)
  21. {
  22. if ($this->connectUserId != $userId) {
  23. $database = get_db_connect($this->table, $userId);
  24. $this->setTable($database['table']);
  25. $this->connect($database);
  26. $this->connectUserId = $userId;
  27. }
  28. return $this;
  29. }
  30. }