宝体数据调用接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 lines
1.2 KiB

<?php
namespace app\common\model;
/**
* 用户模型类
* Class User
* @package app\common\model
*/
class User extends BaseModel
{
protected $name = 'user';
// 性别
private $gender = ['未知', '男', '女'];
/**
* 关联收货地址表
* @return \think\model\relation\HasMany
*/
public function address()
{
return $this->hasMany('UserAddress');
}
/**
* 关联收货地址表 (默认地址)
* @return \think\model\relation\BelongsTo
*/
public function addressDefault()
{
return $this->belongsTo('UserAddress', 'address_id');
}
/**
* 显示性别
* @param $value
* @return mixed
*/
public function getGenderAttr($value)
{
return $this->gender[$value];
}
/**
* 获取用户信息
* @param $where
* @return null|static
* @throws \think\exception\DbException
*/
public static function detail($where)
{
$filter = ['is_delete' => 0];
if (is_array($where)) {
$filter = array_merge($filter, $where);
} else {
$filter['user_id'] = (int)$where;
}
return self::get($filter, ['address', 'addressDefault']);
}
}