83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
use app\components\SysConst;
|
||
|
||
/**
|
||
* This is the model class for table "{{%user_oauth}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property string $type 类型
|
||
* @property int $user_id 用户ID
|
||
* @property string $openid OPENID
|
||
* @property string|null $unionid UNIONID
|
||
* @property string|null $nickname 昵称
|
||
* @property string|null $avatar_url 头像
|
||
* @property int $is_delete 是否删除,0=否,1=是
|
||
* @property int $created_at 添加时间
|
||
*/
|
||
class UserOauth extends \yii\db\ActiveRecord
|
||
{
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%user_oauth}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['openid', 'unionid', 'nickname', 'avatar_url'], 'trim',],
|
||
[['cx_mch_id', 'user_id', 'is_delete', 'created_at'], 'integer'],
|
||
[['user_id', 'openid'], 'required'],
|
||
[['openid', 'unionid', 'nickname'], 'string', 'max' => 256],
|
||
[['type'], 'string', 'max' => 16],
|
||
[['avatar_url'], 'string', 'max' => 2048],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'type' => '类型',
|
||
'user_id' => '用户ID',
|
||
'openid' => 'OPENID',
|
||
'unionid' => 'UNIONID',
|
||
'nickname' => '昵称',
|
||
'avatar_url' => '头像',
|
||
'is_delete' => '是否删除,0=否,1=是',
|
||
'created_at' => '添加时间',
|
||
];
|
||
}
|
||
|
||
public function beforeSave($insert) {
|
||
if(parent::beforeSave($insert)){
|
||
if($this->isNewRecord){
|
||
$this->created_at = time();
|
||
}
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function getUser()
|
||
{
|
||
return $this->hasOne(User::className(),['id' => 'user_id']);
|
||
}
|
||
}
|