Selaa lähdekoodia

合伙人分红加入2.0分红计算

橙汁先生 1 vuosi sitten
vanhempi
commit
a6b6b223d9
1 muutettua tiedostoa jossa 175 lisäystä ja 20 poistoa
  1. 175 20
      app/controller/api/store/merchant/Taskorder.php

+ 175 - 20
app/controller/api/store/merchant/Taskorder.php

@@ -563,7 +563,7 @@ class Taskorder extends BaseController
563 563
 
564 564
         // $store_product_datas = Db::name('old_user_of_goods_old')->select();
565 565
 
566
-        $week_record = 7000;
566
+        $week_record = 139200;
567 567
         $stock_comm = round($week_record * 0.05 ,2);
568 568
 
569 569
         //获取股权分红的人
@@ -619,7 +619,6 @@ class Taskorder extends BaseController
619 619
 
620 620
 
621 621
 
622
-
623 622
         //var_dump($week_record);die;//9912  8400
624 623
         //$star_list = Db::name("user_star")->order("statement_all_num desc")->select()->toArray();//旧星级等级
625 624
         $star_list = Db::name("old_user_starlevel")->order("statement_all_num desc")->select()->toArray();//星级等级
@@ -704,15 +703,17 @@ class Taskorder extends BaseController
704 703
 
705 704
 
706 705
 
707
-//var_dump($sales_arr);die; //把初级中的   id是 12,69, 144从初级中去掉 ,id是49,从中级中去掉
706
+//var_dump($sales_arr);return; //把初级中的   id是 12,69, 144从初级中去掉 ,id是49,从中级中去掉
708 707
 
709 708
         //移动指定ID_end
710 709
 
711
-
712 710
         // var_dump($sales_arr);die;
713 711
         //$sales_arr获取分红的id和分红的比例
714 712
 
715 713
 
714
+
715
+
716
+
716 717
         //执行分开发放
717 718
         foreach($sales_arr as $key =>$value) {
718 719
             //比如这个周的总业绩是 8400
@@ -887,6 +888,9 @@ class Taskorder extends BaseController
887 888
 //     return [$monday_start,$sunday_end];
888 889
 // }
889 890
 
891
+
892
+
893
+
890 894
     /**
891 895
      * 获取用户星级
892 896
      */
@@ -905,13 +909,12 @@ class Taskorder extends BaseController
905 909
                 $team_money += $amount;
906 910
             }
907 911
             //计算自己的共建联盟流水
908
-            // $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
909
-            // $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
912
+
910 913
             $user_team_amount = $this->getperteamcomm($common_nums,$user_id);
911 914
 
912 915
 
913 916
             $team_money += $user_team_amount;
914
-//return $team_money;//115500
917
+
915 918
 
916 919
         }else{
917 920
             $common_nums = $this->getCommonNums($user_id);
@@ -939,6 +942,15 @@ class Taskorder extends BaseController
939 942
             $person_nums = $this->getPersonageNums($user_id);
940 943
 
941 944
         }
945
+        //计算个人在2.0新表中的业绩 start
946
+
947
+        $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门
948
+        $person_money +=  $team_small_big_amount[1];
949
+        $team_money += $team_small_big_amount[0];
950
+
951
+        //end
952
+
953
+
942 954
 
943 955
         //默认是小联盟,如果大联盟业绩比小联盟低,那就谁选业绩低的
944 956
         $slow = $person_money;
@@ -946,12 +958,7 @@ class Taskorder extends BaseController
946 958
             $slow = $team_money;
947 959
         }
948 960
         $sum_money = $team_money + $person_money;
949
-        // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
950
-        // $this->error(0,$data);
951
-        //$star_list = Db::name("user_star")->order("statement_all_num desc")->select();
952 961
 
953
-        // $sum_money = 1000000;
954
-        // $slow = 300000;
955 962
 
956 963
         // var_dump($sum_money);
957 964
         // var_dump($slow);
@@ -1141,9 +1148,151 @@ class Taskorder extends BaseController
1141 1148
 
1142 1149
         $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
1143 1150
 
1151
+
1152
+        //计算个人在2.0新表中的业绩 start
1153
+
1154
+        $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门
1155
+        $total_team_amount3 =  $team_small_big_amount[0] +  $team_small_big_amount[1];
1156
+        $sum_nums_pv += $total_team_amount3;
1157
+
1158
+        //end
1159
+
1144 1160
         return $sum_nums_pv;
1145 1161
     }
1146 1162
 
1163
+    //计算自己和自己团队下面的业绩。新表
1164
+    public function calculatePerformance($uid)
1165
+    {
1166
+        // 初始化业绩数组
1167
+        $performance = [
1168
+
1169
+            'personal_performance' => 0, // 个人业绩
1170
+            'team_performance' => 0, // 团队业绩
1171
+            'total_performance' => 0, // 总业绩
1172
+            'team_count' => 0, // 加上自己的团队数量
1173
+
1174
+        ];
1175
+
1176
+        // 定义业绩换算规则
1177
+        $performanceMapping = [
1178
+            1180 => 700,
1179
+            10620 => 6300,
1180
+            11800 => 7000,
1181
+            9440 => 5600,
1182
+            2360 => 1400
1183
+        ];
1184
+
1185
+        // 计算个人业绩
1186
+        $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
1187
+
1188
+        if ($personalOrder) {
1189
+            // 将浮点数转换为整数
1190
+            $totalPrice = (int)$personalOrder['total_price'];
1191
+            if (isset($performanceMapping[$totalPrice])) {
1192
+                $performance['personal_performance'] = $performanceMapping[$totalPrice];
1193
+            }
1194
+        }
1195
+
1196
+        // 计算旗下团队成员的业绩
1197
+        $teamOrders = Db::name('user')
1198
+            ->alias('u')
1199
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1200
+            ->where("u.spread_uid", $uid) // 查询旗下会员
1201
+            ->where("so.mer_id", 496)
1202
+            // ->where("so.douhuomall", 1)
1203
+            // ->where("so.douhuomall_status", 9)
1204
+            // ->where("so.status", 0)
1205
+            ->select();
1206
+
1207
+        $teamOrders_count = Db::name('user')
1208
+            ->alias('u')
1209
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1210
+            ->where("u.spread_uid", $uid) // 查询旗下会员
1211
+            ->where("so.mer_id", 496)
1212
+            // ->where("so.douhuomall", 1)
1213
+            // ->where("so.douhuomall_status", 9)
1214
+            // ->where("so.status", 0)
1215
+            ->count();
1216
+
1217
+        $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
1218
+
1219
+        foreach ($teamOrders as $order) {
1220
+            if ($order['total_price']) {
1221
+                // 将浮点数转换为整数
1222
+                $totalPrice = (int)$order['total_price'];
1223
+                if (isset($performanceMapping[$totalPrice])) {
1224
+                    $performance['team_performance'] += $performanceMapping[$totalPrice];
1225
+                }
1226
+            }
1227
+        }
1228
+
1229
+        // 计算总业绩
1230
+        $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
1231
+
1232
+        // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
1233
+        return $performance;
1234
+    }
1235
+
1236
+//获取大小部门业绩(新表小标0是大部门,下标1是小部门)
1237
+    public function getbig_samll_datas($user_id) {
1238
+
1239
+        $subordinate_members = Db::name('user')
1240
+            ->alias('u')
1241
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1242
+            ->where("u.spread_uid", $user_id)
1243
+            ->where("so.mer_id", 496)
1244
+            ->group('u.uid')
1245
+
1246
+            ->select();
1247
+
1248
+        // 单独写一个方法获取大小部门的数据
1249
+        $arr_team = [];
1250
+        foreach ($subordinate_members as $k => $v) {
1251
+            // 计算自己和旗下的业绩
1252
+            $arr_team[] = $this->calculatePerformance($v['uid']);
1253
+        }
1254
+
1255
+        // 初始化变量
1256
+        $maxPerformance = 0;
1257
+        $maxIndex = -1;
1258
+
1259
+        // 找出 total_performance 最高的记录
1260
+        foreach ($arr_team as $index => $item) {
1261
+            if ($item['total_performance'] > $maxPerformance) {
1262
+                $maxPerformance = $item['total_performance'];
1263
+                $maxIndex = $index;
1264
+            }
1265
+        }
1266
+
1267
+        // 如果找到了最高记录
1268
+        if ($maxIndex !== -1) {
1269
+            // 提取最高记录
1270
+            $maxRecord = $arr_team[$maxIndex];
1271
+            // 从原数组中移除该记录
1272
+            unset($arr_team[$maxIndex]);
1273
+            // 重新索引数组
1274
+            $arr_team = array_values($arr_team);
1275
+        } else {
1276
+            // 如果没有找到记录,可以设置一个默认值
1277
+            $maxRecord = null;
1278
+        }
1279
+
1280
+        // 计算大部门和小部门的汇总信息
1281
+        $majorDepartmentSummary = [
1282
+            "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
1283
+        ];
1284
+
1285
+        $minorDepartmentSummary = [
1286
+            "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
1287
+        ];
1288
+
1289
+        // 返回所需的结果
1290
+        return [
1291
+            $majorDepartmentSummary['total_performance'],
1292
+            $minorDepartmentSummary['total_performance']
1293
+        ];
1294
+    }
1295
+
1147 1296
 
1148 1297
     /**
1149 1298
      * 释放待发放佣金
@@ -1272,25 +1421,31 @@ class Taskorder extends BaseController
1272 1421
         }
1273 1422
 
1274 1423
         //添加自己共建联盟的流水
1275
-        // $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
1276
-        // $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
1424
+
1277 1425
         $user_team_amount = $this->getperteamcomm($common_nums,$user_id);
1278 1426
         $team_amount += $user_team_amount;
1279 1427
 
1280 1428
         // //计算自己的个人联盟总流水
1281
-        // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
1282
-        // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
1429
+
1283 1430
         $user_person_amount = $this->getperteamcomm($person_nums,$user_id);
1284 1431
         $person_amount += $user_person_amount;
1285 1432
 
1286
-        //var_dump($person_amount);
1287
-        // var_dump($team_amount);
1288
-
1289 1433
         //默认是小联盟,如果大联盟业绩比小联盟低,那就谁选业绩低的
1290 1434
         // 确定最小值和最大值
1291 1435
         $minValue = min($person_amount, $team_amount);
1292 1436
         $maxValue = max($person_amount, $team_amount);
1293
-        //var_dump(array($minValue, $maxValue));
1437
+
1438
+
1439
+        //计算个人在2.0新表中的业绩 start
1440
+
1441
+        $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门
1442
+        $minValue  +=  $team_small_big_amount[1];
1443
+        $maxValue  +=  $team_small_big_amount[0];
1444
+
1445
+
1446
+        //end
1447
+
1448
+
1294 1449
 
1295 1450
         // 返回包含最小值和最大值的数组
1296 1451
         return array($minValue, $maxValue);