commission from first/every purchase
This commit is contained in:
parent
b69850cb21
commit
86cf2981c1
4 changed files with 40 additions and 1 deletions
app
database/seeders/Seeds
resources/views/admin/settings/tabs
|
@ -40,6 +40,7 @@ class Misc
|
|||
'enable_referral' => 'nullable|string',
|
||||
'referral_reward' => 'nullable|numeric',
|
||||
'referral_allowed' => 'nullable|string',
|
||||
'always_give_commission' => 'nullable|string',
|
||||
'referral_percentage' => 'nullable|numeric',
|
||||
'referral_mode' => 'nullable|string',
|
||||
'ticket_enabled' => 'nullable|string',
|
||||
|
@ -87,6 +88,7 @@ class Misc
|
|||
"SETTINGS::REFERRAL::REWARD" => "referral_reward",
|
||||
"SETTINGS::REFERRAL::ALLOWED" => "referral_allowed",
|
||||
"SETTINGS::REFERRAL:MODE" => "referral_mode",
|
||||
"SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION" => "always_give_commission",
|
||||
"SETTINGS::REFERRAL:PERCENTAGE" => "referral_percentage",
|
||||
"SETTINGS::TICKET:ENABLED" => "ticket_enabled"
|
||||
|
||||
|
|
|
@ -184,12 +184,28 @@ class PaymentController extends Controller
|
|||
$user->increment('server_limit', $shopProduct->quantity);
|
||||
}
|
||||
|
||||
//give referral commission always
|
||||
if((config("SETTINGS::REFERRAL:MODE") == "commission" || config("SETTINGS::REFERRAL:MODE") == "both") && $shopProduct->type=="Credits" && config("SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION") == "true"){
|
||||
if($ref_user = DB::table("user_referrals")->where('registered_user_id', '=', $user->id)->first()){
|
||||
$ref_user = User::findOrFail($ref_user->referral_id);
|
||||
$increment = number_format($shopProduct->quantity*(PartnerDiscount::getCommission($ref_user->id))/100,0,"","");
|
||||
$ref_user->increment('credits', $increment);
|
||||
|
||||
//LOGS REFERRALS IN THE ACTIVITY LOG
|
||||
activity()
|
||||
->performedOn($user)
|
||||
->causedBy($ref_user)
|
||||
->log('gained '. $increment.' '.config("SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME").' for commission-referral of '.$user->name.' (ID:'.$user->id.')');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//update role give Referral-reward
|
||||
if ($user->role == 'member') {
|
||||
$user->update(['role' => 'client']);
|
||||
|
||||
if((config("SETTINGS::REFERRAL:MODE") == "commission" || config("SETTINGS::REFERRAL:MODE") == "both") && $shopProduct->type=="Credits"){
|
||||
//give referral commission only on first purchase
|
||||
if((config("SETTINGS::REFERRAL:MODE") == "commission" || config("SETTINGS::REFERRAL:MODE") == "both") && $shopProduct->type=="Credits" && config("SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION") == "false"){
|
||||
if($ref_user = DB::table("user_referrals")->where('registered_user_id', '=', $user->id)->first()){
|
||||
$ref_user = User::findOrFail($ref_user->referral_id);
|
||||
$increment = number_format($shopProduct->quantity*(PartnerDiscount::getCommission($ref_user->id))/100,0,"","");
|
||||
|
|
|
@ -479,6 +479,13 @@ class SettingsSeeder extends Seeder
|
|||
'type' => 'string',
|
||||
'description' => 'Enable or disable the referral system'
|
||||
]);
|
||||
Settings::firstOrCreate([
|
||||
'key' => 'SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION',
|
||||
], [
|
||||
'value' =>"false",
|
||||
'type' => 'string',
|
||||
'description' => 'Whether referrals get percentage commission only on first purchase or on every purchase'
|
||||
]);
|
||||
Settings::firstOrCreate([
|
||||
'key' => 'SETTINGS::REFERRAL::REWARD',
|
||||
], [
|
||||
|
|
|
@ -222,6 +222,20 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="custom-control mb-3 p-0">
|
||||
<div class="col m-0 p-0 d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<input value="true" id="always_give_commission" name="always_give_commission"
|
||||
{{ config('SETTINGS::REFERRAL::ALWAYS_GIVE_COMMISSION') == 'true' ? 'checked' : '' }}
|
||||
type="checkbox">
|
||||
<label for="always_give_commission">{{ __('Always give commission') }}:
|
||||
<i data-toggle="popover" data-trigger="hover"
|
||||
data-content="{{ __('Should users recieve the commission only for the first payment, or for every payment?') }}" class="fas fa-info-circle"></i>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="custom-control mb-3 p-0">
|
||||
<label for="referral_mode">{{ __('Mode') }}:
|
||||
<i data-toggle="popover" data-trigger="hover"
|
||||
|
|
Loading…
Add table
Reference in a new issue