格式化代码

This commit is contained in:
iVampireSP.com 2023-01-17 04:42:59 +08:00
parent 5508c9d850
commit fdacec1882
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 38 additions and 39 deletions

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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;
}
}
);
}
}