diff --git a/app/Http/Controllers/Web/AffiliateController.php b/app/Http/Controllers/Web/AffiliateController.php index cdee6f6..6d57322 100644 --- a/app/Http/Controllers/Web/AffiliateController.php +++ b/app/Http/Controllers/Web/AffiliateController.php @@ -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. */ diff --git a/app/Models/User.php b/app/Models/User.php index 3f674ed..3579207 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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); + } + /** * 获取用户的身份证号 */