Bläddra i källkod

feat: reward service

M1Screw 1 år sedan
förälder
incheckning
5ba50696f4

+ 42 - 42
composer.lock

@@ -123,16 +123,16 @@
         },
         },
         {
         {
             "name": "aws/aws-sdk-php",
             "name": "aws/aws-sdk-php",
-            "version": "3.296.1",
+            "version": "3.296.6",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "38e47bbd3b5f76f008dd71c8a68545f9e4e47b6b"
+                "reference": "11d0a94f8b2539d587e2f6db7c2fa8e39fe78a67"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/38e47bbd3b5f76f008dd71c8a68545f9e4e47b6b",
-                "reference": "38e47bbd3b5f76f008dd71c8a68545f9e4e47b6b",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/11d0a94f8b2539d587e2f6db7c2fa8e39fe78a67",
+                "reference": "11d0a94f8b2539d587e2f6db7c2fa8e39fe78a67",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -212,9 +212,9 @@
             "support": {
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.296.1"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.296.6"
             },
             },
-            "time": "2024-01-14T05:20:33+00:00"
+            "time": "2024-01-19T19:14:55+00:00"
         },
         },
         {
         {
             "name": "bacon/bacon-qr-code",
             "name": "bacon/bacon-qr-code",
@@ -1200,7 +1200,7 @@
         },
         },
         {
         {
             "name": "illuminate/collections",
             "name": "illuminate/collections",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/collections.git",
                 "url": "https://github.com/illuminate/collections.git",
@@ -1255,7 +1255,7 @@
         },
         },
         {
         {
             "name": "illuminate/conditionable",
             "name": "illuminate/conditionable",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/conditionable.git",
                 "url": "https://github.com/illuminate/conditionable.git",
@@ -1301,7 +1301,7 @@
         },
         },
         {
         {
             "name": "illuminate/container",
             "name": "illuminate/container",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/container.git",
                 "url": "https://github.com/illuminate/container.git",
@@ -1352,16 +1352,16 @@
         },
         },
         {
         {
             "name": "illuminate/contracts",
             "name": "illuminate/contracts",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/contracts.git",
                 "url": "https://github.com/illuminate/contracts.git",
-                "reference": "0b26d49d4bb0986da1ca30bcc701d5c22722576b"
+                "reference": "8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/illuminate/contracts/zipball/0b26d49d4bb0986da1ca30bcc701d5c22722576b",
-                "reference": "0b26d49d4bb0986da1ca30bcc701d5c22722576b",
+                "url": "https://api.github.com/repos/illuminate/contracts/zipball/8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac",
+                "reference": "8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -1396,20 +1396,20 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
                 "source": "https://github.com/laravel/framework"
             },
             },
-            "time": "2023-12-28T16:46:25+00:00"
+            "time": "2024-01-15T18:52:32+00:00"
         },
         },
         {
         {
             "name": "illuminate/database",
             "name": "illuminate/database",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/database.git",
                 "url": "https://github.com/illuminate/database.git",
-                "reference": "d41a5b7b1dc67bf640f16bf50c376b29ba575da5"
+                "reference": "f7a7d35dec5e7c6c4711cde31119f67d06846459"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/illuminate/database/zipball/d41a5b7b1dc67bf640f16bf50c376b29ba575da5",
-                "reference": "d41a5b7b1dc67bf640f16bf50c376b29ba575da5",
+                "url": "https://api.github.com/repos/illuminate/database/zipball/f7a7d35dec5e7c6c4711cde31119f67d06846459",
+                "reference": "f7a7d35dec5e7c6c4711cde31119f67d06846459",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -1469,11 +1469,11 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
                 "source": "https://github.com/laravel/framework"
             },
             },
-            "time": "2024-01-07T15:44:56+00:00"
+            "time": "2024-01-16T14:41:20+00:00"
         },
         },
         {
         {
             "name": "illuminate/macroable",
             "name": "illuminate/macroable",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/macroable.git",
                 "url": "https://github.com/illuminate/macroable.git",
@@ -1519,16 +1519,16 @@
         },
         },
         {
         {
             "name": "illuminate/pagination",
             "name": "illuminate/pagination",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/pagination.git",
                 "url": "https://github.com/illuminate/pagination.git",
-                "reference": "7447caf65da6b183a3c247b78942c7633c059bd4"
+                "reference": "b42a851e037984e38f8964d1a96d15b0302bebfc"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/illuminate/pagination/zipball/7447caf65da6b183a3c247b78942c7633c059bd4",
-                "reference": "7447caf65da6b183a3c247b78942c7633c059bd4",
+                "url": "https://api.github.com/repos/illuminate/pagination/zipball/b42a851e037984e38f8964d1a96d15b0302bebfc",
+                "reference": "b42a851e037984e38f8964d1a96d15b0302bebfc",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -1565,20 +1565,20 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
                 "source": "https://github.com/laravel/framework"
             },
             },
-            "time": "2024-01-03T22:51:06+00:00"
+            "time": "2024-01-12T17:17:46+00:00"
         },
         },
         {
         {
             "name": "illuminate/support",
             "name": "illuminate/support",
-            "version": "v10.40.0",
+            "version": "v10.41.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/illuminate/support.git",
                 "url": "https://github.com/illuminate/support.git",
-                "reference": "76a79337200b06b4b2a7fe93902aa770d6dcec03"
+                "reference": "1355b7d28ebb802e95bffcb27417862961382c52"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/illuminate/support/zipball/76a79337200b06b4b2a7fe93902aa770d6dcec03",
-                "reference": "76a79337200b06b4b2a7fe93902aa770d6dcec03",
+                "url": "https://api.github.com/repos/illuminate/support/zipball/1355b7d28ebb802e95bffcb27417862961382c52",
+                "reference": "1355b7d28ebb802e95bffcb27417862961382c52",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -1636,7 +1636,7 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
                 "source": "https://github.com/laravel/framework"
             },
             },
-            "time": "2024-01-07T16:54:08+00:00"
+            "time": "2024-01-15T18:53:10+00:00"
         },
         },
         {
         {
             "name": "irazasyed/telegram-bot-sdk",
             "name": "irazasyed/telegram-bot-sdk",
@@ -6992,16 +6992,16 @@
         },
         },
         {
         {
             "name": "friendsofphp/php-cs-fixer",
             "name": "friendsofphp/php-cs-fixer",
-            "version": "v3.47.0",
+            "version": "v3.48.0",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
                 "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
-                "reference": "184dd992fe49169a18300dba4435212db55220f7"
+                "reference": "a92472c6fb66349de25211f31c77eceae3df024e"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/184dd992fe49169a18300dba4435212db55220f7",
-                "reference": "184dd992fe49169a18300dba4435212db55220f7",
+                "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/a92472c6fb66349de25211f31c77eceae3df024e",
+                "reference": "a92472c6fb66349de25211f31c77eceae3df024e",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -7071,7 +7071,7 @@
             ],
             ],
             "support": {
             "support": {
                 "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
                 "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
-                "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.47.0"
+                "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.48.0"
             },
             },
             "funding": [
             "funding": [
                 {
                 {
@@ -7079,7 +7079,7 @@
                     "type": "github"
                     "type": "github"
                 }
                 }
             ],
             ],
-            "time": "2024-01-15T15:35:57+00:00"
+            "time": "2024-01-19T21:44:39+00:00"
         },
         },
         {
         {
             "name": "justinrainbow/json-schema",
             "name": "justinrainbow/json-schema",
@@ -7994,16 +7994,16 @@
         },
         },
         {
         {
             "name": "phpunit/phpunit",
             "name": "phpunit/phpunit",
-            "version": "10.5.7",
+            "version": "10.5.9",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "e5c5b397a95cb0db013270a985726fcae93e61b8"
+                "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e5c5b397a95cb0db013270a985726fcae93e61b8",
-                "reference": "e5c5b397a95cb0db013270a985726fcae93e61b8",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe",
+                "reference": "0bd663704f0165c9e76fe4f06ffa6a1ca727fdbe",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -8075,7 +8075,7 @@
             "support": {
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.7"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.9"
             },
             },
             "funding": [
             "funding": [
                 {
                 {
@@ -8091,7 +8091,7 @@
                     "type": "tidelift"
                     "type": "tidelift"
                 }
                 }
             ],
             ],
-            "time": "2024-01-14T16:40:30+00:00"
+            "time": "2024-01-22T14:35:40+00:00"
         },
         },
         {
         {
             "name": "psr/cache",
             "name": "psr/cache",

+ 19 - 29
config/settings.json

@@ -1291,63 +1291,53 @@
     },
     },
     {
     {
         "id": null,
         "id": null,
-        "item": "invitation_mode",
-        "value": "after_paid",
+        "item": "invite_mode",
+        "value": "reg_only",
         "class": "ref",
         "class": "ref",
         "is_public": 0,
         "is_public": 0,
         "type": "string",
         "type": "string",
-        "default": "after_paid",
+        "default": "reg_only",
         "mark": "邀请模式"
         "mark": "邀请模式"
     },
     },
     {
     {
         "id": null,
         "id": null,
-        "item": "invite_rebate_mode",
-        "value": "limit_amount",
+        "item": "invite_reward_mode",
+        "value": "reward_count",
         "class": "ref",
         "class": "ref",
         "is_public": 0,
         "is_public": 0,
         "type": "string",
         "type": "string",
-        "default": "limit_amount",
+        "default": "reward_count",
         "mark": "返利模式"
         "mark": "返利模式"
     },
     },
     {
     {
         "id": null,
         "id": null,
-        "item": "rebate_frequency_limit",
-        "value": "3",
+        "item": "invite_reward_rate",
+        "value": "0.2",
         "class": "ref",
         "class": "ref",
-        "is_public": 0,
+        "is_public": 1,
         "type": "string",
         "type": "string",
-        "default": "3",
-        "mark": "返利总次数限制"
+        "default": "0.2",
+        "mark": "返利比例"
     },
     },
     {
     {
         "id": null,
         "id": null,
-        "item": "rebate_amount_limit",
-        "value": "100",
+        "item": "invite_reward_count_limit",
+        "value": "1",
         "class": "ref",
         "class": "ref",
         "is_public": 0,
         "is_public": 0,
-        "type": "int",
-        "default": "100",
-        "mark": "返利总金额限制"
-    },
-    {
-        "id": null,
-        "item": "rebate_ratio",
-        "value": "0.2",
-        "class": "ref",
-        "is_public": 1,
         "type": "string",
         "type": "string",
-        "default": "0.2",
-        "mark": "返利比例"
+        "default": "1",
+        "mark": "返利次数限制"
     },
     },
     {
     {
         "id": null,
         "id": null,
-        "item": "rebate_time_range_limit",
-        "value": "180",
+        "item": "invite_reward_total_limit",
+        "value": "50",
         "class": "ref",
         "class": "ref",
         "is_public": 0,
         "is_public": 0,
         "type": "int",
         "type": "int",
-        "default": "180",
-        "mark": "返利时间范围限制(天)"
+        "default": "50",
+        "mark": "返利金额限制"
     },
     },
     {
     {
         "id": null,
         "id": null,

+ 1 - 0
db/migrations/2023020100-init.php

@@ -198,6 +198,7 @@ return new class() implements MigrationInterface {
                 `userid` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
                 `userid` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
                 `ref_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '推荐人ID',
                 `ref_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '推荐人ID',
                 `ref_get` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '推荐人获得金额',
                 `ref_get` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '推荐人获得金额',
+                `invoice_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '账单ID',
                 `datetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 `datetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 PRIMARY KEY (`id`)
                 PRIMARY KEY (`id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

+ 26 - 0
db/migrations/2024012000-add_payback_invoice_id.php

@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Interfaces\MigrationInterface;
+use App\Services\DB;
+
+return new class() implements MigrationInterface {
+    public function up(): int
+    {
+        DB::getPdo()->exec("
+            ALTER TABLE payback ADD COLUMN IF NOT EXISTS `invoice_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '账单ID';
+        ");
+
+        return 2024012000;
+    }
+
+    public function down(): int
+    {
+        DB::getPdo()->exec('
+            ALTER TABLE payback DROP COLUMN IF EXISTS `invoice_id`;
+        ');
+
+        return 2023120700;
+    }
+};

+ 20 - 35
resources/views/tabler/admin/setting/ref.tpl

@@ -65,14 +65,14 @@
                                         <div class="form-group mb-3 row">
                                         <div class="form-group mb-3 row">
                                             <label class="form-label col-3 col-form-label">邀请模式</label>
                                             <label class="form-label col-3 col-form-label">邀请模式</label>
                                             <div class="col">
                                             <div class="col">
-                                                <select id="invitation_mode" class="col form-select"
-                                                        value="{$settings['invitation_mode']}">
+                                                <select id="invite_mode" class="col form-select"
+                                                        value="{$settings['invite_mode']}">
                                                     <option value="reg_only"
                                                     <option value="reg_only"
-                                                            {if $settings['invitation_mode'] === 'reg_only'}selected{/if}>
+                                                            {if $settings['invite_mode'] === 'reg_only'}selected{/if}>
                                                         不返利
                                                         不返利
                                                     </option>
                                                     </option>
-                                                    <option value="after_paid"
-                                                            {if $settings['invitation_mode'] === 'after_paid'}selected{/if}>
+                                                    <option value="reward"
+                                                            {if $settings['invite_mode'] === 'reward'}selected{/if}>
                                                         被邀请用户支付账单时返利
                                                         被邀请用户支付账单时返利
                                                     </option>
                                                     </option>
                                                 </select>
                                                 </select>
@@ -81,23 +81,15 @@
                                         <div class="form-group mb-3 row">
                                         <div class="form-group mb-3 row">
                                             <label class="form-label col-3 col-form-label">返利模式</label>
                                             <label class="form-label col-3 col-form-label">返利模式</label>
                                             <div class="col">
                                             <div class="col">
-                                                <select id="invite_rebate_mode" class="col form-select"
-                                                        value="{$settings['invite_rebate_mode']}">
-                                                    <option value="continued"
-                                                            {if $settings['invite_rebate_mode'] === 'continued'}selected{/if}>
-                                                        持续返利
+                                                <select id="invite_reward_mode" class="col form-select"
+                                                        value="{$settings['invite_reward_mode']}">
+                                                    <option value="reward_count"
+                                                            {if $settings['invite_reward_mode'] === 'reward_count'}selected{/if}>
+                                                        限制返利次数
                                                     </option>
                                                     </option>
-                                                    <option value="limit_frequency"
-                                                            {if $settings['invite_rebate_mode'] === 'limit_frequency'}selected{/if}>
-                                                        限制邀请人能从被邀请人身上获得的返利次数
-                                                    </option>
-                                                    <option value="limit_amount"
-                                                            {if $settings['invite_rebate_mode'] === 'limit_amount'}selected{/if}>
-                                                        限制邀请人能从被邀请人身上获得的返利金额
-                                                    </option>
-                                                    <option value="limit_time_range"
-                                                            {if $settings['invite_rebate_mode'] === 'limit_time_range'}selected{/if}>
-                                                        限制邀请人能从被邀请人身上获得返利的时间范围
+                                                    <option value="reward_total"
+                                                            {if $settings['invite_reward_mode'] === 'reward_total'}selected{/if}>
+                                                        限制返利金额
                                                     </option>
                                                     </option>
                                                 </select>
                                                 </select>
                                             </div>
                                             </div>
@@ -105,29 +97,22 @@
                                         <div class="form-group mb-3 row">
                                         <div class="form-group mb-3 row">
                                             <label class="form-label col-3 col-form-label">返利比例,10% 填 0.1</label>
                                             <label class="form-label col-3 col-form-label">返利比例,10% 填 0.1</label>
                                             <div class="col">
                                             <div class="col">
-                                                <input id="rebate_ratio" type="text" class="form-control"
-                                                       value="{$settings['rebate_ratio']}">
-                                            </div>
-                                        </div>
-                                        <div class="form-group mb-3 row">
-                                            <label class="form-label col-3 col-form-label">返利时间范围(天)</label>
-                                            <div class="col">
-                                                <input id="rebate_time_range_limit" type="text" class="form-control"
-                                                       value="{$settings['rebate_time_range_limit']}">
+                                                <input id="invite_reward_rate" type="text" class="form-control"
+                                                       value="{$settings['invite_reward_rate']}">
                                             </div>
                                             </div>
                                         </div>
                                         </div>
                                         <div class="form-group mb-3 row">
                                         <div class="form-group mb-3 row">
-                                            <label class="form-label col-3 col-form-label">返利次数</label>
+                                            <label class="form-label col-3 col-form-label">返利次数限制</label>
                                             <div class="col">
                                             <div class="col">
-                                                <input id="rebate_frequency_limit" type="text" class="form-control"
-                                                       value="{$settings['rebate_frequency_limit']}">
+                                                <input id="invite_reward_count_limit" type="text" class="form-control"
+                                                       value="{$settings['invite_reward_count_limit']}">
                                             </div>
                                             </div>
                                         </div>
                                         </div>
                                         <div class="form-group mb-3 row">
                                         <div class="form-group mb-3 row">
                                             <label class="form-label col-3 col-form-label">返利金额限制</label>
                                             <label class="form-label col-3 col-form-label">返利金额限制</label>
                                             <div class="col">
                                             <div class="col">
-                                                <input id="rebate_amount_limit" type="text" class="form-control"
-                                                       value="{$settings['rebate_amount_limit']}">
+                                                <input id="invite_reward_total_limit" type="text" class="form-control"
+                                                       value="{$settings['invite_reward_total_limit']}">
                                             </div>
                                             </div>
                                         </div>
                                         </div>
                                     </div>
                                     </div>

+ 1 - 0
src/Controllers/Admin/InviteController.php

@@ -26,6 +26,7 @@ final class InviteController extends BaseController
                 'ref_by' => '获利用户ID',
                 'ref_by' => '获利用户ID',
                 'ref_user_name' => '获利用户名',
                 'ref_user_name' => '获利用户名',
                 'ref_get' => '获利金额',
                 'ref_get' => '获利金额',
+                'invoice_id' => '账单ID',
                 'datetime' => '时间',
                 'datetime' => '时间',
             ],
             ],
             'update_dialog' => [
             'update_dialog' => [

+ 5 - 6
src/Controllers/Admin/Setting/RefController.php

@@ -13,12 +13,11 @@ final class RefController extends BaseController
     private static array $update_field = [
     private static array $update_field = [
         'invitation_to_register_balance_reward',
         'invitation_to_register_balance_reward',
         'invitation_to_register_traffic_reward',
         'invitation_to_register_traffic_reward',
-        'invitation_mode',
-        'invite_rebate_mode',
-        'rebate_ratio',
-        'rebate_frequency_limit',
-        'rebate_amount_limit',
-        'rebate_time_range_limit',
+        'invite_mode',
+        'invite_reward_mode',
+        'invite_reward_rate',
+        'invite_reward_count_limit',
+        'invite_reward_total_limit',
     ];
     ];
 
 
     /**
     /**

+ 15 - 76
src/Models/Payback.php

@@ -8,12 +8,13 @@ use Illuminate\Database\Query\Builder;
 use function time;
 use function time;
 
 
 /**
 /**
- * @property int   $id       记录ID
- * @property float $total    总金额
- * @property int   $userid   用户ID
- * @property int   $ref_by   推荐人ID
- * @property float $ref_get  推荐人获得金额
- * @property int   $datetime 创建时间
+ * @property int   $id         记录ID
+ * @property float $total      总金额
+ * @property int   $userid     用户ID
+ * @property int   $ref_by     推荐人ID
+ * @property float $ref_get    推荐人获得金额
+ * @property int   $invoice_id 账单ID
+ * @property int   $datetime   创建时间
  *
  *
  * @mixin Builder
  * @mixin Builder
  */
  */
@@ -44,76 +45,14 @@ final class Payback extends Model
             (new User())->where('id', $this->ref_by)->first()->user_name;
             (new User())->where('id', $this->ref_by)->first()->user_name;
     }
     }
 
 
-    public function rebate($user_id, $order_amount): void
+    public function add(float $total, int $user_id, int $ref_by, float $ref_get, int $invoice_id): void
     {
     {
-        $configs = Config::getClass('ref');
-        $user = (new User())->where('id', $user_id)->first();
-        $gift_user_id = $user->ref_by;
-        // 判断
-        $invite_rebate_mode = (string) $configs['invite_rebate_mode'];
-
-        if ($invite_rebate_mode === 'continued') {
-            // 不设限制
-            $this->execute($user_id, $gift_user_id, $order_amount);
-        } elseif ($invite_rebate_mode === 'limit_frequency') {
-            // 限制返利次数
-            $rebate_frequency = self::where('userid', $user_id)->count();
-
-            if ($rebate_frequency < $configs['rebate_frequency_limit']) {
-                $this->execute($user_id, $gift_user_id, $order_amount);
-            }
-        } elseif ($invite_rebate_mode === 'limit_amount') {
-            // 限制返利金额
-            $total_rebate_amount = self::where('userid', $user_id)->sum('ref_get');
-            // 预计返利 (expected_rebate) 是指:订单金额 * 返点比例
-            $expected_rebate = $order_amount * $configs['rebate_ratio'];
-            // 调整返利 (adjust_rebate) 是指:若历史返利总额在加上此次预计返利金额超过总返利限制,总返利限制与历史返利总额的差值
-            if ($total_rebate_amount + $expected_rebate > $configs['rebate_amount_limit']
-                && $total_rebate_amount <= $configs['rebate_amount_limit']
-            ) {
-                $adjust_rebate = $configs['rebate_amount_limit'] - $total_rebate_amount;
-
-                if ($adjust_rebate > 0) {
-                    $this->execute($user_id, $gift_user_id, $order_amount, $adjust_rebate);
-                }
-            } else {
-                $this->execute($user_id, $gift_user_id, $order_amount);
-            }
-        } elseif ($invite_rebate_mode === 'limit_time_range') {
-            if (strtotime($user->reg_date) + $configs['rebate_time_range_limit'] * 86400 > time()) {
-                $this->execute($user_id, $gift_user_id, $order_amount);
-            }
-        }
-    }
-
-    public function execute($user_id, $gift_user_id, $order_amount, $adjust_rebate = null): void
-    {
-        $gift_user = (new User())->where('id', $gift_user_id)
-            ->where('is_banned', 0)
-            ->where('is_shadow_banned', 0)
-            ->first();
-
-        if ($gift_user !== null) {
-            $rebate_amount = $order_amount * Config::obtain('rebate_ratio');
-            // 返利
-            $money_before = $gift_user->money;
-            $gift_user->money += $adjust_rebate ?? $rebate_amount;
-            $gift_user->save();
-            // 余额变动记录
-            (new UserMoneyLog())->add(
-                $gift_user->id,
-                (float) $money_before,
-                (float) $gift_user->money,
-                $adjust_rebate ?? $rebate_amount,
-                '邀请用户 #' . $user_id . ' 返利',
-            );
-            // 添加记录
-            $this->total = $order_amount;
-            $this->userid = $user_id;
-            $this->ref_by = $gift_user_id;
-            $this->ref_get = $adjust_rebate ?? $rebate_amount;
-            $this->datetime = time();
-            $this->save();
-        }
+        $this->total = $total;
+        $this->userid = $user_id;
+        $this->ref_by = $ref_by;
+        $this->ref_get = $ref_get;
+        $this->invoice_id = $invoice_id;
+        $this->datetime = time();
+        $this->save();
     }
     }
 }
 }

+ 3 - 3
src/Services/Gateway/Base.php

@@ -6,9 +6,9 @@ namespace App\Services\Gateway;
 
 
 use App\Models\Config;
 use App\Models\Config;
 use App\Models\Invoice;
 use App\Models\Invoice;
-use App\Models\Payback;
 use App\Models\Paylist;
 use App\Models\Paylist;
 use App\Models\User;
 use App\Models\User;
+use App\Services\Reward;
 use App\Utils\Tools;
 use App\Utils\Tools;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
 use Slim\Http\Response;
@@ -80,8 +80,8 @@ abstract class Base
 
 
         $user = (new User())->find($paylist?->userid);
         $user = (new User())->find($paylist?->userid);
         // 返利
         // 返利
-        if ($user !== null && $user->ref_by > 0 && Config::obtain('invitation_mode') === 'after_paid') {
-            (new Payback())->rebate($user->id, $paylist->total);
+        if ($user !== null && $user->ref_by > 0 && Config::obtain('invitation_mode') === 'reward') {
+            Reward::issuePaybackReward($user->id, $user->ref_by, $paylist->total, $paylist->invoice_id);
         }
         }
     }
     }
 
 

+ 82 - 0
src/Services/Reward.php

@@ -0,0 +1,82 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Services;
+
+use App\Models\Config;
+use App\Models\Payback;
+use App\Models\User;
+use App\Models\UserMoneyLog;
+
+final class Reward
+{
+    public static function issuePaybackReward($user_id, $ref_user_id, $total, $invoice_id): void
+    {
+        $ref_get = 0;
+
+        $ref_user = (new User())->where('id', $ref_user_id)
+            ->where('is_banned', 0)
+            ->where('is_shadow_banned', 0)
+            ->first();
+
+        $exsit_payback = (new Payback())->where('userid', $user_id)
+            ->where('invoice_id', $invoice_id)
+            ->first();
+
+        if ($ref_user !== null && $exsit_payback === null) {
+            $invite_reward_mode = Config::obtain('invite_reward_mode');
+            $invite_reward_rate = Config::obtain('invite_reward_rate');
+
+            if ($invite_reward_mode === 'reward_count') {
+                $invite_reward_count_limit = Config::obtain('invite_reward_count_limit');
+
+                $invite_reward_count = (new Payback())->where('userid', $user_id)
+                    ->where('ref_by', $ref_user_id)
+                    ->count();
+
+                if ($invite_reward_count < $invite_reward_count_limit) {
+                    $ref_get = $total * $invite_reward_rate;
+                }
+            }
+
+            if ($invite_reward_mode === 'reward_total') {
+                $invite_reward_total_limit = Config::obtain('invite_reward_total_limit');
+
+                $invite_reward_total = (new Payback())->where('userid', $user_id)
+                    ->where('ref_by', $ref_user_id)
+                    ->sum('ref_get');
+
+                if ($invite_reward_total < $invite_reward_total_limit) {
+                    $ref_get = $total * $invite_reward_rate;
+
+                    if ($invite_reward_total + $ref_get > $invite_reward_total_limit) {
+                        $ref_get = $invite_reward_total_limit - $invite_reward_total;
+                    }
+                }
+            }
+        }
+
+        if ($ref_get !== 0) {
+            $money_before = $ref_user->money;
+            $ref_user->money += $ref_get;
+            $ref_user->save();
+            // 添加余额记录
+            (new UserMoneyLog())->add(
+                $ref_user->id,
+                (float) $money_before,
+                (float) $ref_user->money,
+                $ref_get,
+                '邀请用户 #' . $user_id . ' 返利',
+            );
+            // 添加返利记录
+            (new Payback())->add(
+                (float) $total,
+                $user_id,
+                $ref_user_id,
+                (float) $ref_get,
+                $invoice_id,
+            );
+        }
+    }
+}

+ 9 - 5
src/Services/Subscribe/Clash.php

@@ -44,7 +44,8 @@ final class Clash extends Base
 
 
                     break;
                     break;
                 case 1:
                 case 1:
-                    $ss_2022_port = $node_custom_config['offset_port_user'] ?? ($node_custom_config['offset_port_node'] ?? 443);
+                    $ss_2022_port = $node_custom_config['offset_port_user'] ??
+                        ($node_custom_config['offset_port_node'] ?? 443);
                     $method = $node_custom_config['method'] ?? '2022-blake3-aes-128-gcm';
                     $method = $node_custom_config['method'] ?? '2022-blake3-aes-128-gcm';
 
 
                     $pk_len = match ($method) {
                     $pk_len = match ($method) {
@@ -68,7 +69,8 @@ final class Clash extends Base
 
 
                     break;
                     break;
                 case 2:
                 case 2:
-                    $tuic_port = $node_custom_config['offset_port_user'] ?? ($node_custom_config['offset_port_node'] ?? 443);
+                    $tuic_port = $node_custom_config['offset_port_user'] ??
+                        ($node_custom_config['offset_port_node'] ?? 443);
                     $host = $node_custom_config['host'] ?? '';
                     $host = $node_custom_config['host'] ?? '';
                     $congestion_control = $node_custom_config['congestion_control'] ?? 'bbr';
                     $congestion_control = $node_custom_config['congestion_control'] ?? 'bbr';
                     // Only Clash.Meta core has TUIC support
                     // Only Clash.Meta core has TUIC support
@@ -87,10 +89,11 @@ final class Clash extends Base
 
 
                     break;
                     break;
                 case 11:
                 case 11:
-                    $v2_port = $node_custom_config['offset_port_user'] ?? ($node_custom_config['offset_port_node'] ?? 443);
+                    $v2_port = $node_custom_config['offset_port_user'] ??
+                        ($node_custom_config['offset_port_node'] ?? 443);
                     $security = $node_custom_config['security'] ?? 'none';
                     $security = $node_custom_config['security'] ?? 'none';
                     $encryption = $node_custom_config['encryption'] ?? 'auto';
                     $encryption = $node_custom_config['encryption'] ?? 'auto';
-                    $network = $node_custom_config['header']['type'] ?? $node_custom_config['network'] ?? '';
+                    $network = $node_custom_config['network'] ?? '';
                     $host = $node_custom_config['header']['request']['headers']['Host'][0] ??
                     $host = $node_custom_config['header']['request']['headers']['Host'][0] ??
                         $node_custom_config['host'] ?? '';
                         $node_custom_config['host'] ?? '';
                     $allow_insecure = $node_custom_config['allow_insecure'] ?? false;
                     $allow_insecure = $node_custom_config['allow_insecure'] ?? false;
@@ -127,7 +130,8 @@ final class Clash extends Base
 
 
                     break;
                     break;
                 case 14:
                 case 14:
-                    $trojan_port = $node_custom_config['offset_port_user'] ?? ($node_custom_config['offset_port_node'] ?? 443);
+                    $trojan_port = $node_custom_config['offset_port_user'] ??
+                        ($node_custom_config['offset_port_node'] ?? 443);
                     $network = $node_custom_config['header']['type'] ?? $node_custom_config['network'] ?? 'tcp';
                     $network = $node_custom_config['header']['type'] ?? $node_custom_config['network'] ?? 'tcp';
                     $host = $node_custom_config['host'] ?? '';
                     $host = $node_custom_config['host'] ?? '';
                     $allow_insecure = $node_custom_config['allow_insecure'] ?? false;
                     $allow_insecure = $node_custom_config['allow_insecure'] ?? false;