From 5402cae0dc8c094fab730d021b31128a6be2846f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= <zoujingli@qq.com>
Date: Fri, 12 Mar 2021 17:46:38 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A5=96=E5=8A=B1=E9=85=8D?=
 =?UTF-8?q?=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/data/service/RebateCurrentService.php | 67 +++++++++++++++++------
 app/data/view/user_rebate/config.html     |  6 +-
 2 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/app/data/service/RebateCurrentService.php b/app/data/service/RebateCurrentService.php
index e2e263b63..0a35d6daf 100644
--- a/app/data/service/RebateCurrentService.php
+++ b/app/data/service/RebateCurrentService.php
@@ -117,14 +117,16 @@ class RebateCurrentService extends Service
         if ($this->app->db->name($this->table)->where($map)->count() > 0) return false;
         if (!$this->checkLevelPrize(self::PRIZE_01, $this->from1['vip_code'])) return false;
         // 创建返利奖励记录
+        $key = "{$this->from1['id']}_{$this->user['id']}";
         $map = ['type' => self::PRIZE_01, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
-        if ($this->app->db->name($this->table)->where($map)->count() < 1) {
-            if (sysconf('shop.fristType') == 1) {
-                $amount = sysconf('shop.fristValue') ?: '0.00';
-                $name = self::instance()->name(self::PRIZE_01) . ",每人 {$amount} 元";
+        if ($this->config("frist_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
+            $value = $this->config("frist_value_vip_{$key}");
+            if ($this->config("frist_type_vip_{$key}") == 1) {
+                $amount = $value ?: '0.00';
+                $name = "{$this->name(self::PRIZE_01)},每人 {$amount} 元";
             } else {
-                $amount = sysconf('shop.fristValue') * $this->order['amount_total'] / 100;
-                $name = self::instance()->name(self::PRIZE_01) . ",订单 " . sysconf('shop.fristValue') . '%';
+                $amount = $value * $this->order['amount_total'] / 100;
+                $name = "{$this->name(self::PRIZE_01)},订单 {$value}%";
             }
             $this->app->db->name($this->table)->insert(array_merge($map, [
                 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'order_amount' => $this->order['amount_total'],
@@ -149,14 +151,16 @@ class RebateCurrentService extends Service
         if ($this->app->db->name($this->table)->where($map)->count() < 1) return false;
         if (!$this->checkLevelPrize(self::PRIZE_02, $this->from1['vip_code'])) return false;
         // 创建返利奖励记录
+        $key = "{$this->from1['id']}_{$this->user['id']}";
         $map = ['type' => self::PRIZE_02, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
-        if ($this->app->db->name($this->table)->where($map)->count() < 1) {
-            if (sysconf('shop.repeatType') == 1) {
-                $amount = sysconf('shop.repeatValue') ?: '0.00';
-                $name = self::instance()->name(self::PRIZE_02) . ",每人 {$amount} 元";
+        if ($this->config("repeat_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
+            $value = $this->config("repeat_value_vip_{$key}");
+            if ($this->config("repeat_type_vip_{$key}") == 1) {
+                $amount = $value ?: '0.00';
+                $name = "{$this->name(self::PRIZE_02)},每人 {$amount} 元";
             } else {
-                $amount = sysconf('shop.repeatValue') * $this->order['amount_total'] / 100;
-                $name = self::instance()->name(self::PRIZE_02) . ",订单 " . sysconf('shop.repeatValue') . '%';
+                $amount = $value * $this->order['amount_total'] / 100;
+                $name = "{$this->name(self::PRIZE_02)},订单 {$value}%";
             }
             $this->app->db->name($this->table)->insert(array_merge($map, [
                 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'order_amount' => $this->order['amount_total'],
@@ -179,10 +183,12 @@ class RebateCurrentService extends Service
         if (empty($this->from1)) return false;
         if (!$this->checkLevelPrize(self::PRIZE_03, $this->from1['vip_code'])) return false;
         // 创建返利奖励记录
+        $key = "{$this->user['id']}";
         $map = ['type' => self::PRIZE_03, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
-        if ($this->app->db->name($this->table)->where($map)->count() < 1) {
-            $amount = sysconf('shop.repeatValue') * $this->order['amount_total'] / 100;
-            $name = self::instance()->name(self::PRIZE_03) . ",订单 " . sysconf('shop.repeatValue') . '%';
+        if ($this->config("direct_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
+            $value = $this->config("direct_value_vip_{$key}");
+            $amount = $value * $this->order['amount_total'] / 100;
+            $name = "{$this->name(self::PRIZE_03)},订单 {$value}%";
             $this->app->db->name($this->table)->insert(array_merge($map, [
                 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'order_amount' => $this->order['amount_total'],
             ]));
@@ -203,10 +209,12 @@ class RebateCurrentService extends Service
     {
         if (empty($this->from2)) return false;
         if (!$this->checkLevelPrize(self::PRIZE_04, $this->from2['vip_code'])) return false;
+        $key = "{$this->user['id']}";
         $map = ['type' => self::PRIZE_04, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
-        if ($this->app->db->name($this->table)->where($map)->count() < 1) {
-            $amount = sysconf('shop.indirectValue') * $this->order['amount_total'] / 100;
-            $name = self::instance()->name(self::PRIZE_04) . ",订单 " . sysconf('shop.indirectValue') . '%';
+        if ($this->config("indirect_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
+            $value = $this->config("indirect_value_vip_{$key}");
+            $amount = $value * $this->order['amount_total'] / 100;
+            $name = "{$this->name(self::PRIZE_04)},订单 {$value}%";
             $this->app->db->name($this->table)->insert(array_merge($map, [
                 'uid' => $this->from2['id'], 'name' => $name, 'amount' => $amount, 'order_amount' => $this->order['amount_total'],
             ]));
@@ -269,6 +277,29 @@ class RebateCurrentService extends Service
         return true;
     }
 
+    /**
+     * 升级奖励发放
+     */
+    private function _prize07()
+    {
+
+    }
+
+    /**
+     * 获取配置数据
+     * @param ?string $name
+     * @return array|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function config(?string $name = null)
+    {
+        static $data = [];
+        if (empty($data)) $data = sysdata('RebateRule');
+        return is_null($name) ? $data : ($data[$name] ?? '');
+    }
+
     /**
      * 检查等级是否有奖励
      * @param string $prize
diff --git a/app/data/view/user_rebate/config.html b/app/data/view/user_rebate/config.html
index 3fd9b9905..ca26d5c7d 100644
--- a/app/data/view/user_rebate/config.html
+++ b/app/data/view/user_rebate/config.html
@@ -12,8 +12,8 @@
                         <fieldset class="block">
                             <legend><span class="layui-badge">结算到账</span></legend>
                             <div class="layui-form-item">
-                                {php} $data['settl_type'] = $data['settl_type'] ?? 0; {/php}
-                                {foreach ['支付后立即到账', '确认收货后到账'] as $key => $val}{if $data.settl_type eq $key}
+                                {php} $data['settl_type'] = $data['settl_type'] ?? 1; {/php}
+                                {foreach [1 => '支付后立即到账',2 => '确认收货后到账'] as $key => $val}{if $data.settl_type eq $key}
                                 <input checked class="layui-input" type="radio" name="settl_type" value="{$key}" title="{$val}">
                                 {else}
                                 <input class="layui-input" type="radio" name="settl_type" value="{$key}" title="{$val}">
@@ -205,7 +205,7 @@
                                                 {/if}
                                             </legend>
                                             <div class="layui-form-item nowrap">
-                                                {php} $key = 'direct_value_vip_'.$level['number']; {/php}
+                                                {php} $key = 'indirect_value_vip_'.$level['number']; {/php}
                                                 <input class="layui-input" type="hidden" name="indirect_type_vip_{$level.number}" value="2">
                                                 <label class="block">
                                                     <span class="color-blue"><b>请输入团队业绩金额比例</b>( 如:比例填写 10.00 表示 10.00% )</span>