12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model as BaseModel;
- /**
- * Class Model
- *
- * @package App\Models
- * @method increment($column, $amount = 1, array $extra = [])
- */
- class Model extends BaseModel
- {
- /** @var int 分表的粒度 */
- public const SLICE = 10000;
- /** @var int 用来分表的key */
- protected $sliceKey = 0;
- /**
- * 设置用来分表的key
- * @param int $sliceKey 用来分表的key(目前仅支持int型分表)
- */
- public function setSliceKey(int $sliceKey)
- {
- $this->sliceKey = $sliceKey;
- if ($this->sliceKey) {
- $index = intdiv($this->sliceKey, self::SLICE);
- $this->table = "{$this->table}_{$index}";
- }
- }
- }
|