BaseModel.php 1.2 KB

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