// +---------------------------------------------------------------------- namespace App\Models; /** * 会员-模型 * @author laravel开发员 * @since 2020/11/11 * Class MemberModel * @package App\Models */ class MemberModel extends BaseModel { // 设置数据表 protected $table = 'member'; protected $appends = ['time_text','idcard_text','mobile_text']; // 头像 public function getAvatarAttribute($value) { $value = $value ? get_image_url($value) : ''; return $value; } // 时间 public function getTimeTextAttribute() { return $this->create_time? datetime($this->create_time,'Y-m-d H:i:s') : ''; } // 身份证 public function getIdcardTextAttribute() { return $this->idcard? substr($this->idcard,0,4).'**************' : ''; } /** * @return array */ public function getmobileTextAttribute() { return $this->mobile? format_mobile($this->mobile):''; } /** * 收益账户 * @return \Illuminate\Database\Eloquent\Relations\hasOne */ public function account() { return $this->hasOne(AccountStatisticsModel::class, 'user_id','id'); } /** * 推荐人 */ public function parent() { return $this->hasOne(MemberModel::class, 'id','parent_id') ->with(['account']) ->where(['status'=>1,'mark'=>1]) ->select(['id', 'nickname','realname','avatar', 'mobile','company','department','position', 'status']); } /** * 邀请用户 */ public function invites() { return $this->hasOne(MemberModel::class, 'parent_id','id') ->with(['account']) ->where(['mark'=>1]) ->select(['id', 'nickname','avatar', 'realname','company','parent_id','department','position', 'mobile', 'status']); } /** * 获取会员信息 * @param int $id 会员ID * @return array|string * @author laravel开发员 * @since 2020/11/11 */ public function getInfo($id) { $info = parent::getInfo($id); // TODO: Change the autogenerated stub if ($info) { // 头像 if ($info['avatar']) { $info['avatar'] = get_image_url($info['avatar']); } } return $info; } }