From fdacec188217556dbd34f03e5c3c6a2857f6b042 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 17 Jan 2023 04:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Public/RealNameController.php | 1 - app/Models/Transaction.php | 13 ++-- app/Models/User.php | 63 +++++++++---------- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Public/RealNameController.php b/app/Http/Controllers/Public/RealNameController.php index c56b6cf..d21aed5 100644 --- a/app/Http/Controllers/Public/RealNameController.php +++ b/app/Http/Controllers/Public/RealNameController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\Public; use App\Http\Controllers\Controller; -use App\Models\Transaction; use App\Models\User; use App\Support\RealNameSupport; use Illuminate\Http\JsonResponse; diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index b82a0cd..6b29ef1 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -47,12 +47,6 @@ class Transaction extends Model 'module_id', ]; - public function scopeThisUser($query) - { - return $query->where('user_id', auth()->id()); - } - - // on create protected static function boot() { parent::boot(); @@ -80,4 +74,11 @@ protected static function boot() $transaction->expired_at = Carbon::now()->addSeconds(7)->toString(); }); } + + // on create + + public function scopeThisUser($query) + { + return $query->where('user_id', auth()->id()); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 70bfdb2..71ff9f0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -120,24 +120,6 @@ private function getBirthdayFromIdCard(): string return $year . '-' . $month . '-' . $day; } - /** - * 获取用户的身份证号 - * - * @return Attribute - */ - protected function idCard(): Attribute - { - return Attribute::make( - function ($value) { - try { - return Crypt::decryptString($value); - } catch (DecryptException) { - return $value; - } - } - ); - } - public function isAdult(): bool { // 如果 birthday_at 为空,那么就返回 false @@ -167,6 +149,22 @@ public function selectPublic(): User return $this->select(['id', 'name', 'email_md5', 'created_at']); } + public function startTransfer(User $to, string $amount, string|null $description) + { + $description_from = "转账给 $to->name($to->email)"; + $description_to = "收到 $this->name($this->email) 的转账"; + + if ($description) { + $description_from .= ",备注:$description"; + $description_to .= ",备注:$description"; + } + + $this->reduce($amount, $description_from, true); + + $to->charge($amount, 'transfer', $description_to); + + return $this->balance; + } /** * 扣除费用 @@ -253,20 +251,21 @@ public function charge(string $amount = "0", string $payment = 'console', string return $this->balance; } - public function startTransfer(User $to, string $amount, string|null $description) + /** + * 获取用户的身份证号 + * + * @return Attribute + */ + protected function idCard(): Attribute { - $description_from = "转账给 $to->name($to->email)"; - $description_to = "收到 $this->name($this->email) 的转账"; - - if ($description) { - $description_from .= ",备注:$description"; - $description_to .= ",备注:$description"; - } - - $this->reduce($amount, $description_from, true); - - $to->charge($amount, 'transfer', $description_to); - - return $this->balance; + return Attribute::make( + function ($value) { + try { + return Crypt::decryptString($value); + } catch (DecryptException) { + return $value; + } + } + ); } }