| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace common\models\user;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use phpDocumentor\Reflection\Types\False_;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_user_extra".
- *
- *
- * @property int $id
- * @property int $user_id
- * @property int $sex 性别:1:男;2:女
- * @property string $id_card 身份证
- * @property string $wechat 微信号
- * @property string $birthday 出生年月日
- * @property string $province 省
- * @property string $city 市
- * @property string $area 区
- * @property string $town 镇
- * @property string $remark 备注
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property int $fans_count 更新时间
- * @property int $follow_count 更新时间
- * @property string|null $personal_home_bg 个人主页背景
- * @property string|null $personal_signature 个人主页个性签名
- * @property float $target_weight 个人主页个性签名
- * @property float $body_weight 个人主页个性签名
- * @property float $body_height 个人主页个性签名
- */
- class UserExtra extends BaseActiveRecord
- {
- const SEX_ARR = [
- 1 => '男',
- 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;
- }
- }
- }
|