12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\common\model;
- use think\Model;
- use think\Cookie;
- class Consume extends Model
- {
- // 表名
- protected $table = 'consume';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [
- ];
- //当前链接的user_id分库
- protected $connectUserId = null;
- /**
- * 设置分库链接数据
- * @param $user_id
- * @return $this
- */
- public function setConnect($user_id)
- {
- if ($this->connectUserId != $user_id) {
- $database = get_db_connect($this->table, $user_id);
- $this->setTable($database['table']);
- $this->connect($database);
- $this->connectUserId = $user_id;
- }
- return $this;
- }
- }
|