// +---------------------------------------------------------------------- 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','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 getLoginTimeAttribute($value) { return $value? datetime($value,'Y-m-d H:i:s') : ''; } // 报单积分 public function getBdScoreAttribute($value) { return $value? floatval($value) : 0; } // 绿色积分 public function getLsScoreAttribute($value) { return $value? floatval($value) : 0; } // 累计收益 public function getBonusTotalAttribute($value) { return $value? floatval($value) : 0; } // 累计提现 public function getWithdrawTotalAttribute($value) { return $value? floatval($value) : 0; } // 累计资产提现 public function getWithdrawPropertyAttribute($value) { return $value? floatval($value) : 0; } // 数字资产 public function getPropertyAttribute($value) { return $value? floatval($value) : 0; } /** * @return array */ public function getmobileTextAttribute() { return $this->mobile? format_mobile($this->mobile):''; } /** * 会员等级数据 */ public function levelData() { return $this->hasOne(MemberLevelModel::class, 'id','member_level') ->where(['mark'=>1]) ->select(['id', 'name','upper_count','bonus','status']); } /** * 推荐人 */ public function parent() { return $this->hasOne(MemberModel::class, 'id','parent_id') ->where(['status'=>1,'mark'=>1]) ->select(['id', 'nickname','realname','avatar','member_level','parent_id','point_id', 'mobile', 'status']); } /** * 邀请用户 */ public function invites() { return $this->hasMany(MemberModel::class, 'parent_id','id') ->where(['mark'=>1]) ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']); } /** * 节点推荐人 */ public function point() { return $this->hasOne(MemberModel::class, 'id','point_id') ->where(['status'=>1,'mark'=>1]) ->select(['id', 'nickname','parent_id','point_id','realname','avatar', 'mobile', 'status']); } /** * 下级节点 */ public function points() { return $this->hasOne(MemberModel::class, 'point_id','id') ->where(['mark'=>1]) ->select(['id', 'nickname','avatar', 'realname','parent_id','point_id', 'mobile', 'status']); } /** * 获取会员信息 * @param int $id 会员ID * @return array|string * @author laravel开发员 * @since 2020/11/11 */ public function getInfo($id) { $info = $this->where(['id'=>$id])->first(); // TODO: Change the autogenerated stub if ($info) { // 头像 if ($info['avatar']) { $info['avatar'] = get_image_url($info['avatar']); } } return $info; } }