BaseModel.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model;
  12. use think\db\BaseQuery;
  13. use think\Model;
  14. /**
  15. * Class BaseModel
  16. * @package app\common\model
  17. * @author xaboy
  18. * @day 2020-03-30
  19. */
  20. abstract class BaseModel extends Model
  21. {
  22. protected $updateTime = false;
  23. /**
  24. * @return string
  25. * @author xaboy
  26. * @day 2020-03-30
  27. */
  28. abstract public static function tablePk():? string;
  29. /**
  30. * @return string
  31. * @author xaboy
  32. * @day 2020-03-30
  33. */
  34. abstract public static function tableName(): string;
  35. /**
  36. * BaseModel constructor.
  37. * @param array $data
  38. */
  39. public function __construct(array $data = [])
  40. {
  41. $this->pk = static::tablePk();
  42. $this->name = static::tableName();
  43. parent::__construct($data);
  44. }
  45. /**
  46. * @return static
  47. */
  48. public static function getInstance(): self
  49. {
  50. return new static();
  51. }
  52. /**
  53. * @param array $scope
  54. * @return BaseQuery
  55. * @author xaboy
  56. * @day 2020-03-30
  57. */
  58. public static function getDB(array $scope = [])
  59. {
  60. return self::getInstance()->db($scope);
  61. }
  62. }