Explorar el Código

Merge branch 'master' into huangfamily

family hace 1 año
padre
commit
5ad28ae58a

+ 18 - 0
app/common.php

@@ -897,3 +897,21 @@ if (!function_exists("is_json")){
897 897
         return true;
898 898
     }
899 899
 }
900
+
901
+
902
+
903
+if (!function_exists("roundOptimize")){
904
+    /**
905
+     * round公用四舍五入去除
906
+     * @param $number
907
+     * @return string
908
+     */
909
+    function roundOptimize($amount, $decimals = 2): string
910
+    {
911
+        if ($amount > 0) {
912
+            $factor = pow(10, $decimals);
913
+            return floor($amount * $factor) / $factor;
914
+        }
915
+        return $amount;
916
+    }
917
+}

+ 448 - 7
app/common/repositories/finance/FinanceRepository.php

@@ -16,6 +16,7 @@ use app\common\repositories\user\UserRepository;
16 16
 use think\Exception;
17 17
 use think\facade\Db;
18 18
 use think\facade\Request;
19
+use crmeb\services\SpreadsheetExcelService;
19 20
 
20 21
 class FinanceRepository extends BaseRepository
21 22
 {
@@ -469,6 +470,126 @@ class FinanceRepository extends BaseRepository
469 470
         $query2 = clone $query;
470 471
         $query3 = clone $query;
471 472
         $query4 = clone $query;
473
+
474
+
475
+        //导出数据
476
+        $is_excel = request()->param('is_excel', 0);
477
+        if($is_excel == 1){
478
+            $date['list'] = $this->date_where($query, $where['date'], 'ub.create_time')
479
+            ->field('ub.bill_id,ub.title,ub.number,ub.mark,ub.take_time,ub.commission_type,u.uid,u.phone,u.nickname,u.user_group,ub.order_sn,ub.take_time,ub.status,ub.create_time')
480
+            ->order('ub.bill_id', 'desc')
481
+            ->select();
482
+
483
+            if (isset($params['commission_type']) && $params['commission_type'] == 5) {
484
+                $title = '养老金账单';
485
+                $arr = [];
486
+                foreach ($date['list'] as $k=>$item){
487
+                    switch ($item['status']) {
488
+                        case '1':
489
+                            $item['status'] = '有效';
490
+                            break;
491
+                        case '-1':
492
+                            $item['status'] = '已失效';
493
+                            break;
494
+                        case '0':
495
+                            $item['status'] = '待确定';
496
+                            break;
497
+                    }
498
+                    switch ($item['user_group']) {
499
+                        case '1':
500
+                            $item['user_group'] = '消费者';
501
+                            break;
502
+                        case '2':
503
+                            $item['user_group'] = '业务员';
504
+                            break;
505
+                        case '3':
506
+                            $item['user_group'] = '业务经理';
507
+                            break;
508
+                        case '4':
509
+                            $item['user_group'] = '初级合伙人';
510
+                            break;
511
+                        case '5':
512
+                            $item['user_group'] = '中级合伙人';
513
+                            break;
514
+                        case '6':
515
+                            $item['user_group'] = '高级合伙人';
516
+                            break;
517
+                        case '7':
518
+                            $item['user_group'] = '董事';
519
+                            break;
520
+                    }
521
+                    $arr[] = array(
522
+                        $item['bill_id'],
523
+                        $item['create_time'],
524
+                        $item['nickname'],
525
+                        $item['phone'],
526
+                        $item['user_group'],
527
+                        $item['number'],
528
+                        $item['status'],
529
+                        $item['order_sn'],
530
+                        $item['mark']
531
+                    );
532
+                }
533
+                return $this->getStatisticsExcel([
534
+                    'ID','时间','用户昵称','手机号','当前身份','金额','状态','关联订单','说名',
535
+                ], $arr, $title);
536
+            } else {
537
+                $title = '佣金账单';
538
+                $arr = [];
539
+                foreach ($date['list'] as $k=>$item){
540
+                    switch ($item['status']) {
541
+                        case '1':
542
+                            $item['status'] = '有效';
543
+                            break;
544
+                        case '-1':
545
+                            $item['status'] = '已失效';
546
+                            break;
547
+                        case '0':
548
+                            $item['status'] = '待确定';
549
+                            break;
550
+                    }
551
+                    switch ($item['user_group']) {
552
+                        case '1':
553
+                            $item['user_group'] = '消费者';
554
+                            break;
555
+                        case '2':
556
+                            $item['user_group'] = '业务员';
557
+                            break;
558
+                        case '3':
559
+                            $item['user_group'] = '业务经理';
560
+                            break;
561
+                        case '4':
562
+                            $item['user_group'] = '初级合伙人';
563
+                            break;
564
+                        case '5':
565
+                            $item['user_group'] = '中级合伙人';
566
+                            break;
567
+                        case '6':
568
+                            $item['user_group'] = '高级合伙人';
569
+                            break;
570
+                        case '7':
571
+                            $item['user_group'] = '董事';
572
+                            break;
573
+                    }
574
+                    $arr[] = array(
575
+                        $item['bill_id'],
576
+                        $item['create_time'],
577
+                        $item['nickname'],
578
+                        $item['phone'],
579
+                        $item['user_group'],
580
+                        $item['number'],
581
+                        $item['status'],
582
+                        $item['order_sn'],
583
+                        $item['mark']
584
+                    );
585
+                }
586
+                return $this->getStatisticsExcel([
587
+                    'ID','时间','用户昵称','手机号','当前身份','金额','状态','关联订单','说名',
588
+                ], $arr, $title);
589
+            }
590
+        }
591
+
592
+
472 593
         $data['list'] = $this->date_where($query, $where['date'], 'ub.create_time')
473 594
             ->field('ub.bill_id,ub.title,ub.number,ub.mark,ub.take_time,ub.commission_type,u.uid,u.phone,u.nickname,u.user_group,ub.order_sn,ub.take_time,ub.status,ub.create_time')
474 595
             ->order('ub.bill_id', 'desc')
@@ -633,6 +754,43 @@ class FinanceRepository extends BaseRepository
633 754
         $query5 = clone $query;
634 755
         $query6 = clone $query;
635 756
         $query7 = clone $query;
757
+
758
+        //导出数据
759
+        $is_excel = request()->param('is_excel', 0);
760
+        if($is_excel == 1){
761
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
762
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.pm,uss.reward_socre,o.order_sn,uss.status,uss.mark,u.score')
763
+            ->order('uss.id', 'desc')
764
+            ->select();
765
+            $arr = [];
766
+            foreach ($date['list'] as $k=>$item){
767
+                switch ($item['status']) {
768
+                    case '1':
769
+                        $item['status'] = '有效';
770
+                        break;
771
+                    case '-1':
772
+                        $item['status'] = '待确认';
773
+                        break;
774
+                    case '0':
775
+                        $item['status'] = '已失效';
776
+                        break;
777
+                }
778
+                $arr[] = array(
779
+                    $item['id'],
780
+                    date('Y-m-d H:i:s', $item['addtime']),
781
+                    $item['nickname'],
782
+                    $item['phone'],
783
+                    $item['reward_socre'],
784
+                    $item['status'],
785
+                    $item['order_sn'],
786
+                    $item['mark']
787
+                );
788
+            }
789
+            return $this->getStatisticsExcel([
790
+                'ID','时间','用户昵称','手机号','积分数','结算状态','关联订单','说名',
791
+            ], $arr, '积分统计');
792
+        }
793
+
636 794
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
637 795
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.pm,uss.reward_socre,o.order_sn,uss.status,uss.mark,u.score')
638 796
             ->page($page, $limit)
@@ -703,6 +861,43 @@ class FinanceRepository extends BaseRepository
703 861
         $query5 = clone $query;
704 862
         $query6 = clone $query;
705 863
         $query7 = clone $query;
864
+
865
+        //导出数据
866
+        $is_excel = request()->param('is_excel', 0);
867
+        if($is_excel == 1){
868
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
869
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
870
+            ->order('uss.id', 'desc')
871
+            ->select();
872
+            $arr = [];
873
+            foreach ($date['list'] as $k=>$item){
874
+                switch ($item['status']) {
875
+                    case '1':
876
+                        $item['status'] = '有效';
877
+                        break;
878
+                    case '-1':
879
+                        $item['status'] = '待确认';
880
+                        break;
881
+                    case '0':
882
+                        $item['status'] = '已失效';
883
+                        break;
884
+                }
885
+                $arr[] = array(
886
+                    $item['id'],
887
+                    date('Y-m-d H:i:s', $item['addtime']),
888
+                    $item['nickname'],
889
+                    $item['phone'],
890
+                    $item['number'],
891
+                    $item['status'],
892
+                    $item['order_sn'],
893
+                    $item['mark']
894
+                );
895
+            }
896
+            return $this->getStatisticsExcel([
897
+                'ID','时间','用户昵称','手机号','京豆数','状态','关联订单','说名',
898
+            ], $arr, '京豆统计');
899
+        }
900
+
706 901
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
707 902
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
708 903
             ->page($page, $limit)
@@ -746,9 +941,6 @@ class FinanceRepository extends BaseRepository
746 941
         ->when(isset($params['uid']) && $params['uid'] != '', function ($query) use ($params) {
747 942
             $query->where('uss.uid', $params['uid']);
748 943
         })
749
-        // ->when(isset($params['pm']) && $params['pm'] != '', function ($query) use ($params) {
750
-        //     $query->where('uss.pm', $params['pm']);
751
-        // })
752 944
         ->when(isset($params['status']) && $params['status'] != '', function ($query) use ($params) {
753 945
             $query->where('uss.status', $params['status']);
754 946
         })
@@ -765,6 +957,43 @@ class FinanceRepository extends BaseRepository
765 957
         $query5 = clone $query;
766 958
         $query6 = clone $query;
767 959
         $query7 = clone $query;
960
+
961
+        //导出数据
962
+        $is_excel = request()->param('is_excel', 0);
963
+        if($is_excel == 1){
964
+            $date['list'] =  $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
965
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
966
+            ->order('uss.number', 'desc')
967
+            ->select();
968
+            $arr = [];
969
+            foreach ($date['list'] as $k=>$item){
970
+                switch ($item['status']) {
971
+                    case '1':
972
+                        $item['status'] = '有效';
973
+                        break;
974
+                    case '-1':
975
+                        $item['status'] = '待确认';
976
+                        break;
977
+                    case '0':
978
+                        $item['status'] = '已失效';
979
+                        break;
980
+                }
981
+                $arr[] = array(
982
+                    $item['id'],
983
+                    date('Y-m-d H:i:s', $item['addtime']),
984
+                    $item['nickname'],
985
+                    $item['phone'],
986
+                    $item['number'],
987
+                    $item['status'],
988
+                    $item['order_sn'],
989
+                    $item['mark']
990
+                );
991
+            }
992
+            return $this->getStatisticsExcel([
993
+                'ID','时间','用户昵称','手机号','贡献值数','贡献值状态','关联订单','说名',
994
+            ], $arr, '贡献值统计');
995
+        }
996
+
768 997
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
769 998
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
770 999
             ->page($page, $limit)
@@ -836,6 +1065,43 @@ class FinanceRepository extends BaseRepository
836 1065
         $query5 = clone $query;
837 1066
         $query6 = clone $query;
838 1067
         $query7 = clone $query;
1068
+
1069
+        //导出数据
1070
+        $is_excel = request()->param('is_excel', 0);
1071
+        if($is_excel == 1){
1072
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1073
+            ->field('uss.id,uss.addtime,uss.commission_type,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
1074
+            ->order('uss.id', 'desc')
1075
+            ->select();
1076
+            $arr = [];
1077
+            foreach ($date['list'] as $k=>$item){
1078
+                switch ($item['status']) {
1079
+                    case '1':
1080
+                        $item['status'] = '有效';
1081
+                        break;
1082
+                    case '-1':
1083
+                        $item['status'] = '待确认';
1084
+                        break;
1085
+                    case '0':
1086
+                        $item['status'] = '已失效';
1087
+                        break;
1088
+                }
1089
+                $arr[] = array(
1090
+                    $item['id'],
1091
+                    date('Y-m-d H:i:s', $item['addtime']),
1092
+                    $item['nickname'],
1093
+                    $item['phone'],
1094
+                    $item['number'],
1095
+                    $item['status'],
1096
+                    $item['order_sn'],
1097
+                    $item['mark']
1098
+                );
1099
+            }
1100
+            return $this->getStatisticsExcel([
1101
+                'ID','时间','用户昵称','手机号','复购金数','复购金状态','关联订单','说名',
1102
+            ], $arr, '复购金统计');
1103
+        }
1104
+
839 1105
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
840 1106
             ->field('uss.id,uss.addtime,uss.commission_type,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
841 1107
             ->page($page, $limit)
@@ -898,6 +1164,43 @@ class FinanceRepository extends BaseRepository
898 1164
         $query5 = clone $query;
899 1165
         $query6 = clone $query;
900 1166
         $query7 = clone $query;
1167
+
1168
+        //导出数据
1169
+        $is_excel = request()->param('is_excel', 0);
1170
+        if($is_excel == 1){
1171
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1172
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
1173
+            ->order('uss.id', 'desc')
1174
+            ->select();
1175
+            $arr = [];
1176
+            foreach ($date['list'] as $k=>$item){
1177
+                switch ($item['status']) {
1178
+                    case '1':
1179
+                        $item['status'] = '有效';
1180
+                        break;
1181
+                    case '-1':
1182
+                        $item['status'] = '待确认';
1183
+                        break;
1184
+                    case '0':
1185
+                        $item['status'] = '已失效';
1186
+                        break;
1187
+                }
1188
+                $arr[] = array(
1189
+                    $item['id'],
1190
+                    date('Y-m-d H:i:s', $item['addtime']),
1191
+                    $item['nickname'],
1192
+                    $item['phone'],
1193
+                    $item['number'],
1194
+                    $item['status'],
1195
+                    $item['order_sn'],
1196
+                    $item['mark']
1197
+                );
1198
+            }
1199
+            return $this->getStatisticsExcel([
1200
+                'ID','时间','用户昵称','手机号','红包数','红包状态','关联订单','说名',
1201
+            ], $arr, '红包统计');
1202
+        }
1203
+
901 1204
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
902 1205
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.status,uss.mark,u.score')
903 1206
             ->page($page, $limit)
@@ -962,6 +1265,39 @@ class FinanceRepository extends BaseRepository
962 1265
         $query5 = clone $query;
963 1266
         $query6 = clone $query;
964 1267
         $query7 = clone $query;
1268
+
1269
+        //导出数据
1270
+        $is_excel = request()->param('is_excel', 0);
1271
+        if($is_excel == 1){
1272
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1273
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.type,uss.mark,u.score')
1274
+            ->order('uss.id', 'desc')
1275
+            ->select();
1276
+            $arr = [];
1277
+            foreach ($date['list'] as $k=>$item){
1278
+                switch ($item['type']) {
1279
+                    case '1':
1280
+                        $item['type'] = '转入';
1281
+                        break;
1282
+                    case '2':
1283
+                        $item['type'] = '消耗';
1284
+                        break;
1285
+                }
1286
+                $arr[] = array(
1287
+                    $item['id'],
1288
+                    date('Y-m-d H:i:s', $item['addtime']),
1289
+                    $item['nickname'],
1290
+                    $item['phone'],
1291
+                    $item['number'],
1292
+                    $item['type'],
1293
+                    $item['mark']
1294
+                );
1295
+            }
1296
+            return $this->getStatisticsExcel([
1297
+                'ID','时间','用户昵称','手机号','VR数','VR类型','说名',
1298
+            ], $arr, 'VR统计');
1299
+        }
1300
+
965 1301
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
966 1302
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,uss.type,uss.mark,u.score')
967 1303
             ->page($page, $limit)
@@ -994,10 +1330,10 @@ class FinanceRepository extends BaseRepository
994 1330
         $where = request()->params(['date']);
995 1331
         $params = request()->params([ 'uid', 'pm', 'phone','status']);
996 1332
 
997
-        if($params['status'] == 99){
998
-            unset($params['status']);
999
-            $params['type'] = 2;
1000
-        }
1333
+        // if($params['status'] == 99){
1334
+        //     unset($params['status']);
1335
+        //     $params['type'] = 2;
1336
+        // }
1001 1337
 
1002 1338
         $date = [];
1003 1339
         //商户ID
@@ -1024,6 +1360,44 @@ class FinanceRepository extends BaseRepository
1024 1360
         $query5 = clone $query;
1025 1361
         $query6 = clone $query;
1026 1362
         $query7 = clone $query;
1363
+
1364
+        //导出数据
1365
+        $is_excel = request()->param('is_excel', 0);
1366
+        if($is_excel == 1){
1367
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1368
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.pv,o.order_sn,uss.status,uss.mark,u.score')
1369
+            ->order('uss.id', 'desc')
1370
+            ->select();
1371
+            $arr = [];
1372
+            foreach ($date['list'] as $k=>$item){
1373
+                switch ($item['status']) {
1374
+                    case '1':
1375
+                        $item['status'] = '有效';
1376
+                        break;
1377
+                    case '-1':
1378
+                        $item['status'] = '待确认';
1379
+                        break;
1380
+                    case '0':
1381
+                        $item['status'] = '已失效';
1382
+                        break;
1383
+                }
1384
+                $arr[] = array(
1385
+                    $item['id'],
1386
+                    date('Y-m-d H:i:s', $item['addtime']),
1387
+                    $item['nickname'],
1388
+                    $item['phone'],
1389
+                    $item['pv'],
1390
+                    $item['status'],
1391
+                    $item['order_sn'],
1392
+                    $item['mark']
1393
+                );
1394
+            }
1395
+            return $this->getStatisticsExcel([
1396
+                'ID','时间','用户昵称','手机号','PV数','状态','关联订单','说名',
1397
+            ], $arr, 'PV统计');
1398
+        }
1399
+
1400
+
1027 1401
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1028 1402
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.pv,o.order_sn,uss.status,uss.mark,u.score')
1029 1403
             ->page($page, $limit)
@@ -1088,6 +1462,42 @@ class FinanceRepository extends BaseRepository
1088 1462
         $query5 = clone $query;
1089 1463
         $query6 = clone $query;
1090 1464
         $query7 = clone $query;
1465
+
1466
+        //导出数据
1467
+        $is_excel = request()->param('is_excel', 0);
1468
+        if($is_excel == 1){
1469
+            $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1470
+            ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,o.total_price,uss.status,uss.mark,u.score,m.mer_name')
1471
+            ->order('uss.id', 'desc')
1472
+            ->select();
1473
+            $arr = [];
1474
+            foreach ($date['list'] as $k=>$item){
1475
+                switch ($item['status']) {
1476
+                    case '1':
1477
+                        $item['status'] = '有效';
1478
+                        break;
1479
+                    case '-1':
1480
+                        $item['status'] = '待确认';
1481
+                        break;
1482
+                    case '0':
1483
+                        $item['status'] = '已失效';
1484
+                        break;
1485
+                }
1486
+                $arr[] = array(
1487
+                    $item['id'],
1488
+                    date('Y-m-d H:i:s', $item['addtime']),
1489
+                    $item['number'],
1490
+                    $item['total_price'],
1491
+                    $item['status'],
1492
+                    $item['mer_name'],
1493
+                    $item['order_sn']
1494
+                );
1495
+            }
1496
+            return $this->getStatisticsExcel([
1497
+                'ID','时间','商户分润金额','订单金额','状态','店铺名称','关联订单',
1498
+            ], $arr, '商户分润统计');
1499
+        }
1500
+
1091 1501
         $date['list'] = $this->date_where($query, $where['date'], 'uss.addtime', '-', 2)
1092 1502
             ->field('uss.id,uss.addtime,u.nickname,u.phone,uss.number,o.order_sn,o.total_price,uss.status,uss.mark,u.score,m.mer_name')
1093 1503
             ->page($page, $limit)
@@ -1108,6 +1518,37 @@ class FinanceRepository extends BaseRepository
1108 1518
     }
1109 1519
 
1110 1520
 
1521
+    /**
1522
+     * 获取统计导出
1523
+     */
1524
+    public function getStatisticsExcel($header,$arr,$title)
1525
+    {
1526
+        $filename = $title.'_'.date('YmdHis').'_'.rand(10000,99999);
1527
+        $name = $filename;
1528
+        $info = '生成时间:' . date('Y-m-d H:i:s',time());
1529
+        $suffix='xlsx';
1530
+        $path='extract';
1531
+        unset($_instance);
1532
+
1533
+        $_instance = SpreadsheetExcelService::instance_xin();
1534
+
1535
+        $_path =$_instance
1536
+            ->createOrActive()
1537
+            ->setExcelHeader($header)
1538
+            ->setExcelTile($title, $name, $info)
1539
+            ->setExcelContent($arr)
1540
+            ->excelSave($filename, $suffix, $path);
1541
+
1542
+        $domain = request()->domain();
1543
+        $data= [
1544
+            'name' => $filename.'.'.$suffix,
1545
+            'status' => 1,
1546
+            'path' => $domain.'/'.$_path
1547
+        ];
1548
+
1549
+        return $data;
1550
+    }
1551
+
1111 1552
 
1112 1553
     /**
1113 1554
      * 列表中的时间条件

+ 45 - 26
app/common/repositories/store/order/StoreOrderRepository.php

@@ -3684,6 +3684,21 @@ class StoreOrderRepository extends BaseRepository
3684 3684
     public function yugu_rebate_gong_fu($order)
3685 3685
     {
3686 3686
 
3687
+        $make="";
3688
+        $type_shop = $order['type_shop']??0;
3689
+        if($type_shop==1){
3690
+            $make="拼多多";
3691
+        }else if($type_shop==5){
3692
+            $make="淘宝";
3693
+        }else if($type_shop==6){
3694
+            $make="京东";
3695
+        }else if($type_shop==3){
3696
+            $make="苏宁";
3697
+        }else if($type_shop==2){
3698
+            $make="唯品会";
3699
+        }else if($type_shop==9){
3700
+            $make="话费";
3701
+        }
3687 3702
 
3688 3703
         $order_sn = $order["order_sn"];
3689 3704
         log::info("进入添加养老金{$order['order_sn']}");
@@ -3729,11 +3744,11 @@ class StoreOrderRepository extends BaseRepository
3729 3744
         log::info("++{$order['total_price']}+返回佣金===={$oldagefee}");
3730 3745
         //当前已扣会费总额
3731 3746
 //            $oldagefee = $oldagefee-$dues;
3732
-        $mark = "消费获得养老金" . $oldagefee;
3747
+        $mark = $make."消费获得养老金" . $oldagefee;
3733 3748
 
3734 3749
         //end会费
3735 3750
         //sat存养老金
3736
-        $title = "养老金 ";
3751
+        $title = "养老金";
3737 3752
         $commission_type = 5;
3738 3753
         if ($oldagefee >= 0.01) {
3739 3754
             $this->add_bill($title, $oldagefee, $order["uid"], $mark, $commission_type, $order_sn, $order_id, $order["mer_id"], 0, 0, $order["type_shop"]);
@@ -3749,7 +3764,7 @@ class StoreOrderRepository extends BaseRepository
3749 3764
         $zijiUser = Db::name("user")->where('uid', $order["uid"])->find();
3750 3765
         // 老用户发红包奖励
3751 3766
         if($zijiUser['is_old'] == 1){
3752
-            $this->giveHongBao($order["uid"], $pvfee, $order_id, '消费赠送红包');
3767
+            $this->giveHongBao($order["uid"], $pvfee, $order_id, $make.'消费赠送红包');
3753 3768
         }
3754 3769
         $sprerdUser = Db::name("user")->where('uid', $zijiUser['spread_uid'])->find();
3755 3770
         //不为空的时候进行添加推荐奖励
@@ -3808,17 +3823,17 @@ class StoreOrderRepository extends BaseRepository
3808 3823
                 $yongjinbili = 17;
3809 3824
             }
3810 3825
 
3826
+            //计算出佣金
3811 3827
             $yongjin = $pvfee * $yongjinbili / 100;
3812
-            // 佣金百分之90进入佣金池
3813
-            // $tuiguanyongjin = round($yongjin * 0.9, 2);
3814
-            $tuiguanyongjin = bcmul($pvfee, $yongjinbili / 100, 2);
3815
-
3816 3828
 
3817
-            $tuiYongmark = "推荐消费获得佣金" . $tuiguanyongjin;
3829
+            // 佣金百分之90进入佣金池  佣金百分之10进入复购金
3830
+            $tuiguanyongjin = roundOptimize($yongjin * 0.9, 2);
3831
+            $tuiguanfugou = $yongjin;//复购金赠送函数里面有计算百分之10
3818 3832
 
3819 3833
             //end会费
3820 3834
             //sat存养老金
3821 3835
             $tuiYongzhoutitle = "推广佣金 ";
3836
+            $tuiYongmark = "推荐消费获得佣金" . $tuiguanyongjin;
3822 3837
             $commission_yong_type = 3;
3823 3838
             if ($tuiguanyongjin >= 0.01) {
3824 3839
                 $this->add_bill($tuiYongzhoutitle, $tuiguanyongjin, $sprerdUser["uid"], $tuiYongmark, $commission_yong_type, $order_sn, $order_id, $order["mer_id"], 0, 0, $order["type_shop"]);
@@ -3826,12 +3841,12 @@ class StoreOrderRepository extends BaseRepository
3826 3841
                 Db::name('log')->insert(['data' => '订单号:' . $order_sn . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
3827 3842
             }
3828 3843
 
3829
-            if($yongjin >= 0.1){
3844
+            if($tuiguanfugou >= 0.1){
3830 3845
                 // 佣金百分之10进入复购金
3831 3846
                 $orderThird = app()->make(UserThirdRepository::class);
3832 3847
                 //复购金
3833 3848
                 $orderThird->yuguFugou(
3834
-                    $yongjin,
3849
+                    $tuiguanfugou,
3835 3850
                     $sprerdUser["uid"],
3836 3851
                     $order_sn,
3837 3852
                     $order["type_shop"]
@@ -9609,8 +9624,10 @@ class StoreOrderRepository extends BaseRepository
9609 9624
                 // 贡献值
9610 9625
                 $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送贡献值");
9611 9626
                 $this->con_log_pv($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送PV值");
9612
-                // 红包
9613
-                $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买精彩生活商品赠送红包');
9627
+                if (!empty($user_data['is_old'])) {
9628
+                    // 红包
9629
+                    $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买精彩生活商品赠送红包');
9630
+                }
9614 9631
                 // 积分
9615 9632
                 $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送积分");
9616 9633
 
@@ -9622,8 +9639,8 @@ class StoreOrderRepository extends BaseRepository
9622 9639
                     $rate = static::getUserGroupRate($spread_data['user_group']);
9623 9640
 
9624 9641
                     if ($spread_data['user_group'] == 1) {
9625
-                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
9626
-                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9642
+                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
9643
+                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
9627 9644
 
9628 9645
                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
9629 9646
 
@@ -9637,8 +9654,8 @@ class StoreOrderRepository extends BaseRepository
9637 9654
                     } else if ($spread_data['user_group'] > 1) {
9638 9655
 
9639 9656
                         $ssf = bcmul($pv, $rate, 2);
9640
-                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
9641
-                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9657
+                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
9658
+                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
9642 9659
                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
9643 9660
 
9644 9661
                         //贡献值
@@ -9658,8 +9675,8 @@ class StoreOrderRepository extends BaseRepository
9658 9675
                     $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
9659 9676
                     if (!empty($merchant_user_data)) {
9660 9677
                         //给推广者分配佣金
9661
-                        $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
9662
-                        $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9678
+                        $yj_amount_90 = bcmul($pv * 0.9, 0.05, 2);
9679
+                        $fgj_amount_10 = bcmul($pv * 0.1, 0.05, 2);//推广者的佣金抽10%到个人复购金
9663 9680
                         //推广佣金
9664 9681
                         $this->bill_user_log($merchant_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $store_order_data['order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
9665 9682
                     }
@@ -9837,8 +9854,10 @@ class StoreOrderRepository extends BaseRepository
9837 9854
                 $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送贡献值");
9838 9855
                 // 购买商贸区赠送PV值
9839 9856
                 $this->con_log_pv($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区赠送PV值");
9840
-                // 红包
9841
-                $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买商贸区商品赠送红包');
9857
+                if (!empty($user_data['is_old'])) {
9858
+                    // 红包
9859
+                    $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买商贸区商品赠送红包');
9860
+                }
9842 9861
                 // 积分
9843 9862
                 $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
9844 9863
 
@@ -9849,8 +9868,8 @@ class StoreOrderRepository extends BaseRepository
9849 9868
                     $rate = static::getUserGroupRate($spread_data['user_group']);
9850 9869
                     if ($spread_data['user_group'] > 1) {
9851 9870
                         $ssf = bcmul($pv, $rate, 2);
9852
-                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
9853
-                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9871
+                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
9872
+                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
9854 9873
                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
9855 9874
 
9856 9875
                         //贡献值
@@ -9867,8 +9886,8 @@ class StoreOrderRepository extends BaseRepository
9867 9886
                     if ($spread_data['user_group'] == 1) {
9868 9887
                         //给推广者分配佣金
9869 9888
 
9870
-                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
9871
-                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9889
+                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
9890
+                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
9872 9891
 
9873 9892
                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
9874 9893
 
@@ -9887,8 +9906,8 @@ class StoreOrderRepository extends BaseRepository
9887 9906
                     $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
9888 9907
                     if (!empty($merchant_user_data)) {
9889 9908
                         //给推广者分配佣金
9890
-                        $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
9891
-                        $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
9909
+                        $yj_amount_90 = bcmul($pv * 0.9, 0.05, 2);
9910
+                        $fgj_amount_10 = bcmul($pv * 0.1, 0.05, 2);//推广者的佣金抽10%到个人复购金
9892 9911
                         $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
9893 9912
                         //推广佣金
9894 9913
                         $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);

+ 12 - 77
app/common/repositories/user/UserThirdRepository.php

@@ -747,7 +747,6 @@ class UserThirdRepository extends BaseRepository
747 747
     /**
748 748
      * 添加预估积分记录
749 749
      */
750
-//预估养老金
751 750
     public static function yuguJifen($price,$user_id,$order_sn,$type_shop)
752 751
     {
753 752
         if (empty($user_id)) {
@@ -775,14 +774,11 @@ class UserThirdRepository extends BaseRepository
775 774
 
776 775
             $sanfangfenpei=json_decode($systemvalueObj['value'],true);
777 776
             $inc_score = $gongxian = round($price*$sanfangfenpei['pv'],2);//pv=佣金的50%=积分=贡献值
778
-//            log::info("===========dddddddddddddddddddd");
779 777
 
780 778
 
781 779
             //每个表的统计值
782 780
             $jfzongwei=Db::name('user_sign_score')->where('status', -1)->where('uid', $user_id)->sum('reward_socre');
783 781
             $gxzongwei=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user_id)->sum('number');
784
-//            type_shop 1 拼多多 ,5淘宝
785
-//            log::info("==========={$jfzongwei}");
786 782
 
787 783
             $make="";
788 784
             if($type_shop==1){
@@ -817,26 +813,12 @@ class UserThirdRepository extends BaseRepository
817 813
                 ];
818 814
             log::info("{$make}==准备开始添加积分,贡献");
819 815
             Db::name("user_sign_score")->insert($data);//添加积分记录
820
-
821 816
             log::info("准备开始添加积分");
822
-//            $ins_data['uid'] = $user_id;
823
-//            $ins_data['reward_socre'] = $inc_score;
824
-//            $ins_data['addtime'] = time();
825
-//            $ins_data['status'] = -1;
826
-//            $ins_data['order_type'] = $type_shop;
827
-//            $ins_data['order_id'] = $order_sn;
828
-//            $ins_data['mark'] = "购买三方商品赠送积分";
829
-//            $ins_data['desc'] = '';
830
-//            $ins_data['surplus'] = $user_score + $inc_score;
831
-//            $ins_data['type'] = 1;
832
-//            $ins_data['pm'] = 1;
833
-//            $ins_data['source_type'] =3;
834 817
 
835 818
 
836 819
             //赠送贡献值
837 820
             $gongxian_data = [
838 821
                 "uid"           =>$user_id,
839
-//                "number"  =>    $inc_score,
840 822
                 "number"  =>    $gongxian,
841 823
                 "addtime"       =>time(),
842 824
                 "status"        =>-1,
@@ -847,21 +829,6 @@ class UserThirdRepository extends BaseRepository
847 829
                 "surplus"       =>$surplusgongxian+$gxzongwei,
848 830
                 "type"          =>1
849 831
             ];
850
-
851
-//            $gongxian_data['uid'] = $user_id;
852
-//            $gongxian_data['number'] = $inc_score;
853
-//            $gongxian_data['addtime'] = time();
854
-//            $gongxian_data['status'] = -1;
855
-//            $gongxian_data['order_type'] = $type_shop;
856
-//            $gongxian_data['order_id'] = $order_sn;
857
-//            $gongxian_data['mark'] = "购买三方商品赠送贡献值";
858
-//            $gongxian_data['desc'] = '';
859
-//            $gongxian_data['surplus'] = $user_score + $inc_score;
860
-//            $gongxian_data['type'] = 1;
861
-//            $gongxian_data['pm'] = 1;
862
-//            $gongxian_data['source_type'] =3;
863
-
864
-
865 832
             Db::name("user_sign_gongxian")->insert($gongxian_data);//添加贡献记录
866 833
             log::info("===添加完积分和贡献值");
867 834
 
@@ -880,7 +847,7 @@ class UserThirdRepository extends BaseRepository
880 847
             //判断是否是老用户  is_old=1是1.0的用户,1.0的用户要总pv*45%的红包
881 848
             if($user["is_old"]==1){
882 849
                 //添加红包
883
-                $hongbao=round($inc_score*0.45,2);
850
+                $hongbao=roundOptimize($inc_score*0.45,2);
884 851
                 $hongbao_data = [
885 852
                     "uid"           =>$user_id,
886 853
                     "number"  =>    $hongbao,
@@ -895,51 +862,20 @@ class UserThirdRepository extends BaseRepository
895 862
                 ];
896 863
                 Db::name("user_sign_hongbao")->insert($hongbao_data);//添加贡献记录
897 864
                 log::info("===添加完红包奖励");
898
-
899 865
             }
900 866
 
901 867
 
902
-
903 868
             // 添加推荐奖励
904 869
             $zijiUser=Db::name("user")->where('uid',$user_id)->find();
905 870
             $sprerdUser= Db::name("user")->where('uid',$zijiUser['spread_uid'])->find();
906 871
             //不为空的时候进行添加推荐奖励
907 872
             if($sprerdUser){
908
-                //奖励推广佣金
873
+                //奖励推广
909 874
                 $yongjinbili=0;
910
-                //普通用户
911
-                if($sprerdUser["user_group"]==1){
912
-                    $yongjinbili=5;
913
-                }
914
-                //业务员
915
-                if($sprerdUser["user_group"]==2){
916
-                    $yongjinbili=7;
917
-                }
918
-                //业务经理
919
-                if($sprerdUser["user_group"]==3){
920
-                    $yongjinbili=9;
921
-                }
922
-                //初级合伙人
923
-                if($sprerdUser["user_group"]==4){
924
-                    $yongjinbili=11;
925
-                }
926
-                //中级合伙人
927
-                if($sprerdUser["user_group"]==5){
928
-                    $yongjinbili=13;
929
-                }
930
-                //高级合伙人
931
-                if($sprerdUser["user_group"]==6){
932
-                    $yongjinbili=15;
933
-                }
934
-                //懂事
935
-                if($sprerdUser["user_group"]==7){
936
-                    $yongjinbili=17;
937
-                }
875
+        
938 876
                 // @todo 用户身份比例
939 877
                 $yongjinbili = StoreOrderRepository::getUserGroupRate($sprerdUser['user_group']);
940
-
941
-                $tuiguanyongjin=round($yongjinbili*$inc_score/100,2);//按照身份获得佣金
942
-
878
+                $tuiguanyongjin=roundOptimize($yongjinbili*$inc_score,2);//按照身份获得佣金
943 879
 
944 880
                 //添加推广积分
945 881
                 $tuijifendata = [
@@ -949,8 +885,8 @@ class UserThirdRepository extends BaseRepository
949 885
                     "status"        =>  -1,
950 886
                     "order_type"    =>  $type_shop,
951 887
                     "order_id"      =>  $order_sn,
952
-                    "mark"          =>  "推广消费从{$make}购买商品赠送积分",
953
-                    "surplus"       =>  $surplus,
888
+                    "mark"          =>  "推广{$make}商品赠送积分",
889
+                    "surplus"       =>  $sprerdUser['score'] + $tuiguanyongjin,
954 890
                     "pm"            =>  1,
955 891
                     "source_type"   =>  4
956 892
                 ];
@@ -958,26 +894,25 @@ class UserThirdRepository extends BaseRepository
958 894
                 Db::name("user_sign_score")->insert($tuijifendata);//添加积分记录
959 895
 
960 896
 
961
-                //添加推荐献值
897
+                //添加推荐献值 普通用户 贡献值为 pv* 30%;推广人是业务员及以上身份,贡献值为:pv的1:1
898
+                if($sprerdUser['user_group'] <= 1){
899
+                    $gongxian = roundOptimize($gongxian*0.3,2);
900
+                }
962 901
                 $tuigangongxian_data = [
963 902
                     "uid"           =>$sprerdUser['uid'],
964
-//                    "number"  =>    $tuiguanyongjin,
965 903
                     "number"  =>    $gongxian,
966 904
                     "addtime"       =>time(),
967 905
                     "status"        =>-1,
968 906
                     "order_type"    =>$type_shop,
969 907
                     "order_id"      =>$order_sn,
970
-                    "mark"          =>"推广消费从{$make}商品赠送贡献值",
908
+                    "mark"          =>"推广{$make}商品赠送贡献值",
971 909
                     "desc"          =>'',
972
-                    "surplus"       =>$surplusgongxian+$gxzongwei,
910
+                    "surplus"       => $sprerdUser['contribute'] + $gongxian,
973 911
                     "type"          =>1
974 912
                 ];
975 913
 
976 914
                 Db::name("user_sign_gongxian")->insert($tuigangongxian_data);//添加贡献记录
977 915
                 log::info("===添加完积分和贡献值");
978
-
979
-
980
-
981 916
             }
982 917
 
983 918
 

+ 21 - 21
app/controller/api/Auth.php

@@ -913,28 +913,28 @@ class Auth extends BaseController
913 913
 
914 914
     public function getteamsnum($teamid){
915 915
 
916
-        $subordinate_members = Db::name('user')
917
-            ->alias('u')
918
-            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
919
-            ->where("u.spread_uid", $teamid)
920
-            ->where("so.mer_id", 496)
921
-            ->group('u.uid')
922
-
923
-            ->select();
924
-
925
-
926
-        $total_amount_pv_team = 0;
927
-        $team_count_total = 0;
928
-
929
-        foreach ($subordinate_members as $k => $v) {
930
-            $t_teams_pv = $this->calculatePerformance($v['uid']);
931
-            $total_amount_pv_team += $t_teams_pv['total_performance'];
932
-            $team_count_total += $t_teams_pv['team_count'];
933
-
934
-
935
-        }
916
+//        $subordinate_members = Db::name('user')
917
+//            ->alias('u')
918
+//            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
919
+//            ->where("u.spread_uid", $teamid)
920
+//            ->where("so.mer_id", 496)
921
+//            ->group('u.uid')
922
+//
923
+//            ->select();
924
+//
925
+//
926
+//        $total_amount_pv_team = 0;
927
+//        $team_count_total = 0;
928
+//
929
+//        foreach ($subordinate_members as $k => $v) {
930
+//            $t_teams_pv = $this->calculatePerformance($v['uid']);
931
+//            $total_amount_pv_team += $t_teams_pv['total_performance'];
932
+//            $team_count_total += $t_teams_pv['team_count'];
933
+//
934
+//
935
+//        }
936 936
 
937
-        return $team_count_total;
937
+        return Db::name('user')->where(['spread_uid'=>$teamid])->count();
938 938
 
939 939
     }
940 940
 

+ 22 - 57
app/controller/api/Notify.php

@@ -187,8 +187,10 @@ class Notify
187 187
                                     $this->con_log_pv($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送pv");
188 188
                                     $this->con_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送贡献值");
189 189
                                     $this->score_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送积分");
190
-                                    // 红包
191
-                                    $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买精彩生活商品赠送红包');
190
+                                    if (!empty($user_data['is_old'])) {
191
+                                        // 红包
192
+                                        $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买精彩生活商品赠送红包');
193
+                                    }
192 194
 
193 195
                                     //给推广者分配养老金
194 196
                                     //给推广者分配佣金
@@ -198,8 +200,8 @@ class Notify
198 200
                                         $StoreOrderRepository = app()->make(StoreOrderRepository::class);
199 201
                                         $rate = $StoreOrderRepository->getUserGroupRate($spread_data['user_group']);
200 202
                                     if ($spread_data['user_group'] == 1) {
201
-                                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
202
-                                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
203
+                                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
204
+                                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
203 205
 
204 206
                                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
205 207
 
@@ -213,8 +215,8 @@ class Notify
213 215
                                     } else if ($spread_data['user_group'] > 1) {
214 216
 
215 217
                                         $ssf = bcmul($pv, $rate, 2);
216
-                                        $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
217
-                                        $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
218
+                                        $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
219
+                                        $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
218 220
                                         $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
219 221
 
220 222
                                         //贡献值
@@ -481,8 +483,8 @@ class Notify
481 483
                                     $uer_bill = $spread_data['annuity'] + bcmul($pv, 0.035,2);
482 484
 
483 485
 
484
-                                    $yj_amount_90 = $le_yw_amount * 0.9;
485
-                                    $fgj_amount_10 = $le_yw_amount * 0.1;//推广者的佣金抽10%到个人复购金
486
+                                    $yj_amount_90 = bcmul($le_yw_amount,0.9,2);
487
+                                    $fgj_amount_10 = bcmul($le_yw_amount,0.1,2);//推广者的佣金抽10%到个人复购金
486 488
 
487 489
                                     $yongjin = $spread_data['brokerage_price'] + $yj_amount_90;
488 490
                                     $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -524,8 +526,8 @@ class Notify
524 526
                                     if(!empty($merchant_user_data)){
525 527
 
526 528
 
527
-                                        $yj_amount_90 = bcmul($pv, 0.035,2) * 0.9;
528
-                                        $fgj_amount_10 = bcmul($pv, 0.035,2) * 0.1;//推广者的佣金抽10%到个人复购金
529
+                                        $yj_amount_90 = bcmul($pv * 0.9, 0.035,2);
530
+                                        $fgj_amount_10 = bcmul($pv * 0.1, 0.035,2);//推广者的佣金抽10%到个人复购金
529 531
 
530 532
                                         $yj_amount = $merchant_data['brokerage_price'] + $yj_amount_90;
531 533
                                         $fgj_amount = $merchant_data['fugou'] + $fgj_amount_10;
@@ -627,16 +629,17 @@ class Notify
627 629
                                     $this->con_log_pv($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区赠送PV值");
628 630
                                     // 积分
629 631
                                     $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
630
-                                    // 红包
631
-                                    $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买商贸区商品赠送红包');
632
-
632
+                                    if (!empty($user_data['is_old'])) {
633
+                                        // 红包
634
+                                        $this->giveHongBao($user_data['uid'], $pv, $store_order_data['order_id'], '购买商贸区商品赠送红包');
635
+                                    }
633 636
                                     $spread_data = Db::name('user')->where('uid',$user_data['spread_uid'])->find();
634 637
                                     if($spread_data) {
635 638
                                         $StoreOrderRepository = app()->make(StoreOrderRepository::class);
636 639
                                         $rate = $StoreOrderRepository->getUserGroupRate($spread_data['user_group']);
637 640
                                         if ($spread_data['user_group'] == 1) {
638
-                                            $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
639
-                                            $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
641
+                                            $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
642
+                                            $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
640 643
 
641 644
                                             $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
642 645
 
@@ -650,8 +653,8 @@ class Notify
650 653
                                         } else if ($spread_data['user_group'] > 1) {
651 654
 
652 655
                                             $ssf = bcmul($pv, $rate, 2);
653
-                                            $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
654
-                                            $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
656
+                                            $yj_amount_90 = bcmul($pv * 0.9, $rate, 2);
657
+                                            $fgj_amount_10 = bcmul($pv * 0.1, $rate, 2);//推广者的佣金抽10%到个人复购金
655 658
                                             $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
656 659
 
657 660
                                             //贡献值
@@ -664,44 +667,6 @@ class Notify
664 667
                                             $this->bill_user_log($spread_data['uid'], bcmul($pv, 0.05, 2), $store_order_data['order_id'], 5, $store_order_data['order_sn'], '推广获得养老金' . bcmul($pv, 0.05, 2), $store_order_data['mer_id'], 0);
665 668
                                         }
666 669
                                     }
667
-//                                    if ($user_data['spread_uid'] != 0) {
668
-//                                        //查询下单用户上级
669
-//                                        $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
670
-//                                        /** @var \app\common\repositories\store\order\StoreOrderRepository $StoreOrderRepository */
671
-//                                        $rate = $StoreOrderRepository->getUserGroupRate($spread_data['user_group']);
672
-//                                        if ($spread_data['user_group'] > 1) {
673
-//                                            $ssf = bcmul($pv, $rate, 2);
674
-//                                            $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
675
-//                                            $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
676
-//                                            $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
677
-//
678
-//                                            //贡献值
679
-//                                            $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
680
-//                                            //积分
681
-//                                            $this->score_log($spread_data['uid'], $ssf, $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
682
-//                                            //推广佣金
683
-//                                            $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);
684
-//                                            //养老金
685
-//                                            $this->bill_user_log($spread_data['uid'], bcmul($pv, 0.05, 2), $store_order_data['order_id'], 5, $group_order['group_order_sn'], '推广获得养老金' . round($pv * 0.05, 2), $store_order_data['mer_id'], 0);
686
-//                                        }
687
-//
688
-//                                        //普通用户推广人
689
-//                                        if ($spread_data['user_group'] == 1) {
690
-//                                            //给推广者分配佣金
691
-//
692
-//                                            $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
693
-//                                            $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
694
-//
695
-//                                            $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
696
-//
697
-//                                            //推广佣金
698
-//                                            $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);
699
-//                                            // 贡献值
700
-//                                            $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
701
-//                                            // 积分
702
-//                                            $this->score_log($spread_data['uid'], bcmul($pv, $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
703
-//                                        }
704
-//                                    }
705 670
 
706 671
                                     //锁客收益
707 672
                                     if ($user_data['mer_id'] != 0) {
@@ -709,8 +674,8 @@ class Notify
709 674
                                         $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
710 675
                                         if (!empty($merchant_user_data)) {
711 676
                                             //给推广者分配佣金
712
-                                            $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
713
-                                            $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
677
+                                            $yj_amount_90 = bcmul($pv * 0.9, 0.05, 2);
678
+                                            $fgj_amount_10 = bcmul($pv * 0.1, 0.05, 2);//推广者的佣金抽10%到个人复购金
714 679
                                             $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
715 680
                                             //推广佣金
716 681
                                             $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);

+ 7 - 7
app/controller/api/store/service/Huafei.php

@@ -213,13 +213,13 @@ class Huafei extends BaseController
213 213
 			$order_sn,
214 214
 			$type_shop
215 215
 		);						
216
-		//复购金
217
-		$orderThird->yuguFugou(
218
-			$commissionMoney,
219
-			$uid,
220
-			$order_sn,
221
-			$type_shop
222
-		);	
216
+		// //复购金
217
+		// $orderThird->yuguFugou(
218
+		// 	$commissionMoney,
219
+		// 	$uid,
220
+		// 	$order_sn,
221
+		// 	$type_shop
222
+		// );	
223 223
 
224 224
 		//推送订单
225 225
 		$push = $this->pushOrder($order_sn, $phone, $money);

+ 17 - 4
app/controller/api/user/User.php

@@ -1574,15 +1574,25 @@ class User extends BaseController
1574 1574
         $user = Db::name('user')->where('uid', $user_id)->field('uid,nickname,avatar,spread_uid,pv,create_time')->find();
1575 1575
         $child_nums = $this->getdepartmentStatistics($user_id);
1576 1576
         $child_nums_Tree = $this->buildTreePv($child_nums, $user['spread_uid']);
1577
+        $new_performance = 0; //一周内新增总业绩
1578
+        $end_time = date('Y-m-d ' . '00:00:00', strtotime('-7 days'));
1577 1579
         $person_nums_pv = 0;//大部门业绩
1578 1580
         $common_nums_pv = 0;//小部门业绩
1579 1581
         $aLL_list = [];//全部数据
1580 1582
         $person_list = [];//大部门数据
1581 1583
         $common_list = [];//小部门数据
1582 1584
         if(count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])){
1585
+            // 计算总新增业绩
1586
+            $uid_list = array_column($child_nums, 'uid');
1587
+            $uid_list = array_diff($uid_list,[$user_id]);
1588
+            $new_performance = Db::name("user_pv_log")->where([['uid','in',$uid_list],['settlement_time','>',$end_time]])->sum('pv');
1583 1589
             //获取大部门的key
1584 1590
             $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
1585 1591
             foreach($child_nums_Tree[0]['children'] as $k=>$v){
1592
+                $child_nums = $this->getdepartmentStatistics($v['uid']);
1593
+                $uid_list = array_column($child_nums, 'uid');
1594
+                array_push($uid_list,$v['uid']);
1595
+                $new_performance_child = Db::name("user_pv_log")->where([['uid','in',$uid_list],['settlement_time','>',$end_time]])->sum('pv');
1586 1596
                 if($k == $maxBalanceIndex){
1587 1597
                     $person_list[] = [
1588 1598
                         "uid" => $v["uid"],
@@ -1592,7 +1602,8 @@ class User extends BaseController
1592 1602
                         "pv" => $v['pv'],
1593 1603
                         "total_performance" => (int)$v['total_pv'],
1594 1604
                         "create_time" => $v['create_time'],
1595
-                        'team_count'=> $v['team_count']
1605
+                        'team_count'=> $v['team_count'],
1606
+                        'new_performance' => $new_performance_child
1596 1607
                     ];
1597 1608
                     $person_nums_pv = bcadd($person_nums_pv,$v['total_pv']);
1598 1609
                 }else{
@@ -1604,7 +1615,8 @@ class User extends BaseController
1604 1615
                         "pv" => $v['pv'],
1605 1616
                         "total_performance" => (int)$v['total_pv'],
1606 1617
                         "create_time" => $v['create_time'],
1607
-                        'team_count'=> $v['team_count']
1618
+                        'team_count'=> $v['team_count'],
1619
+                        'new_performance' => $new_performance_child
1608 1620
                     ];
1609 1621
                     $common_nums_pv = bcadd($common_nums_pv,$v['total_pv']);
1610 1622
                 }
@@ -1616,7 +1628,8 @@ class User extends BaseController
1616 1628
                     "pv" => $v['pv'],
1617 1629
                     "total_performance" => (int)$v['total_pv'],
1618 1630
                     "create_time" => $v['create_time'],
1619
-                    'team_count'=> $v['team_count']
1631
+                    'team_count'=> $v['team_count'],
1632
+                    'new_performance' => $new_performance_child
1620 1633
                 ];
1621 1634
             }
1622 1635
         }
@@ -1657,7 +1670,7 @@ class User extends BaseController
1657 1670
             $data['teamid'] = $teamid;
1658 1671
             $data['team_list'] = $data1;
1659 1672
             $data['fans_num'] = $child_nums_Tree[0]['team_count'];//总人数
1660
-            $data['new_performance'] = 0;//新增业绩
1673
+            $data['new_performance'] = $new_performance;//新增总业绩
1661 1674
             $data['total_performance'] = (int)bcadd($child_nums_Tree[0]['total_pv'] ?? 0, 0, 2);//总业绩
1662 1675
             $data['person_nums'] = count($person_list);//大部门人数
1663 1676
             $data['common_nums'] = count($common_list);//小部门人数