'int', 'restrict_recharge' => 'int', 'restrict_balance_purchase' => 'int', 'restrict_invite' => 'int', 'restrict_ticket' => 'int', 'restrict_transaction_records' => 'int', 'restriction_updated_at' => 'int', 'restriction_operator_id' => 'int', 'login_session_version' => 'int', 'is_admin' => 'boolean', ]; public function getGravatarAttribute() { $hash = md5(strtolower(trim($this->attributes['email']))); return "https://secure.gravatar.com/avatar/".$hash; } public function getAffLink() { if (!$this->canInvite()) { return ''; } $domain = trim((string) ($_SERVER['HTTP_HOST'] ?? '')); if ($domain === '' || preg_match('/[\x00-\x20\x7F]/', $domain) === 1) { return ''; } $code = ReferralService::codeForUser($this); if ($code === null || ReferralService::normalizeCode($code->code) === '') { return ''; } return 'https://' . $domain . '/auth/register?aff=' . rawurlencode((string) $code->code); } public function canInvite() { return (int) $this->enable === 1 && !UserFeatureRestrictionService::isInviteRestricted($this); } public function isAdmin() { return $this->attributes['is_admin']; } public function regDate() { return $this->attributes['reg_date']; } public function updatePassword($pwd) { $this->pass = Hash::passwordHash($pwd); if (!$this->save()) { throw new \RuntimeException('密码保存失败'); } \App\Services\LoginSessionRevocationService::revokeUser($this); } public function inviteCodes() { $uid = $this->attributes['id']; return InviteCode::where('user_id', $uid)->get(); } public function ref_by_user() { $uid = $this->attributes['ref_by']; return User::where('id', $uid)->first(); } public function invitedMemberTotal() { return User::where('ref_by', $this->attributes['id'])->count(); } public function inviteMoneyTotal() { $uid = $this->attributes['id']; $aff_money = 0; $paybacks = Payback::where("ref_by", $uid)->get(); foreach ($paybacks as $payback) { $aff_money += $payback->ref_get; } return $aff_money; } public function yesterdayIncome() { return Code::where('usedatetime','like',date('Y-m-d%',strtotime("-1 days")))->sum('number'); } public function todayIncome() { return Code::where('usedatetime','like',date('Y-m-d%'))->sum('number'); } public function thisMonthIncome() { return Code::where('usedatetime','like',date('Y-m%'))->sum('number'); } public function lastMonthIncome() { return Code::where('usedatetime','like',date('Y-m%',strtotime("-1 months")))->sum('number'); } public function totalIncome() { return Code::where('usedatetime','like',date('%'))->sum('number'); } public function kill_user() { $result = (new UserDataDeletionService())->deleteUsers([(int) $this->attributes['id']]); return (int) $result['deleted'] === 1; } }