优化 代码

This commit is contained in:
iVampireSP.com 2023-02-28 18:04:58 +08:00
parent 34892e0511
commit cd2a77de85
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 22 additions and 14 deletions

View File

@ -33,6 +33,20 @@ public function index(Request $request): View|RedirectResponse
return view('affiliates.index', compact('affiliateUsers', 'affiliate'));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
if (auth()->user()->affiliate) {
return redirect()->route('affiliates.index')->with('error', '您已经激活了推介计划。');
}
$request->user('web')->affiliate()->create();
return redirect()->route('affiliates.index')->with('success', '欢迎您,并感谢您。');
}
/**
* Show the form for creating a new resource.
*/
@ -48,20 +62,6 @@ public function create(Request $request): View|RedirectResponse
return view('affiliates.create', compact('user'));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
if (auth()->user()->affiliate) {
return redirect()->route('affiliates.index')->with('error', '您已经激活了推介计划。');
}
$request->user('web')->affiliate()->create();
return redirect()->route('affiliates.index')->with('success', '欢迎您,并感谢您。');
}
/**
* Display the specified resource.
*/

View File

@ -200,6 +200,9 @@ public function reduce(string|null $amount = '0', string $description = '消费'
return $this->balance;
}
/**
* @throws BalanceNotEnoughException
*/
return Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) {
$this->refresh();
@ -281,6 +284,11 @@ public function getCostPrice(string $price): string
return $this->user_group->getCostPrice($price);
}
public function subscriptions(): HasMany
{
return $this->hasMany(Subscription::class);
}
/**
* 获取用户的身份证号
*/