AbstractTreePath.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\librarys\shareTree\models;
  8. use yii\base\InvalidConfigException;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. use yii\db\Expression;
  12. /**
  13. * @property int $parent_id
  14. * @property int $child_id
  15. * @property int $nearest_parent_id
  16. * @property int $parent_level
  17. * @property int $child_level
  18. * @property string $created_at
  19. */
  20. abstract class AbstractTreePath extends ActiveRecord
  21. {
  22. /**
  23. * @inheritDoc
  24. */
  25. public static function tableName(): string
  26. {
  27. throw new InvalidConfigException('请指定用于存储父子关系的表名称');
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. public static function primaryKey()
  33. {
  34. return ['parent_id', 'child_id'];
  35. }
  36. /**
  37. * @inheritDoc
  38. */
  39. public function behaviors(): array
  40. {
  41. return [
  42. [
  43. 'class' => TimestampBehavior::class,
  44. 'createdAtAttribute' => 'created_at',
  45. 'updatedAtAttribute' => null,
  46. 'value' => new Expression('NOW()'),
  47. ],
  48. ];
  49. }
  50. }