UserRelationshipLog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace common\models\user;
  3. use common\models\base\BaseActiveRecord;
  4. use PHPUnit\Util\Exception;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_user_relationship_log".
  8. *
  9. *
  10. * @property int $id
  11. * @property int $user_id 会员id
  12. * @property int $before_id 修改前的上级id
  13. * @property int $after_id 修改后的上级id
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class UserRelationshipLog extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%user_relationship_log}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['user_id', 'before_id', 'after_id', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'user_id' => '会员id',
  43. 'before_id' => '修改前的上级id',
  44. 'after_id' => '修改后的上级id',
  45. 'created_at' => 'Created At',
  46. 'updated_at' => 'Updated At',
  47. ];
  48. }
  49. /**
  50. * 保存数据
  51. * @param array $params
  52. * @return bool|object
  53. */
  54. public static function setData(array $params)
  55. {
  56. try {
  57. if (!empty($params['user_id'])) {
  58. if (empty($model)) {
  59. $model = new self();
  60. $model->loadDefaultValues();
  61. }
  62. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  63. return $model;
  64. }
  65. } catch (Exception $e) {
  66. self::$static_error = $e->getMessage();
  67. return false;
  68. }
  69. }
  70. /**
  71. * 关联修改前的直推上级
  72. * @return \yii\db\ActiveQuery
  73. */
  74. public function getBeforeParent()
  75. {
  76. return $this->hasOne(User::class, ['id' => 'before_id']);
  77. }
  78. /**
  79. * 关联修改后的直推上级
  80. * @return \yii\db\ActiveQuery
  81. */
  82. public function getAfterParent()
  83. {
  84. return $this->hasOne(User::class, ['id' => 'after_id']);
  85. }
  86. }