Skip to content

Commit 693ccfa

Browse files
done
1 parent 98aa0c8 commit 693ccfa

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/Repositories/OrderRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public function setRefunded ( Order $order, float $amount ) {
108108
}
109109
public function setPaid ( Order $order, float $amount ) {
110110

111+
app(\App\Services\SettingService::class)->handleCommissions($order->user, ['order', 'referral'], $amount);
112+
111113
return parent::update($order->id, [
112114
'paid' => true,
113115
'paid_amount' => positive($order->paid_amount) + positive($amount),

app/Services/AuthService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function __construct(
1414
protected UserRepository $userRepository,
1515
protected ResetRepository $resetRepository,
1616
protected SocialRepository $socialRepository,
17-
protected VerificationService $verificationService
17+
protected VerificationService $verificationService,
18+
protected SettingService $settingService
1819
) { parent::__construct($userRepository); }
1920

2021
public function info ( User $user ) {
@@ -32,7 +33,10 @@ public function verify ( User $user, string $type, string $over ) {
3233
public function register ( string $role, array $data, bool $verify = true ) {
3334

3435
if ( $this->userRepository->emailExists($data['email'] ?? '') ) return failed(['email' => 'email exists']);
36+
3537
$user = $this->userRepository->createUser( array_merge($data, ['role' => $role]) );
38+
$this->settingService->handleCommission($user, 'register');
39+
3640
return $verify ? $this->verify($user, 'auth', 'email') : $this->info($user);
3741

3842
}

app/Services/SettingService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public function contextCommission ( Setting $commission, User $user, float $amou
6565
'user' => $user,
6666
'wallet' => $wallet,
6767
'coupon' => $coupon,
68-
'key' => $key,
69-
'type' => $type,
7068
'balance' => $balance,
7169
'amount' => $amount,
7270
'points' => $points,
71+
'type' => $type,
72+
'key' => $key,
7373
];
7474

7575
}

app/Services/SubscriptionService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(
1515
protected SubscriptionRepository $subscriptionRepository,
1616
protected WalletRepository $walletRepository,
1717
protected PlanRepository $planRepository,
18+
protected SettingService $settingService
1819
) { parent::__construct($subscriptionRepository); }
1920

2021
public function ownerPay ( Store $store, float $price ) {
@@ -88,6 +89,8 @@ public function subscribe ( Store $store, Plan $plan, array $data = [] ) {
8889
if ( $price && !$this->storePay($store, $price) ) throwError('pay', "chain store can't pay");
8990

9091
$plan->newUsage('max_subscriptions');
92+
$this->settingService->handleCommission($store->owner, 'subscription', $price);
93+
9194
return $this->subscriptionRepository->create(array_merge($data, ['store_id' => $store->id]));
9295

9396
}

routes/apis/admin.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@
129129
Route::get('test', function () {
130130

131131
$order = \App\Models\Order::find(1);
132-
dump(app(\App\Services\SettingService::class)->handleCommission($order->user, 'referral', $order->paid_amount, false));
133-
134-
$order = \App\Models\Order::find(1);
135-
dump(app(\App\Services\SettingService::class)->handleCommission($order->user, 'order', $order->paid_amount, false));
132+
dump(app(\App\Services\SettingService::class)->handleCommissions($order->user, ['order', 'referral'], $order->paid_amount, false));
136133

137134
$user = \App\Models\User::find(1);
138135
dump(app(\App\Services\SettingService::class)->handleCommission($user, 'register', null, false));

0 commit comments

Comments
 (0)