cxgj/models/UserOauth.php
2023-11-27 09:45:13 +08:00

83 lines
2.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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']);
}
}