From 25b3b11efdf763525e59b848a00f4fc1e46baefd Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Sat, 18 Sep 2021 21:04:35 +0900 Subject: [PATCH] update: add commission distribution --- app/Console/Commands/CheckCommission.php | 13 ++++++++++++- app/Models/CommissionLog.php | 16 ++++++++++++++++ database/install.sql | 16 +++++++++++++++- database/update.sql | 11 +++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 app/Models/CommissionLog.php diff --git a/app/Console/Commands/CheckCommission.php b/app/Console/Commands/CheckCommission.php index 8f57f59f..c109814a 100644 --- a/app/Console/Commands/CheckCommission.php +++ b/app/Console/Commands/CheckCommission.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\CommissionLog; use Illuminate\Console\Command; use App\Models\Order; use App\Models\User; @@ -96,7 +97,7 @@ class CheckCommission extends Command $inviter = User::find($inviteUserId); if (!$inviter) continue; if (!$commissionShareLevels[$l]) continue; - $commissionBalance = $order->commission_balance * $commissionShareLevels[$l]; + $commissionBalance = $order->commission_balance * ($commissionShareLevels[$l] / 100); if ((int)config('v2board.withdraw_close_enable', 0)) { $inviter->balance = $inviter->balance + $commissionBalance; } else { @@ -106,6 +107,16 @@ class CheckCommission extends Command DB::rollBack(); return false; } + if (!CommissionLog::create([ + 'invite_user_id' => $inviteUserId, + 'user_id' => $order->user_id, + 'trade_no' => $order->trade_no, + 'order_amount' => $order->total_amount, + 'get_amount' => $commissionBalance + ])) { + DB::rollBack(); + return false; + } $inviteUserId = $inviter->invite_user_id; } return true; diff --git a/app/Models/CommissionLog.php b/app/Models/CommissionLog.php new file mode 100644 index 00000000..744c5d50 --- /dev/null +++ b/app/Models/CommissionLog.php @@ -0,0 +1,16 @@ + 'timestamp', + 'updated_at' => 'timestamp' + ]; +} diff --git a/database/install.sql b/database/install.sql index 48449bbc..bb0ec3dc 100644 --- a/database/install.sql +++ b/database/install.sql @@ -19,6 +19,20 @@ CREATE TABLE `failed_jobs` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +DROP TABLE IF EXISTS `v2_commission_log`; +CREATE TABLE `v2_commission_log` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `invite_user_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `trade_no` char(36) NOT NULL, + `order_amount` int(11) NOT NULL, + `get_amount` int(11) NOT NULL, + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + DROP TABLE IF EXISTS `v2_coupon`; CREATE TABLE `v2_coupon` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -353,4 +367,4 @@ CREATE TABLE `v2_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- 2021-09-14 04:09:49 +-- 2021-09-18 12:00:43 diff --git a/database/update.sql b/database/update.sql index 78302f8a..d2af0efe 100644 --- a/database/update.sql +++ b/database/update.sql @@ -441,3 +441,14 @@ ALTER TABLE `v2_coupon` ALTER TABLE `v2_user` ADD `password_salt` char(10) COLLATE 'utf8_general_ci' NULL AFTER `password_algo`; + +CREATE TABLE `v2_commission_log` ( + `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, + `invite_user_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `trade_no` char(36) NOT NULL, + `order_amount` int(11) NOT NULL, + `get_amount` int(11) NOT NULL, + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL +) COLLATE 'utf8mb4_general_ci';