BaseModel.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. use think\db\BaseQuery;
  4. use think\Model;
  5. /**
  6. * Class BaseModel
  7. * @package app\common\model
  8. * @author xaboy
  9. * @day 2020-03-30
  10. */
  11. abstract class BaseModel extends Model
  12. {
  13. protected $updateTime = false;
  14. /**
  15. * @return string
  16. * @author xaboy
  17. * @day 2020-03-30
  18. */
  19. abstract public static function tablePk():? string;
  20. /**
  21. * @return string
  22. * @author xaboy
  23. * @day 2020-03-30
  24. */
  25. abstract public static function tableName(): string;
  26. /**
  27. * BaseModel constructor.
  28. * @param array $data
  29. */
  30. public function __construct(array $data = [])
  31. {
  32. $this->pk = static::tablePk();
  33. $this->name = static::tableName();
  34. parent::__construct($data);
  35. }
  36. /**
  37. * @return static
  38. */
  39. public static function getInstance(): self
  40. {
  41. return new static();
  42. }
  43. /**
  44. * @param array $scope
  45. * @return BaseQuery
  46. * @author xaboy
  47. * @day 2020-03-30
  48. */
  49. public static function getDB(array $scope = [])
  50. {
  51. return self::getInstance()->db($scope);
  52. }
  53. }