| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_user_relationship_log".
- *
- *
- * @property int $id
- * @property int $user_id 会员id
- * @property int $before_id 修改前的上级id
- * @property int $after_id 修改后的上级id
- * @property int $created_at
- * @property int $updated_at
- */
- class UserRelationshipLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_relationship_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id', 'before_id', 'after_id', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => '会员id',
- 'before_id' => '修改前的上级id',
- 'after_id' => '修改后的上级id',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @param array $params
- * @return bool|object
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['user_id'])) {
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 关联修改前的直推上级
- * @return \yii\db\ActiveQuery
- */
- public function getBeforeParent()
- {
- return $this->hasOne(User::class, ['id' => 'before_id']);
- }
- /**
- * 关联修改后的直推上级
- * @return \yii\db\ActiveQuery
- */
- public function getAfterParent()
- {
- return $this->hasOne(User::class, ['id' => 'after_id']);
- }
- }
|