Explorar o código

商贸区组合支付分佣中的比例读取数据库字段配置

family hai 1 ano
pai
achega
59b4890174
Modificáronse 1 ficheiros con 89 adicións e 59 borrados
  1. 89 59
      app/common/repositories/store/order/StoreOrderRepository.php

+ 89 - 59
app/common/repositories/store/order/StoreOrderRepository.php

@@ -10052,38 +10052,42 @@ class StoreOrderRepository extends BaseRepository
10052 10052
                     //查询下单用户上级
10053 10053
                     $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
10054 10054
 
10055
+                    $user_group_rate = Db::name("system_config_value")->where(["config_key"=>"user_group_rate"])->value("value");
10056
+                    $user_group_rate = json_decode($user_group_rate, true);
10057
+                    $group_rate = array_column($user_group_rate, 'rate','user_groub');
10055 10058
                     //业务员或以上的推荐人等级
10056
-                    //user_group=1是消费者 3%,2:业务员 5%,3:业务经理7%,4:初级合伙人9%,5:中级合伙人11%,6:高级合伙人13%,7:董事15%
10059
+                    //[{"user_groub":1,"rate":5,"name":"用户"},
10060
+                    //{"user_groub":2,"rate":7,"name":"业务员"},
10061
+                    //{"user_groub":3,"rate":9,"name":"业务经理"},
10062
+                    //{"user_groub":4,"rate":11,"name":"初级合伙人"},
10063
+                    //{"user_groub":5,"rate":13,"name":"中级合伙人"},
10064
+                    //{"user_groub":6,"rate":15,"name":"高级合伙人"},
10065
+                    //{"user_groub":7,"rate":17,"name":"董事"}
10066
+                    //]
10067
+                    $rate = isset($group_rate[$spread_data['user_group']])?round($group_rate[$spread_data['user_group']]/100,2):0.00;
10057 10068
                     if ($spread_data['user_group'] > 1) {
10058
-
10059
-                        // //给推广者分配佣金
10060
-                        $yj_amount = 0;
10061
-                        $ylj_amount = $spread_data['annuity'] + round($pv * 0.05, 2);
10062 10069
                         $ssf = 0;//变量
10063 10070
                         $yj_amount_90 = 0;//90%的佣金
10064
-
10071
+                        // 业务员
10065 10072
                         if ($spread_data['user_group'] == 2) {
10066
-                            $ssf = round($pv * 0.07, 2);
10067
-                            $con = $spread_data['contribute'] + round($pv * 0.07, 2);
10068
-                            $score = $spread_data['score'] + round($pv * 0.07, 2);
10073
+                            $ssf = round($pv * $rate, 2);
10074
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10075
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10069 10076
 
10070 10077
 
10071
-                            $yj_amount_90 = round($pv * 0.07, 2) * 0.9;
10072
-                            $fgj_amount_10 = round($pv * 0.07, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10078
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10079
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10073 10080
 
10074 10081
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10075 10082
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
10076 10083
                             $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
10077
-
10078
-
10079
-                            // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
10080 10084
                         } else if ($spread_data['user_group'] == 3) {
10081
-                            $ssf = round($pv * 0.09, 2);
10082
-                            $con = $spread_data['contribute'] + round($pv * 0.09, 2);
10083
-                            $score = $spread_data['score'] + round($pv * 0.09, 2);
10085
+                            $ssf = round($pv * $rate, 2);
10086
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10087
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10084 10088
 
10085
-                            $yj_amount_90 = round($pv * 0.09, 2) * 0.9;
10086
-                            $fgj_amount_10 = round($pv * 0.09, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10089
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10090
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10087 10091
 
10088 10092
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10089 10093
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10091,12 +10095,12 @@ class StoreOrderRepository extends BaseRepository
10091 10095
 
10092 10096
                             // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
10093 10097
                         } else if ($spread_data['user_group'] == 4) {
10094
-                            $ssf = round($pv * 0.11, 2);
10095
-                            $con = $spread_data['contribute'] + round($pv * 0.11, 2);
10096
-                            $score = $spread_data['score'] + round($pv * 0.11, 2);
10098
+                            $ssf = round($pv * $rate, 2);
10099
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10100
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10097 10101
 
10098
-                            $yj_amount_90 = round($pv * 0.11, 2) * 0.9;
10099
-                            $fgj_amount_10 = round($pv * 0.11, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10102
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10103
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10100 10104
 
10101 10105
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10102 10106
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10104,13 +10108,13 @@ class StoreOrderRepository extends BaseRepository
10104 10108
 
10105 10109
                             //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
10106 10110
                         } else if ($spread_data['user_group'] == 5) {
10107
-                            $ssf = round($pv * 0.13, 2);
10108
-                            $con = $spread_data['contribute'] + round($pv * 0.13, 2);
10109
-                            $score = $spread_data['score'] + round($pv * 0.13, 2);
10110
-                            // $yj_amount = $spread_data['brokerage_price'] + round($pv * 0.13,2);
10111
+                            $ssf = round($pv * $rate, 2);
10112
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10113
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10114
+                            // $yj_amount = $spread_data['brokerage_price'] + round($pv * $rate,2);
10111 10115
 
10112
-                            $yj_amount_90 = round($pv * 0.13, 2) * 0.9;
10113
-                            $fgj_amount_10 = round($pv * 0.13, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10116
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10117
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10114 10118
 
10115 10119
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10116 10120
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10118,12 +10122,12 @@ class StoreOrderRepository extends BaseRepository
10118 10122
 
10119 10123
                             // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
10120 10124
                         } else if ($spread_data['user_group'] == 6) {
10121
-                            $ssf = round($pv * 0.15, 2);
10122
-                            $con = $spread_data['contribute'] + round($pv * 0.15, 2);
10123
-                            $score = $spread_data['score'] + round($pv * 0.15, 2);
10125
+                            $ssf = round($pv * $rate, 2);
10126
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10127
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10124 10128
 
10125
-                            $yj_amount_90 = round($pv * 0.15, 2) * 0.9;
10126
-                            $fgj_amount_10 = round($pv * 0.15, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10129
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10130
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10127 10131
 
10128 10132
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10129 10133
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10131,13 +10135,13 @@ class StoreOrderRepository extends BaseRepository
10131 10135
 
10132 10136
                             // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
10133 10137
                         } else if ($spread_data['user_group'] == 7) {
10134
-                            $ssf = round($pv * 0.17, 2);
10135
-                            $con = $spread_data['contribute'] + round($pv * 0.17, 2);
10136
-                            $score = $spread_data['score'] + round($pv * 0.17, 2);
10138
+                            $ssf = round($pv * $rate, 2);
10139
+                            $con = $spread_data['contribute'] + round($pv * $rate, 2);
10140
+                            $score = $spread_data['score'] + round($pv * $rate, 2);
10137 10141
 
10138 10142
 
10139
-                            $yj_amount_90 = round($pv * 0.17, 2) * 0.9;
10140
-                            $fgj_amount_10 = round($pv * 0.17, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10143
+                            $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10144
+                            $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10141 10145
 
10142 10146
                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10143 10147
                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10160,8 +10164,8 @@ class StoreOrderRepository extends BaseRepository
10160 10164
                     if ($spread_data['user_group'] == 1) {
10161 10165
                         //给推广者分配佣金
10162 10166
 
10163
-                        $yj_amount_90 = round($pv * 0.21, 2) * 0.9;
10164
-                        $fgj_amount_10 = round($pv * 0.21, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10167
+                        $yj_amount_90 = round($pv * $rate, 2) * 0.9;
10168
+                        $fgj_amount_10 = round($pv * $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10165 10169
 
10166 10170
                         $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
10167 10171
                         $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -10169,35 +10173,25 @@ class StoreOrderRepository extends BaseRepository
10169 10173
 
10170 10174
                         //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
10171 10175
 
10172
-                        $con = $spread_data['contribute'] + round($pv * 0.21, 2);
10173
-                        $score = $spread_data['score'] + round($pv * 0.21, 2);
10176
+                        $con = $spread_data['contribute'] + round($pv * $rate, 2);
10177
+                        $score = $spread_data['score'] + round($pv * $rate, 2);
10174 10178
 
10175 10179
                         //贡献值和积分
10176 10180
                         // Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
10177 10181
 
10178
-                        //推广养老金
10179 10182
                         //推广佣金
10180 10183
                         $this->bill_user_log($spread_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得拥金' . $yj_amount_90, $store_order_data['mer_id'], 0);
10181
-                        $this->con_log($spread_data['uid'], round($pv * 0.21, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
10182
-                        $this->score_log($spread_data['uid'], round($pv * 0.21, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
10183
-
10184
-
10184
+                        $this->con_log($spread_data['uid'], round($pv * $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
10185
+                        $this->score_log($spread_data['uid'], round($pv * $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
10185 10186
                     }
10186
-
10187
-
10188 10187
                 }
10189 10188
 
10190 10189
                 //锁客收益
10191 10190
                 if ($user_data['mer_id'] != 0) {
10192
-
10193 10191
                     $merchant_data = Db::name('merchant')->where('mer_id', $user_data['mer_id'])->find();
10194
-
10195 10192
                     $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
10196
-
10197 10193
                     if (!empty($merchant_user_data)) {
10198
-
10199 10194
                         //给推广者分配佣金
10200
-
10201 10195
                         $yj_amount_90 = round($pv * 0.05, 2) * 0.9;
10202 10196
                         $fgj_amount_10 = round($pv * 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
10203 10197
 
@@ -10205,13 +10199,49 @@ class StoreOrderRepository extends BaseRepository
10205 10199
                         $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10;
10206 10200
                         $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
10207 10201
 
10208
-
10209
-                        // Db::name('user')->where('uid',$merchant_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
10210 10202
                         //推广佣金
10211 10203
                         $this->bill_user_log($merchant_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得拥金' . $yj_amount_90, $store_order_data['mer_id'], 0);
10212
-
10204
+                    }
10205
+                    //商户获得贡献值
10206
+                    if ($concession_pri >= 0.01) {
10207
+                        $gongxian_data = [
10208
+                            "uid"           =>$merchant_data["uid"],
10209
+                            "mer_id"        =>$user_data['mer_id'],
10210
+                            "pv"            =>$pv,
10211
+                            "number"  =>    $concession_pri,
10212
+                            "addtime"       =>time(),
10213
+                            "status"        =>-1,
10214
+                            "order_type"    =>2,
10215
+                            "order_id"      =>$store_order_data['order_id'],
10216
+                            "mark"          =>"锁客商家获得贡献值",
10217
+                            "desc"          =>'',
10218
+                            "surplus"       =>$concession_pri,
10219
+                            "type"          =>1
10220
+                        ];
10221
+                        Db::name("user_sign_gongxian")->insert($gongxian_data);//添加记录
10222
+                    } else {
10223
+                        Db::name('log')->insert(['data' => '订单号:' .$store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,贡献值低于0.01无法入库 特此记录!']);
10213 10224
                     }
10214 10225
 
10226
+                    //商户获得京豆
10227
+                    if ($concession_pri >= 0.01) {
10228
+                        $jd_data = [
10229
+                            "uid"           =>$merchant_data["uid"],
10230
+                            "mer_id"        =>$user_data['mer_id'],
10231
+                            "number"  =>    $concession_pri,
10232
+                            "addtime"       =>time(),
10233
+                            "status"        =>-1,
10234
+                            "order_type"    =>2,
10235
+                            "order_id"      =>$store_order_data['order_id'],
10236
+                            "mark"          =>"锁客商家获得京豆",
10237
+                            "desc"          =>'',
10238
+                            "surplus"       =>$concession_pri,
10239
+                            "type"          =>1
10240
+                        ];
10241
+                        Db::name("user_sign_jingdou")->insert($jd_data);//添加记录
10242
+                    } else {
10243
+                        Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,京豆低于0.01无法入库 特此记录!']);
10244
+                    }
10215 10245
                 }
10216 10246
             }
10217 10247
         }