'男', 2 => '女' ]; /** * {@inheritdoc} */ public static function tableName() { return '{{%user_extra}}'; } /** * {@inheritdoc} */ public function rules() { return [ [['user_id'], 'required'], [['user_id', 'sex', 'created_at', 'updated_at','follow_count','fans_count'], 'integer'], [['id_card'], 'string', 'max' => 30], [['province', 'city', 'area', 'remark', 'personal_home_bg', 'personal_signature', 'town'], 'string', 'max' => 255], [['birthday'], 'string', 'max' => 50], [['target_weight', 'body_weight', 'body_height'], 'number'], [['wechat'], 'safe'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'user_id' => 'User ID', 'sex' => '性别:1:男;2:女', 'id_card' => '身份证', 'wechat' => '微信号', 'birthday' => '出生年月日', 'province' => '省', 'city' => '市', 'area' => '区', 'town' => '镇', 'remark' => '备注', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'personal_home_bg' => '个人主页背景', 'personal_signature' => '个人主页个性签名', 'follow_count' => '关注人数', 'fans_count' => '粉丝人数', ]; } /** * 关联用户表 * @Author: lun * @DateTime: 2021/12/22 0022 10:32 * @Copyright: copyright (c) 2021 广东七件事集团 * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } /** * 保存数据 * @param array $params * @return bool|UserExtra */ public static function setData(array $params) { try { if (!empty($params['user_id'])) { $model = self::findOne(['user_id' => $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; } } /** * 获取额外参数 * @Author: lun * @DateTime: 2021/12/3 0003 10:00 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $user_id * @return array|bool */ public static function getUserExtra($user_id) { try { $field = "sex,id_card,birthday,wechat,province,city,area,town,personal_home_bg,personal_signature"; $model = self::find()->select($field)->where(['user_id' => $user_id])->one(); if (empty($model)) { $model = new self(); $model->user_id = $user_id; $model->loadDefaultValues(); if (!$model->save()) throw new Exception($model->getErrorMessage()); } return $model->toArray(); } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } }