NovelUserPorperty.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. class NovelUserPorperty extends Model
  7. {
  8. use TableSuffix;
  9. protected $table = 'novel_user_properties';
  10. protected $fillable = [
  11. 'uid',
  12. 'category_id',
  13. 'category',
  14. 'sex',
  15. ];
  16. public static function model(string $date)
  17. {
  18. self::suffix($date);
  19. $model = new self;
  20. return $model;
  21. }
  22. /**
  23. * 创建表
  24. */
  25. public function createTableIfNotExists()
  26. {
  27. if (!Schema::hasTable($this->table)) {
  28. Schema::create($this->table, function (Blueprint $table) {
  29. $table->increments('id');
  30. $table->integer('uid');
  31. $table->integer('category_id');
  32. $table->string('category');
  33. $table->integer('sex');
  34. $table->timestamps();
  35. $table->index('uid', 'idx_uid');
  36. });
  37. }
  38. }
  39. /**
  40. * 删除三天前的表
  41. */
  42. public static function dropTable()
  43. {
  44. $date = date('Ymd', strtotime('-3 days'));
  45. Schema::dropIfExists('novel_user_properties' . $date);
  46. }
  47. }