From 7754c2098b59a5495d818a0543f4dbb0bf98b943 Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Sat, 24 Jun 2023 16:04:52 +0700 Subject: [PATCH] fix afiilate --- app/Http/Controllers/SettingController.php | 29 ++-- database/seeders/InstallationSeed.php | 10 +- resources/js/Components/FormInputNumeric.jsx | 5 +- resources/js/Pages/Setting/Affilate.jsx | 147 +++++++++++++++++++ resources/js/Pages/Setting/Index.jsx | 116 ++++----------- resources/js/Pages/Setting/Payment.jsx | 5 +- 6 files changed, 207 insertions(+), 105 deletions(-) create mode 100644 resources/js/Pages/Setting/Affilate.jsx diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 0830d6f..1cde4dd 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\CustomerLevel; use App\Models\Setting; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; @@ -94,33 +95,33 @@ class SettingController extends Controller { $setting = Setting::all(); - return inertia('Setting/Payment', [ + return inertia('Setting/Affilate', [ 'setting' => $setting, - 'midtrans_notification_url' => route('api.midtrans.notification'), + 'levels' => CustomerLevel::all() ]); } public function updateAffilate(Request $request) { $request->validate([ - 'MIDTRANS_SERVER_KEY' => 'required|string', - 'MIDTRANS_CLIENT_KEY' => 'required|string', - 'MIDTRANS_MERCHANT_ID' => 'required|string', - 'MIDTRANS_ADMIN_FEE' => 'required|numeric', - 'MIDTRANS_ENABLED' => 'required|in:0,1', - 'midtrans_logo_file' => 'nullable|image', + 'AFFILATE_ENABLED' => 'required|in:0,1', + 'AFFILATE_POIN_AMOUNT' => 'required|numeric', + 'AFFILATE_DOWNLINE_POIN_AMOUNT' => 'required|numeric', + 'AFFILATE_SHARE_REFFERAL_CODE' => 'required|string', + 'AFFILATE_ALLOWED_LEVELS' => 'required|array', + 'AFFILATE_ALLOWED_LEVELS.*.key' => 'required|exists:customer_levels,key', ]); DB::beginTransaction(); - foreach ($request->except(['midtrans_logo_file']) as $key => $value) { + foreach ($request->except(['AFFILATE_ALLOWED_LEVELS']) as $key => $value) { Setting::where('key', $key)->update(['value' => $value]); } - if ($request->hasFile('midtrans_logo_file')) { - $file = $request->file('midtrans_logo_file'); - $file->store('uploads', 'public'); - Setting::where('key', 'MIDTRANS_LOGO')->update(['value' => $file->hashName('uploads')]); - } + $allowedLevel = collect($request->AFFILATE_ALLOWED_LEVELS)->toArray(); + + Setting::where('key', 'AFFILATE_ALLOWED_LEVELS')->update([ + 'value' => json_encode($allowedLevel) + ]); Cache::flush(); diff --git a/database/seeders/InstallationSeed.php b/database/seeders/InstallationSeed.php index aec83af..cecc0a8 100644 --- a/database/seeders/InstallationSeed.php +++ b/database/seeders/InstallationSeed.php @@ -20,12 +20,19 @@ class InstallationSeed extends Seeder public function settings() { $settings = [ + // general ['key' => 'OPEN_WEBSITE_NAME', 'value' => 'Welcome to Voucher App', 'type' => 'text'], + ['key' => 'SHARE_TEXT', 'value' => '', 'type' => 'text'], + + // affilate ['key' => 'AFFILATE_ENABLED', 'value' => '0', 'type' => 'checkbox'], ['key' => 'AFFILATE_POIN_AMOUNT', 'value' => '0', 'type' => 'text'], ['key' => 'AFFILATE_DOWNLINE_POIN_AMOUNT', 'value' => '0', 'type' => 'text'], + ['key' => 'AFFILATE_SHARE_REFFERAL_CODE', 'value' => 'Yuk daftar dapatkan bonus poin', 'type' => 'text'], + ['key' => 'AFFILATE_ALLOWED_LEVELS', 'value' => json_encode([]), 'type' => 'json'], + // midtrans ['key' => 'MIDTRANS_SERVER_KEY', 'value' => 'SB-Mid-server-UA0LQbY4aALV0CfLLX1v7xs8', 'type' => 'text'], ['key' => 'MIDTRANS_CLIENT_KEY', 'value' => 'SB-Mid-client-xqqkspzoZOM10iUG', 'type' => 'text'], ['key' => 'MIDTRANS_MERCHANT_ID', 'value' => 'G561244367', 'type' => 'text'], @@ -33,8 +40,7 @@ class InstallationSeed extends Seeder ['key' => 'MIDTRANS_ENABLED', 'value' => '0', 'type' => 'text'], ['key' => 'MIDTRANS_ADMIN_FEE', 'value' => '2500', 'type' => 'text'], - // ['key' => 'VOUCHER_STOCK_NOTIFICATION', 'value' => '10', 'type' => 'text'], - + // deposit ['key' => 'ENABLE_CASH_DEPOSIT', 'value' => '0', 'type' => 'text'], ['key' => 'ENABLE_MANUAL_TRANSFER', 'value' => '0', 'type' => 'text'], ['key' => 'MAX_MANUAL_TRANSFER_TIMEOUT', 'value' => '2', 'type' => 'text'], //dalam jam diff --git a/resources/js/Components/FormInputNumeric.jsx b/resources/js/Components/FormInputNumeric.jsx index f0cd547..f9ea153 100644 --- a/resources/js/Components/FormInputNumeric.jsx +++ b/resources/js/Components/FormInputNumeric.jsx @@ -18,15 +18,18 @@ export default function FormInputNumeric({ } value = Number(value) + const labelId = `${name}-${value}` + return (
{ + if (e.target.checked) { + const isExists = data.AFFILATE_ALLOWED_LEVELS.find( + (l) => l.id === level.id + ) + if (isExists) { + return + } + setData( + 'AFFILATE_ALLOWED_LEVELS', + data.AFFILATE_ALLOWED_LEVELS.concat(level) + ) + } else { + setData( + 'AFFILATE_ALLOWED_LEVELS', + data.AFFILATE_ALLOWED_LEVELS.filter((l) => l.id !== level.id) + ) + } + } + + const isCheck = (level) => { + const isExists = data.AFFILATE_ALLOWED_LEVELS.find( + (l) => l.id === level.id + ) + if (isExists) { + return true + } + return false + } + + const handleOnChange = (event) => { + setData( + event.target.name, + event.target.type === 'checkbox' + ? event.target.checked + ? 1 + : 0 + : event.target.value + ) + } + + const handleSubmit = () => { + post(route('setting.affilate')) + } + + return ( + + + +
+
+
+
+
Affilate
+ + +