Просмотр исходного кода

Merge branch 'master' into huangfamily

family 1 год назад
Родитель
Сommit
f41329243c

+ 15 - 15
app/command/PensionTasks.php

@@ -1573,16 +1573,16 @@ class PensionTasks extends Command
1573 1573
     public function huafeiOrderNew($timeLimit)
1574 1574
     {
1575 1575
         // 普通订单
1576
-        $order_data = Db::name('order_huafei')->where('status', 3)->where('gzc' , 0)->select();
1576
+        $order_data = Db::name('order_huafei')->where('status', 2)->where('gzc' , 0)->select();
1577 1577
         if($order_data) {
1578 1578
             $order_data = $order_data->toArray();
1579 1579
             foreach ($order_data as $online) {
1580 1580
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1581
-                if($date < $online['finish_time']) continue;
1581
+                if($date < $online['create_time']) continue;
1582 1582
                 $online['order_id'] = $online['order_huafei_id'];
1583 1583
                 Db::transaction(function () use ($online) {
1584 1584
                     $this->settleAward($online);
1585
-                    Db::name('order_huafei')->where('order_huafei_id', $online['order_huafei_id'])->update(['gzc' => 1 ,'modify_time' => date('Y-m-d H:i:s')]);
1585
+                    Db::name('order_huafei')->where('order_huafei_id', $online['order_huafei_id'])->update(['gzc' => 1]);
1586 1586
                 });
1587 1587
             }
1588 1588
         }
@@ -1604,11 +1604,11 @@ class PensionTasks extends Command
1604 1604
             $order_data = $order_data->toArray();
1605 1605
             foreach ($order_data as $online) {
1606 1606
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1607
-                if($date < date('Y-m-d H:i:s', $online['pay_time'])) continue;
1607
+                if($date < $online['create_time']) continue;
1608 1608
                 $online['order_id'] = $online['order_pdd_id'];
1609 1609
                 Db::transaction(function () use ($online) {
1610 1610
                     $this->settleAward($online);
1611
-                    Db::name('order_pdd')->where('order_pdd_id', $online['order_pdd_id'])->update(['gzc' => 1 ,'settle_time' => date('Y-m-d H:i:s')]);
1611
+                    Db::name('order_pdd')->where('order_pdd_id', $online['order_pdd_id'])->update(['gzc' => 1]);
1612 1612
                 });
1613 1613
             }
1614 1614
         }
@@ -1630,11 +1630,11 @@ class PensionTasks extends Command
1630 1630
             $order_data = $order_data->toArray();
1631 1631
             foreach ($order_data as $online) {
1632 1632
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1633
-                if($date < $online['finish_time']) continue;
1633
+                if($date < $online['create_time']) continue;
1634 1634
                 $online['order_id'] = $online['order_jd_id'];
1635 1635
                 Db::transaction(function () use ($online) {
1636 1636
                     $this->settleAward($online);
1637
-                    Db::name('order_jd')->where('order_jd_id', $online['order_jd_id'])->update(['gzc' => 1 ,'modify_time' => date('Y-m-d H:i:s')]);
1637
+                    Db::name('order_jd')->where('order_jd_id', $online['order_jd_id'])->update(['gzc' => 1]);
1638 1638
                 });
1639 1639
             }
1640 1640
         }
@@ -1651,16 +1651,16 @@ class PensionTasks extends Command
1651 1651
     public function suOrderNew($timeLimit)
1652 1652
     {
1653 1653
         // 普通订单
1654
-        $order_data = Db::name('order_su')->where('status', 1)->where('gzc', 0)->select();
1654
+        $order_data = Db::name('order_su')->where('status', '确认收货')->where('gzc', 0)->select();
1655 1655
         if($order_data) {
1656 1656
             $order_data = $order_data->toArray();
1657 1657
             foreach ($order_data as $online) {
1658 1658
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1659
-                if($date < date('Y-m-d H:i:s',$online['pay_time'])) continue;
1659
+                if($date < $online['create_time']) continue;
1660 1660
                 $online['order_id'] = $online['order_su_id'];
1661 1661
                 Db::transaction(function () use ($online) {
1662 1662
                     $this->settleAward($online);
1663
-                    Db::name('order_su')->where('order_su_id', $online['order_su_id'])->update(['gzc' => 1 ,'settled_time' => date('Y-m-d H:i:s')]);
1663
+                    Db::name('order_su')->where('order_su_id', $online['order_su_id'])->update(['gzc' => 1]);
1664 1664
                 });
1665 1665
             }
1666 1666
         }
@@ -1682,7 +1682,7 @@ class PensionTasks extends Command
1682 1682
             $order_data = $order_data->toArray();
1683 1683
             foreach ($order_data as $online) {
1684 1684
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1685
-                if($date < date('Y-m-d H:i:s',$online['tk_earning_time'])) continue;
1685
+                if($date < $online['create_time']) continue;
1686 1686
                 $online['order_id'] = $online['order_tb_id'];
1687 1687
                 Db::transaction(function () use ($online) {
1688 1688
                     $this->settleAward($online);
@@ -1708,11 +1708,11 @@ class PensionTasks extends Command
1708 1708
             $order_data = $order_data->toArray();
1709 1709
             foreach ($order_data as $online) {
1710 1710
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1711
-                if($date < date('Y-m-d H:i:s',$online['last_update_time'])) continue;
1711
+                if($date < $online['create_time']) continue;
1712 1712
                 $online['order_id'] = $online['order_vip_id'];
1713 1713
                 Db::transaction(function () use ($online) {
1714 1714
                     $this->settleAward($online);
1715
-                    Db::name('order_vip')->where('order_vip_id', $online['order_vip_id'])->update(['gzc' => 1,'settle_time' => date('Y-m-d H:i:s')]);
1715
+                    Db::name('order_vip')->where('order_vip_id', $online['order_vip_id'])->update(['gzc' => 1]);
1716 1716
                 });
1717 1717
             }
1718 1718
         }
@@ -1734,11 +1734,11 @@ class PensionTasks extends Command
1734 1734
             $order_data = $order_data->toArray();
1735 1735
             foreach ($order_data as $online) {
1736 1736
                 $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
1737
-                if($date < date('Y-m-d H:i:s',$online['pay_success_time'])) continue;
1737
+                if($date < $online['create_time']) continue;
1738 1738
                 $online['order_id'] = $online['order_dy_id'];
1739 1739
                 Db::transaction(function () use ($online) {
1740 1740
                     $this->settleAward($online);
1741
-                    Db::name('order_dy')->where('order_dy_id', $online['order_dy_id'])->update(['gzc' => 1,'settle_time' => date('Y-m-d H:i:s')]);
1741
+                    Db::name('order_dy')->where('order_dy_id', $online['order_dy_id'])->update(['gzc' => 1]);
1742 1742
                 });
1743 1743
             }
1744 1744
         }

+ 2 - 2
app/command/repairPvLog.php

@@ -24,10 +24,10 @@ class repairPvLog extends Command
24 24
      */
25 25
     protected function execute(Input $input, Output $output)
26 26
     {
27
-        $user_id_list = Db::name('user')->where([['pv','=',0],['contribute','>',0]])->column('uid');
27
+        $user_id_list = Db::name('user')->where([['pv','=',0]])->column('uid');
28 28
         if($user_id_list){
29 29
             foreach ($user_id_list as $user_id) {
30
-                $order_list = Db::name('store_order')->where(['uid' => $user_id,'paid' => 1,'gzc' => 1])->select();
30
+                $order_list = Db::name('store_order')->where(['uid' => $user_id,'paid' => 1])->where('mer_id',496)->select();
31 31
                 if($order_list) {
32 32
                     $pv = 0;
33 33
                     foreach ($order_list as $order) {

+ 298 - 169
app/common/repositories/finance/FinanceRepository.php

@@ -28,142 +28,217 @@ class FinanceRepository extends BaseRepository
28 28
      */
29 29
     public function order_overview($mer_id = 0)
30 30
     {
31
-        // if ($mer_id) {
32
-        //     $where = "mer_id = " . $mer_id . " and paid = 1";
33
-        // } else {
31
+        if ($mer_id) {
32
+            $where = "mer_id = " . $mer_id . " and paid = 1";
33
+            $type = input('type', 1);
34
+            $day = input('day', '');
35
+    
36
+            if ($type == 1 and $day != '') {
37
+                $where .= " and DATE(pay_time) = '" . $day . "'";
38
+            }
39
+            if ($type == 2 and $day != '') {
40
+                $date = new \DateTime($day);
41
+                $year = $date->format('Y');
42
+                $month = $date->format('m');
43
+    
44
+                $where .= " and YEAR(pay_time) = " . $year . " AND MONTH(pay_time) = " . $month;
45
+            }
46
+            $xianshangzhifu = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->sum('pay_price');
47
+            $xianshangzhifu_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->sum('pay_price');
48
+            $hongjifenxiaofei = Db::name('store_order')->where($where)->where("pay_type", 5)->sum('pay_price');
49
+    
50
+            $chengjiaomoney = decimal2($xianshangzhifu + $hongjifenxiaofei);
51
+            $list1[] = ['count' => set_price_rtrim($xianshangzhifu), 'name' => '线上支付金额'];
52
+            if (!$mer_id) {
53
+                $list1[] = ['count' => set_price_rtrim($xianshangzhifu_xuni), 'name' => '虚拟支付金额'];
54
+            }
55
+            $list1[] = ['count' => 0, 'name' => '代付金额'];
56
+            $xianshangzhifunum = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->count();
57
+            $xianshangzhifunum_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->count();
58
+            $hongjifenxiaofeinum = Db::name('store_order')->where($where)->where("pay_type", 5)->count();
59
+    
60
+            $chengjiaocount = $xianshangzhifunum + $hongjifenxiaofeinum;
61
+    
62
+            $list2[] = ['count' => $xianshangzhifunum, 'name' => '线上支付订单量'];
63
+            if (!$mer_id) {
64
+                $list2[] = ['count' => $xianshangzhifunum_xuni, 'name' => '虚拟支付订单量'];
65
+            }
66
+            $list2[] = ['count' => 0, 'name' => '代付订单量'];
67
+            $xianshangzhifuren = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->group('uid')->count();
68
+            $xianshangzhifuren_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->group('uid')->count();
69
+            $hongjifenxiaofeiren = Db::name('store_order')->where($where)->where("pay_type", 5)->group('uid')->count();
70
+    
71
+            $chengjiaoren = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1, 5])->group('uid')->count();
72
+            $list3[] = ['count' => set_price_rtrim($xianshangzhifuren), 'name' => '线上支付人数'];
73
+            if (!$mer_id) {
74
+                $list3[] = ['count' => set_price_rtrim($xianshangzhifuren_xuni), 'name' => '虚拟支付人数'];
75
+            }
76
+            $list3[] = ['count' => 0, 'name' => '代付人数'];
77
+    
78
+    
79
+            $xianshangtuikuan = Db::name('store_order')->where($where)->where('status', -1)->sum('pay_price');
80
+    
81
+            $tuikuanmoney = $xianshangtuikuan;
82
+            $list4 = array(
83
+                array('count' => $xianshangtuikuan, 'name' => '线上支付退单'),
84
+                array('count' => 0, 'name' => '代付退单'),
85
+            );
86
+            $xianshangzhifutuinum = Db::name('store_order')->where($where)->where('status', -1)->count();
87
+    
88
+            $tuikuancount = $xianshangzhifutuinum;
89
+            $list5 = array(
90
+                array('count' => set_price_rtrim($xianshangzhifutuinum), 'name' => '线上支付退单量'),
91
+                array('count' => 0, 'name' => '代付退单量'),
92
+            );
93
+            $xianshangzhifutuiremn = Db::name('store_order')->where($where)->where('status', -1)->group('uid')->count();
94
+    
95
+            $tuikuanren = $xianshangzhifutuiremn;
96
+            $list6 = array(
97
+                array('count' => set_price_rtrim($xianshangzhifutuiremn), 'name' => '线上支付退单人数'),
98
+                array('count' => 0, 'name' => '代付退单数'),
99
+            );
100
+    
101
+    
102
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '成交金额', 'list' => $list1];
103
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '成交订单量', 'list' => $list2];
104
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '支付人数', 'list' => $list3];
105
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '退款金额', 'list' => $list4];
106
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '退款订单量', 'list' => $list5];
107
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '退款人数', 'list' => $list6];
108
+            return $data;
109
+        } else {
34 110
             $where = " paid = 1";
35
-        // }
36
-
37
-        $type = input('type', 1);
38
-        $day = input('day', '');
39
-        //天
40
-        if ($type == 1 and $day != '') {
41
-            $where .= " and DATE(create_time) = '" . $day . "'";
42
-        }
43
-        //月
44
-        if ($type == 2 and $day != '') {
45
-            $date = new \DateTime($day);
46
-            $year = $date->format('Y');
47
-            $month = $date->format('m');
48
-            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
111
+            $type = input('type', 1);
112
+            $day = input('day', '');
113
+            //天
114
+            if ($type == 1 and $day != '') {
115
+                $where .= " and DATE(create_time) = '" . $day . "'";
116
+            }
117
+            //月
118
+            if ($type == 2 and $day != '') {
119
+                $date = new \DateTime($day);
120
+                $year = $date->format('Y');
121
+                $month = $date->format('m');
122
+                $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
123
+            }
124
+    
125
+            $weekWhere = " paid = 1";
126
+            $dayWhere = " paid = 1";
127
+            // 获取今天的日期和时间
128
+            $today = new \DateTime();
129
+            // 计算一周前的日期
130
+            $oneWeekAgo = clone $today; // 克隆一个对象,避免修改原始对象
131
+            $oneWeekAgo->sub(new \DateInterval('P1W')); // 减去一周
132
+            
133
+            // 格式化日期
134
+            $todayFormatted = $today->format('Y-m-d');
135
+            $oneWeekAgoFormatted = $oneWeekAgo->format('Y-m-d');
136
+    
137
+            //周时间条件
138
+            $weekWhere .= " and DATE(create_time) >= '" . $oneWeekAgoFormatted . "' and DATE(create_time) <= '" . $todayFormatted . "'";
139
+            //今日时间条件
140
+            $dayWhere .= " and DATE(create_time) = '" . $todayFormatted . "'";
141
+    
142
+    
143
+            // 会员专区订单总数
144
+            //总数
145
+            $chengjiaomoney = Db::name('store_order')->where($where)->where('mer_id', 496)->count();
146
+            $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 496)->count();
147
+            $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 496)->count();
148
+            $list1[] = ['count' => $weekCount, 'name' => '周订单总数'];
149
+            $list1[] = ['count' => $todayCount, 'name' => '日订单总数'];
150
+    
151
+            //精彩生活区订单总数
152
+            //总数
153
+            $chengjiaocount = Db::name('store_order')->where($where)->where('mer_id', 439)->count();
154
+            $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 439)->count();
155
+            $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 439)->count();
156
+            $list2[] = ['count' => $weekCount, 'name' => '周订单总数'];
157
+            $list2[] = ['count' => $todayCount, 'name' => '日订单总数'];
158
+    
159
+            //商贸区订单总数
160
+            //总数
161
+            $chengjiaoren = Db::name('store_order')->where($where)->whereNotIn('mer_id', [496, 439, 491])->count();
162
+            $weekCount = Db::name('store_order')->where($weekWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
163
+            $todayCount = Db::name('store_order')->where($dayWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
164
+            $list3[] = ['count' => $weekCount, 'name' => '周订单总数'];
165
+            $list3[] = ['count' => $todayCount, 'name' => '日订单总数'];
166
+    
167
+            //复购区订单总数
168
+            //总数
169
+            $tuikuanmoney = Db::name('store_order')->where($where)->where('mer_id', 491)->count();
170
+            $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 491)->count();
171
+            $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 491)->count();
172
+            $list4[] = ['count' => $weekCount, 'name' => '周订单总数'];
173
+            $list4[] = ['count' => $todayCount, 'name' => '日订单总数'];
174
+    
175
+            //三方平台订单总数
176
+            //总数
177
+    
178
+            //话费
179
+            $whereNew = str_replace("paid", "status", $where);
180
+            $weekWhereNew = str_replace("paid", "status", $weekWhere);
181
+            $dayWhereNew = str_replace("paid", "status", $dayWhere);
182
+            $huafei = Db::name('order_huafei_hf')->where($whereNew)->count();
183
+            $huafei_week = Db::name('order_huafei_hf')->where($weekWhereNew)->count();
184
+            $huafei_today = Db::name('order_huafei_hf')->where($dayWhereNew)->count();
185
+    
186
+    
187
+            //京东
188
+            $whereNew = str_replace(" paid = 1", " status IN (16, 17)", $where);
189
+            $weekWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $weekWhere);
190
+            $dayWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $dayWhere);
191
+            $jd = Db::name('order_jd')->where($whereNew)->count();
192
+            $jd_week = Db::name('order_jd')->where($weekWhereNew)->count();
193
+            $jd_today = Db::name('order_jd')->where($dayWhereNew)->count();
194
+    
195
+            //拼多多
196
+            $whereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $where);
197
+            $weekWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $weekWhere);
198
+            $dayWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $dayWhere);
199
+            $pdd = Db::name('order_pdd')->where($whereNew)->count();
200
+            $pdd_week = Db::name('order_pdd')->where($weekWhereNew)->count();
201
+            $pdd_today = Db::name('order_pdd')->where($dayWhereNew)->count();
202
+    
203
+            //淘宝
204
+            $whereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $where);
205
+            $weekWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $weekWhere);
206
+            $dayWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $dayWhere);
207
+            $tb = Db::name('order_tb')->where($whereNew)->count();
208
+            $tb_week = Db::name('order_tb')->where($weekWhereNew)->count();
209
+            $tb_today = Db::name('order_tb')->where($dayWhereNew)->count();
210
+    
211
+            //电影票
212
+            $whereNew = str_replace(" paid = 1", " status IN (1, 4)", $where);
213
+            $weekWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $weekWhere);
214
+            $dayWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $dayWhere);
215
+            $movie = Db::name('order_movie')->where($whereNew)->count();
216
+            $movie_week = Db::name('order_movie')->where($weekWhereNew)->count();
217
+            $movie_today = Db::name('order_movie')->where($dayWhereNew)->count();
218
+    
219
+            $tuikuancount = $huafei+$jd+$pdd+$tb+$movie;
220
+            $weekCount = $huafei_week+$jd_week+$pdd_week+$tb_week+$movie_week;
221
+            $todayCount = $huafei_today+$jd_today+$pdd_today+$tb_today+$movie_today;
222
+            $list5[] = ['count' => $weekCount, 'name' => '周订单总数'];
223
+            $list5[] = ['count' => $todayCount, 'name' => '日订单总数'];
224
+    
225
+            //线下订单总数
226
+            //总数
227
+            $tuikuanren = Db::name('order_merchant')->where($where)->count();
228
+            $weekCount = Db::name('order_merchant')->where($weekWhere)->count();
229
+            $todayCount = Db::name('order_merchant')->where($dayWhere)->count();
230
+            $list6[] = ['count' => $weekCount, 'name' => '周订单总数'];
231
+            $list6[] = ['count' => $todayCount, 'name' => '日订单总数'];
232
+    
233
+    
234
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '会员专区订单总数', 'list' => $list1];
235
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '精彩生活区订单总数', 'list' => $list2];
236
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '商贸区订单总数', 'list' => $list3];
237
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '复购区订单总数', 'list' => $list4];
238
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '三方平台订单总数', 'list' => $list5];
239
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '线下订单总数', 'list' => $list6];
240
+            return $data;
49 241
         }
50
-
51
-        $weekWhere = " paid = 1";
52
-        $dayWhere = " paid = 1";
53
-        // 获取今天的日期和时间
54
-        $today = new \DateTime();
55
-        // 计算一周前的日期
56
-        $oneWeekAgo = clone $today; // 克隆一个对象,避免修改原始对象
57
-        $oneWeekAgo->sub(new \DateInterval('P1W')); // 减去一周
58
-        
59
-        // 格式化日期
60
-        $todayFormatted = $today->format('Y-m-d');
61
-        $oneWeekAgoFormatted = $oneWeekAgo->format('Y-m-d');
62
-
63
-        //周时间条件
64
-        $weekWhere .= " and DATE(create_time) >= '" . $oneWeekAgoFormatted . "' and DATE(create_time) <= '" . $todayFormatted . "'";
65
-        //今日时间条件
66
-        $dayWhere .= " and DATE(create_time) = '" . $todayFormatted . "'";
67
-
68
-
69
-        // 会员专区订单总数
70
-        //总数
71
-        $chengjiaomoney = Db::name('store_order')->where($where)->where('mer_id', 496)->count();
72
-        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 496)->count();
73
-        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 496)->count();
74
-        $list1[] = ['count' => $weekCount, 'name' => '周订单总数'];
75
-        $list1[] = ['count' => $todayCount, 'name' => '日订单总数'];
76
-
77
-        //精彩生活区订单总数
78
-        //总数
79
-        $chengjiaocount = Db::name('store_order')->where($where)->where('mer_id', 439)->count();
80
-        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 439)->count();
81
-        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 439)->count();
82
-        $list2[] = ['count' => $weekCount, 'name' => '周订单总数'];
83
-        $list2[] = ['count' => $todayCount, 'name' => '日订单总数'];
84
-
85
-        //商贸区订单总数
86
-        //总数
87
-        $chengjiaoren = Db::name('store_order')->where($where)->whereNotIn('mer_id', [496, 439, 491])->count();
88
-        $weekCount = Db::name('store_order')->where($weekWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
89
-        $todayCount = Db::name('store_order')->where($dayWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
90
-        $list3[] = ['count' => $weekCount, 'name' => '周订单总数'];
91
-        $list3[] = ['count' => $todayCount, 'name' => '日订单总数'];
92
-
93
-        //复购区订单总数
94
-        //总数
95
-        $tuikuanmoney = Db::name('store_order')->where($where)->where('mer_id', 491)->count();
96
-        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 491)->count();
97
-        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 491)->count();
98
-        $list4[] = ['count' => $weekCount, 'name' => '周订单总数'];
99
-        $list4[] = ['count' => $todayCount, 'name' => '日订单总数'];
100
-
101
-        //三方平台订单总数
102
-        //总数
103
-
104
-        //话费
105
-        $whereNew = str_replace("paid", "status", $where);
106
-        $weekWhereNew = str_replace("paid", "status", $weekWhere);
107
-        $dayWhereNew = str_replace("paid", "status", $dayWhere);
108
-        $huafei = Db::name('order_huafei_hf')->where($whereNew)->count();
109
-        $huafei_week = Db::name('order_huafei_hf')->where($weekWhereNew)->count();
110
-        $huafei_today = Db::name('order_huafei_hf')->where($dayWhereNew)->count();
111
-
112
-
113
-        //京东
114
-        $whereNew = str_replace(" paid = 1", " status IN (16, 17)", $where);
115
-        $weekWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $weekWhere);
116
-        $dayWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $dayWhere);
117
-        $jd = Db::name('order_jd')->where($whereNew)->count();
118
-        $jd_week = Db::name('order_jd')->where($weekWhereNew)->count();
119
-        $jd_today = Db::name('order_jd')->where($dayWhereNew)->count();
120
-
121
-        //拼多多
122
-        $whereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $where);
123
-        $weekWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $weekWhere);
124
-        $dayWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $dayWhere);
125
-        $pdd = Db::name('order_pdd')->where($whereNew)->count();
126
-        $pdd_week = Db::name('order_pdd')->where($weekWhereNew)->count();
127
-        $pdd_today = Db::name('order_pdd')->where($dayWhereNew)->count();
128
-
129
-        //淘宝
130
-        $whereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $where);
131
-        $weekWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $weekWhere);
132
-        $dayWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $dayWhere);
133
-        $tb = Db::name('order_tb')->where($whereNew)->count();
134
-        $tb_week = Db::name('order_tb')->where($weekWhereNew)->count();
135
-        $tb_today = Db::name('order_tb')->where($dayWhereNew)->count();
136
-
137
-        //电影票
138
-        $whereNew = str_replace(" paid = 1", " status IN (1, 4)", $where);
139
-        $weekWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $weekWhere);
140
-        $dayWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $dayWhere);
141
-        $movie = Db::name('order_movie')->where($whereNew)->count();
142
-        $movie_week = Db::name('order_movie')->where($weekWhereNew)->count();
143
-        $movie_today = Db::name('order_movie')->where($dayWhereNew)->count();
144
-
145
-        $tuikuancount = $huafei+$jd+$pdd+$tb+$movie;
146
-        $weekCount = $huafei_week+$jd_week+$pdd_week+$tb_week+$movie_week;
147
-        $todayCount = $huafei_today+$jd_today+$pdd_today+$tb_today+$movie_today;
148
-        $list5[] = ['count' => $weekCount, 'name' => '周订单总数'];
149
-        $list5[] = ['count' => $todayCount, 'name' => '日订单总数'];
150
-
151
-        //线下订单总数
152
-        //总数
153
-        $tuikuanren = Db::name('order_merchant')->where($where)->count();
154
-        $weekCount = Db::name('order_merchant')->where($weekWhere)->count();
155
-        $todayCount = Db::name('order_merchant')->where($dayWhere)->count();
156
-        $list6[] = ['count' => $weekCount, 'name' => '周订单总数'];
157
-        $list6[] = ['count' => $todayCount, 'name' => '日订单总数'];
158
-
159
-
160
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '会员专区订单总数', 'list' => $list1];
161
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '精彩生活区订单总数', 'list' => $list2];
162
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '商贸区订单总数', 'list' => $list3];
163
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '复购区订单总数', 'list' => $list4];
164
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '三方平台订单总数', 'list' => $list5];
165
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '线下订单总数', 'list' => $list6];
166
-        return $data;
167 242
     }
168 243
 
169 244
     /**
@@ -184,43 +259,97 @@ class FinanceRepository extends BaseRepository
184 259
                 $chilid_userids_string = implode(',',$chilid_userids);
185 260
             }
186 261
             $where .= "and uid in ({$chilid_userids_string})";
187
-        }
188
-        $type = input('type', 1);
189
-        $day = input('day', '');
190 262
 
191
-        if ($type == 1 and $day != '') {
192
-            $where .= " and DATE(create_time) = '" . $day . "'";
193
-        }
194
-        if ($type == 2 and $day != '') {
195
-            $date = new \DateTime($day);
196
-            $year = $date->format('Y');
197
-            $month = $date->format('m');
198
-            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
263
+            $where = "1=1 ";
264
+            if ($mer_id) {
265
+                $mer_uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
266
+                $userRepository = app()->make(UserRepository::class);
267
+                $chilid_userids = $userRepository->getSpreadUidBreak($mer_uid);
268
+                $chilid_userids_string = "1";
269
+                if (!empty($chilid_userids)) {
270
+                    $chilid_userids_string = implode(',',$chilid_userids);
271
+                }
272
+                $where .= "and uid in ({$chilid_userids_string})";
273
+            }
274
+            $type = input('type', 1);
275
+            $day = input('day', '');
276
+    
277
+            if ($type == 1 and $day != '') {
278
+                $where .= " and DATE(create_time) = '" . $day . "'";
279
+            }
280
+            if ($type == 2 and $day != '') {
281
+                $date = new \DateTime($day);
282
+                $year = $date->format('Y');
283
+                $month = $date->format('m');
284
+                $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
285
+            }
286
+            $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
287
+            $dataQuery = array_column($dataQuery, 'count', 'user_group');
288
+            $shopPartnerCount = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where mer_id={$mer_id} and is_shop_partner=1 group by user_group");
289
+    
290
+            $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
291
+            $maker = array_column($maker, 'count', 'k');
292
+    
293
+            $userByCodeCount = Db::query("SELECT 'temp' as `temp1`, count(*) count FROM `rrx_user` where {$where} and user_group =4 and is_show = 3");
294
+            $userByCodeCount = array_column($userByCodeCount, 'count', 'temp1');
295
+    
296
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
297
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
298
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
299
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
300
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
301
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
302
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
303
+            $list1 = array(
304
+                array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-2'] ?? 0), 'name' => '集团会员'),//is_show=2
305
+                array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-1'] ?? 0), 'name' => '电商创客'),
306
+                array('className' => 'el-icon-s-goods', 'count' => intval($userByCodeCount['temp'] ?? 0), 'name' => '激活创客'),
307
+            );
308
+    
309
+            if ($mer_id) {
310
+                $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[4] ?? 0), 'name' => '创客'];
311
+            }
312
+            $res['left'][] = $data;
313
+            $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim(intval($maker['4-2'] ?? 0) + intval($maker['4-1'] ?? 0) + intval($userByCodeCount['temp'] ?? 0)), 'name' => '创客'];
314
+        }else{
315
+            $type = input('type', 1);
316
+            $day = input('day', '');
317
+    
318
+            if ($type == 1 and $day != '') {
319
+                $where .= " and DATE(create_time) = '" . $day . "'";
320
+            }
321
+            if ($type == 2 and $day != '') {
322
+                $date = new \DateTime($day);
323
+                $year = $date->format('Y');
324
+                $month = $date->format('m');
325
+                $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
326
+            }
327
+            $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
328
+            $dataQuery = array_column($dataQuery, 'count', 'user_group');
329
+    
330
+            $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
331
+            $maker = array_column($maker, 'count', 'k');
332
+    
333
+    
334
+            $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
335
+            $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
336
+            $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
337
+            $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
338
+            $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
339
+    
340
+            $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
341
+            $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
342
+            $maker = Db::query("SELECT count(uid) as count FROM `rrx_user` where {$where} and originator_id_old > 0");
343
+            $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '联创'];
344
+            
345
+            $whereTow = str_replace("uid", "user_id", $where);
346
+            $maker = Db::query("SELECT count(user_id) as count FROM `rrx_old_user_stock` where {$whereTow}");
347
+            
348
+            $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '股权'];
349
+            $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
350
+            $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '商户'];
351
+            $res['left'] = $data;
199 352
         }
200
-        $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
201
-        $dataQuery = array_column($dataQuery, 'count', 'user_group');
202
-
203
-        $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
204
-        $maker = array_column($maker, 'count', 'k');
205
-
206
-
207
-        $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
208
-        $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
209
-        $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
210
-        $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
211
-        $data['one'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
212
-
213
-        $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
214
-        $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
215
-        $maker = Db::query("SELECT count(uid) as count FROM `rrx_user` where {$where} and originator_id_old > 0");
216
-        $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '联创'];
217
-        $maker = Db::query("SELECT count(user_id) as count FROM `rrx_old_user_stock` where {$where}");
218
-        $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '股权'];
219
-        $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
220
-        $data['tow'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '商户'];
221
-
222
-        $res['left'] = $data;
223
-
224 353
         return $res;
225 354
     }
226 355
 

+ 230 - 0
app/common/repositories/user/UserAwardRepository.php

@@ -0,0 +1,230 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-05-07
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\repositories\user;
12
+
13
+
14
+use app\common\dao\user\UserIdentityDao;
15
+use app\common\repositories\BaseRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use FormBuilder\Factory\Elm;
18
+use FormBuilder\Form;
19
+use think\db\exception\DataNotFoundException;
20
+use think\db\exception\DbException;
21
+use think\db\exception\ModelNotFoundException;
22
+use think\facade\Route; 
23
+use think\facade\Db;
24
+
25
+/**
26
+ * Class UserAwardRepository
27
+ * @package app\common\repositories\user
28
+ * @author xaboy
29
+ * @day 2020-05-07
30
+ * @mixin UserIdentityDao
31
+ */
32
+class UserAwardRepository extends BaseRepository
33
+{
34
+    /**
35
+     * @var UserIdentityDao
36
+     */
37
+    protected $dao;
38
+
39
+    /**
40
+     * UserGroupRepository constructor.
41
+     * @param UserIdentityDao $dao
42
+     */
43
+    public function __construct(UserIdentityDao $dao)
44
+    {
45
+        $this->dao = $dao;
46
+    }
47
+
48
+    /**
49
+     * @param array $where
50
+     * @param $page
51
+     * @param $limit
52
+     * @return array
53
+     * @throws DataNotFoundException
54
+     * @throws DbException
55
+     * @throws ModelNotFoundException
56
+     * @author xaboy
57
+     * @day 2020-05-07
58
+     */
59
+    public function getList(array $where, $page, $limit)
60
+    {
61
+        $count = 0;
62
+        $list = [];
63
+
64
+
65
+        $brokerage_fugou_rate = Db::name("system_config_value")->where(["config_key"=>"brokerage_fugou_rate"])->value("value");
66
+        $brokerage_fugou_rate = json_decode($brokerage_fugou_rate, true);
67
+
68
+        $user_group_rate = Db::name("system_config_value")->where(["config_key"=>"user_group_rate"])->value("value");
69
+        $user_group_rate = json_decode($user_group_rate, true);
70
+
71
+        $user_group_fugou_rate = Db::name("system_config_value")->where(["config_key"=>"user_group_fugou_rate"])->value("value");
72
+        $user_group_fugou_rate = json_decode($user_group_fugou_rate, true);
73
+
74
+        $brokerage_guquan_rate = Db::name("system_config_value")->where(["config_key"=>"brokerage_guquan_rate"])->value("value");
75
+        $fugou_guquan_rate = Db::name("system_config_value")->where(["config_key"=>"fugou_guquan_rate"])->value("value");
76
+
77
+        $brokerage_lianchuang_rate = Db::name("system_config_value")->where(["config_key"=>"brokerage_lianchuang_rate"])->value("value");
78
+        $fugou_lianchuang_rate = Db::name("system_config_value")->where(["config_key"=>"fugou_lianchuang_rate"])->value("value");
79
+
80
+        $list[] = [
81
+            'name' => '佣金',
82
+            'key' => 'brokerage',
83
+            'number_rate' => $brokerage_fugou_rate['brokerage_rate']??0,
84
+            'guquan_rate' => $brokerage_guquan_rate??0,
85
+            'lianchuang_rate' => $brokerage_lianchuang_rate??0,
86
+            'user_groub_1' => $user_group_rate[0]['rate']??0,
87
+            'user_groub_2' => $user_group_rate[1]['rate']??0,
88
+            'user_groub_3' => $user_group_rate[2]['rate']??0,
89
+            'user_groub_4' => $user_group_rate[3]['rate']??0,
90
+            'user_groub_5' => $user_group_rate[4]['rate']??0,
91
+            'user_groub_6' => $user_group_rate[5]['rate']??0,
92
+            'user_groub_7' => $user_group_rate[6]['rate']??0,
93
+        ];
94
+
95
+        $list[] = [
96
+            'name' => '复购金',
97
+            'key' => 'fugou',
98
+            'number_rate' => $brokerage_fugou_rate['fugou_rate']??0,
99
+            'lianchuang_rate' => $fugou_lianchuang_rate??0,
100
+            'guquan_rate' => $fugou_guquan_rate??0,
101
+            'user_groub_1' => $user_group_fugou_rate[0]['rate']??0,
102
+            'user_groub_2' => $user_group_fugou_rate[1]['rate']??0,
103
+            'user_groub_3' => $user_group_fugou_rate[2]['rate']??0,
104
+            'user_groub_4' => $user_group_fugou_rate[3]['rate']??0,
105
+            'user_groub_5' => $user_group_fugou_rate[4]['rate']??0,
106
+            'user_groub_6' => $user_group_fugou_rate[5]['rate']??0,
107
+            'user_groub_7' => $user_group_fugou_rate[6]['rate']??0,
108
+        ];
109
+
110
+        $count = count($list);
111
+        return compact('count', 'list');
112
+    }
113
+
114
+    /**
115
+     * @param array $formData
116
+     * @return Form
117
+     * @throws FormBuilderException
118
+     * @author xaboy
119
+     * @day 2020-05-07
120
+     */
121
+    public function form(array $formData = [])
122
+    {
123
+        $action = Route::buildUrl('configAwardUpdate' , $formData)->build();
124
+        return Elm::createForm($action, [
125
+            Elm::number('number_rate', $formData['name'].'占比(%)')->min(0)->size('large'),
126
+            Elm::number('lianchuang_rate', '联创占比(%)')->min(0)->size('large'),
127
+            Elm::number('guquan_rate', '股权占比(%)')->min(0)->size('large'),
128
+            Elm::number('user_groub_1', '消费者占比(%)')->min(0)->size('large'),
129
+            Elm::number('user_groub_2', '业务员占比(%)')->min(0)->size('large'),
130
+            Elm::number('user_groub_3', '业务经理占比(%)')->min(0)->size('large'),
131
+            Elm::number('user_groub_4', '初级合伙人占比(%)')->min(0)->size('large'),
132
+            Elm::number('user_groub_5', '中级合伙人占比(%)')->min(0)->size('large'),
133
+            Elm::number('user_groub_6', '高级合伙人占比(%)')->min(0)->size('large'),
134
+            Elm::number('user_groub_7', '董事占比(%)')->min(0)->size('large'),
135
+        ])->setTitle($formData['name'].'设置')->formData($formData);
136
+    }
137
+
138
+    /**
139
+     * @param $id
140
+     * @return Form
141
+     * @throws FormBuilderException
142
+     * @throws DataNotFoundException
143
+     * @throws DbException
144
+     * @throws ModelNotFoundException
145
+     * @author xaboy
146
+     * @day 2020-05-07
147
+     */
148
+    public function updateForm($data)
149
+    {
150
+        return $this->form($data);
151
+    }
152
+
153
+    /**
154
+     * @param $id
155
+     * @param data
156
+     * @return array
157
+     * @day 2020-05-07
158
+     */
159
+    public function updateAward($key, $data)
160
+    {
161
+        if ($key == 'brokerage') {
162
+            //修改佣金比例
163
+            $brokerage_fugou_rate = Db::name("system_config_value")->where(["config_key"=>"brokerage_fugou_rate"])->value("value");
164
+            $brokerage_fugou_rate = json_decode($brokerage_fugou_rate, true);
165
+            $brokerage_fugou_rate['brokerage_rate'] = $data['number_rate'];
166
+            Db::name("system_config_value")->where(["config_key"=>"brokerage_fugou_rate"])->where('mer_id', 0)->update([
167
+                'value' => json_encode($brokerage_fugou_rate)
168
+            ]);
169
+
170
+            //修改佣金等级分成比例
171
+            $user_group_rate = Db::name("system_config_value")->where(["config_key"=>"user_group_rate"])->value("value");
172
+            $user_group_rate = json_decode($user_group_rate, true);
173
+            $user_group_rate[0]['rate'] = $data['user_groub_1'];
174
+            $user_group_rate[1]['rate'] = $data['user_groub_2'];
175
+            $user_group_rate[2]['rate'] = $data['user_groub_3'];
176
+            $user_group_rate[3]['rate'] = $data['user_groub_4'];
177
+            $user_group_rate[4]['rate'] = $data['user_groub_5'];
178
+            $user_group_rate[5]['rate'] = $data['user_groub_6'];
179
+            $user_group_rate[6]['rate'] = $data['user_groub_7'];
180
+            Db::name("system_config_value")->where(["config_key"=>"user_group_rate"])->where('mer_id', 0)->update(['value' =>json_encode($user_group_rate)]);
181
+
182
+            //修改佣金股权比例
183
+            Db::name("system_config_value")->where(["config_key"=>"brokerage_guquan_rate"])->where('mer_id', 0)->update(['value' =>$data['guquan_rate']]);
184
+            //修改佣金联创比例
185
+            Db::name("system_config_value")->where(["config_key"=>"brokerage_lianchuang_rate"])->where('mer_id', 0)->update(['value' =>$data['lianchuang_rate']]);
186
+        }
187
+
188
+        if ($key == 'fugou') {
189
+            //修改复购金比例
190
+            $brokerage_fugou_rate = Db::name("system_config_value")->where(["config_key"=>"brokerage_fugou_rate"])->value("value");
191
+            $brokerage_fugou_rate = json_decode($brokerage_fugou_rate, true);
192
+            $brokerage_fugou_rate['fugou_rate'] = $data['number_rate'];
193
+            Db::name("system_config_value")->where(["config_key"=>"brokerage_fugou_rate"])->where('mer_id', 0)->update([
194
+                'value' => json_encode($brokerage_fugou_rate)
195
+            ]);
196
+            //修改复购金等级分成比例
197
+            $user_group_fugou_rate = Db::name("system_config_value")->where(["config_key"=>"user_group_fugou_rate"])->value("value");
198
+            $user_group_fugou_rate = json_decode($user_group_fugou_rate, true);
199
+            $user_group_fugou_rate[0]['rate'] = $data['user_groub_1'];
200
+            $user_group_fugou_rate[1]['rate'] = $data['user_groub_2'];
201
+            $user_group_fugou_rate[2]['rate'] = $data['user_groub_3'];
202
+            $user_group_fugou_rate[3]['rate'] = $data['user_groub_4'];
203
+            $user_group_fugou_rate[4]['rate'] = $data['user_groub_5'];
204
+            $user_group_fugou_rate[5]['rate'] = $data['user_groub_6'];
205
+            $user_group_fugou_rate[6]['rate'] = $data['user_groub_7'];
206
+            Db::name("system_config_value")->where(["config_key"=>"user_group_fugou_rate"])->where('mer_id', 0)->update([
207
+                'value' => json_encode($user_group_fugou_rate)
208
+            ]);
209
+            //修改复购金股权比例
210
+            Db::name("system_config_value")->where(["config_key"=>"fugou_guquan_rate"])->where('mer_id', 0)->update(['value' => $data['guquan_rate']]);
211
+            //修改复购金联创比例
212
+            Db::name("system_config_value")->where(["config_key"=>"fugou_lianchuang_rate"])->where('mer_id', 0)->update(['value' => $data['lianchuang_rate']]);
213
+        }
214
+
215
+        return true;
216
+    }
217
+
218
+    /**
219
+     * @param array $where
220
+     * @return array
221
+     * @throws DataNotFoundException
222
+     * @throws DbException
223
+     * @throws ModelNotFoundException
224
+     */
225
+    public function getIdentityList(array $where = [])
226
+    {
227
+        $query = $this->dao->search($where);
228
+        return $query->select()->toArray();
229
+    }
230
+}

+ 53 - 47
app/common/repositories/user/UserRepository.php

@@ -3365,11 +3365,11 @@ class UserRepository extends BaseRepository
3365 3365
      * @throws DbException
3366 3366
      * @throws ModelNotFoundException
3367 3367
      */
3368
-    public function getUidContributeListBySpreadUidList(array $uidList)
3368
+    public function getUidContributeListByLevelIdList(array $uidList)
3369 3369
     {
3370 3370
         return Db::name("user")
3371
-            ->whereIn("spread_uid", $uidList)
3372
-            ->field("uid, contribute, spread_uid")
3371
+            ->whereIn("level_id", $uidList)
3372
+            ->field("uid, contribute, level_id")
3373 3373
             ->select()
3374 3374
             ->toArray();
3375 3375
     }
@@ -3420,7 +3420,7 @@ class UserRepository extends BaseRepository
3420 3420
             foreach(array_chunk($currentLevelIds, $chunkSize) as $chunk) {
3421 3421
                 $subordinatesChunk = Db::name('user')
3422 3422
                     ->field('uid') // 只需要下级的uid
3423
-                    ->whereIn('spread_uid', $chunk) // spread_uid 在当前层级用户块中
3423
+                    ->whereIn('level_id', $chunk) //level_id 在当前层级用户块中
3424 3424
                     ->where('status', 1)
3425 3425
                     ->select()
3426 3426
                     ->toArray();
@@ -3549,7 +3549,8 @@ class UserRepository extends BaseRepository
3549 3549
         foreach ($userSignGongxianList as $value) {
3550 3550
             // 贡献表中 包含多种类型的 贡献值记录,比如 用户消费商家获得赠送贡献值 , 推广获得的贡献值(直推),这些都不能算是 用户的 直接贡献值
3551 3551
             // 只有 用户取消费 比如:购买 ** 商品、扫码消费获得赠送贡献值 等 才算做个人贡献值
3552
-            if (strpos($value['mark'], "购买") !== false || strpos($value['mark'], "扫码") !== false) {
3552
+            //            || strpos($value['mark'], "扫码") !== false
3553
+            if (strpos($value['mark'], "购买") !== false || strpos($value['mark'], "会员专区消费商品赠送贡献值") !== false) {
3553 3554
                 if($value['type'] == 1) {
3554 3555
                     $type = 1;
3555 3556
                 } else {
@@ -3562,40 +3563,40 @@ class UserRepository extends BaseRepository
3562 3563
                 ];
3563 3564
             }
3564 3565
         }
3565
-        // 老订单 产生的贡献值 并未在 贡献记录表中
3566
-        $oldUserOfGoodsList = Db::name('old_user_of_goods')
3567
-            ->where('status', 1) // '是否完成 0, 未完成 1 已完成',
3568
-            ->whereIn('user_id', $uidList)
3569
-            ->field('user_id, money, status, create_time') // 只需要下级的uid和贡献值
3570
-            ->select()
3571
-            ->toArray();
3572
-        // 定义一个映射数组,用于存储不同 money 对应的 contribute 值
3573
-        $contributeMapping = [
3574
-            1180 => 700,
3575
-            10620 => 6300,
3576
-            11800 => 7000,
3577
-            9440 => 5600,
3578
-            2360 => 1400,
3579
-        ];
3580
-        // 遍历每个 $storeProductData
3581
-        foreach ($oldUserOfGoodsList as $storeProductData) {
3582
-            // 获取 money 的值
3583
-            $money = $storeProductData['money'];
3584
-            // 检查 money 是否在映射中
3585
-            if (isset($contributeMapping[$money])) {
3586
-                // 如果存在,则使用映射的值
3587
-                $contribute = $contributeMapping[$money];
3588
-            } else {
3589
-                // 否则按默认规则计算
3590
-                $contribute = bcmul($money, 0.7, 2);
3591
-            }
3592
-            // 将数据添加到 $userContributeTimeList
3593
-            $userContributeTimeMap[$storeProductData['user_id']][] = [
3594
-                'type' => 1,
3595
-                'contribute' => $contribute,
3596
-                'settlementTime' => $storeProductData['create_time']
3597
-            ];
3598
-        }
3566
+        // // 老订单 产生的贡献值 并未在 贡献记录表中
3567
+        // $oldUserOfGoodsList = Db::name('old_user_of_goods')
3568
+        //     ->where('status', 1) // '是否完成 0, 未完成 1 已完成',
3569
+        //     ->whereIn('user_id', $uidList)
3570
+        //     ->field('user_id, money, status, create_time') // 只需要下级的uid和贡献值
3571
+        //     ->select()
3572
+        //     ->toArray();
3573
+        // // 定义一个映射数组,用于存储不同 money 对应的 contribute 值
3574
+        // $contributeMapping = [
3575
+        //     1180 => 700,
3576
+        //     10620 => 6300,
3577
+        //     11800 => 7000,
3578
+        //     9440 => 5600,
3579
+        //     2360 => 1400,
3580
+        // ];
3581
+        // // 遍历每个 $storeProductData
3582
+        // foreach ($oldUserOfGoodsList as $storeProductData) {
3583
+        //     // 获取 money 的值
3584
+        //     $money = $storeProductData['money'];
3585
+        //     // 检查 money 是否在映射中
3586
+        //     if (isset($contributeMapping[$money])) {
3587
+        //         // 如果存在,则使用映射的值
3588
+        //         $contribute = $contributeMapping[$money];
3589
+        //     } else {
3590
+        //         // 否则按默认规则计算
3591
+        //         $contribute = bcmul($money, 0.7, 2);
3592
+        //     }
3593
+        //     // 将数据添加到 $userContributeTimeList
3594
+        //     $userContributeTimeMap[$storeProductData['user_id']][] = [
3595
+        //         'type' => 1,
3596
+        //         'contribute' => $contribute,
3597
+        //         'settlementTime' => date('Y-m-d H:i:s', $storeProductData['create_time'])
3598
+        //     ];
3599
+        // }
3599 3600
         foreach ($userContributeTimeMap as $key => &$subArray) {
3600 3601
             usort($subArray, function ($a, $b) {
3601 3602
                 return strtotime($a['settlementTime']) - strtotime($b['settlementTime']);
@@ -3630,9 +3631,9 @@ class UserRepository extends BaseRepository
3630 3631
             }
3631 3632
             // 2、获取用户贡献值 日志记录 对应时间
3632 3633
             $userContributeTimeMap = $this->getUserContributeTimeMapByUidList([$uid]);
3634
+            $myIdentityUpTime = '';
3633 3635
             if (!empty($userContributeTimeMap[$uid])) {
3634 3636
                 $myArriveNumOwn = 0;
3635
-                $myIdentityUpTime = '';
3636 3637
                 foreach ($userContributeTimeMap[$uid] as $value) {
3637 3638
                     if ($value['type'] == 1) {
3638 3639
                         $myArriveNumOwn += $value['contribute'];
@@ -3644,12 +3645,17 @@ class UserRepository extends BaseRepository
3644 3645
                         break;
3645 3646
                     }
3646 3647
                 }
3647
-                if (!empty($myIdentityUpTime)) {
3648
-                    $data['identity_up_time'] = $userData['identity_up_time'] = $myIdentityUpTime;
3649
-                    // 只升级 不降级
3650
-                    if ($userData['user_group'] == 1) {
3651
-                        $userData['user_group'] = $yeWuYuanId;
3652
-                    }
3648
+            }
3649
+            if (!empty($myIdentityUpTime)) {
3650
+                $data['identity_up_time'] = $userData['identity_up_time'] = $myIdentityUpTime;
3651
+                // 只升级 不降级
3652
+                if ($userData['user_group'] == 1) {
3653
+                    $userData['user_group'] = $yeWuYuanId;
3654
+                }
3655
+                $this->dao->update($uid, $data);
3656
+            } else {
3657
+                if ($userData['is_old'] == 1) {
3658
+                    $data['identity_up_time'] = $userData['identity_up_time'] = $userData['create_time'];
3653 3659
                     $this->dao->update($uid, $data);
3654 3660
                 }
3655 3661
             }
@@ -3720,7 +3726,7 @@ class UserRepository extends BaseRepository
3720 3726
         $userContributionSumMap = [];
3721 3727
         if ($depth >= 0 && !empty($startTime)) {
3722 3728
             // 获取用户的直属下级
3723
-            $uidContributeList = $this->getUidContributeListBySpreadUidList([$uid]);
3729
+            $uidContributeList = $this->getUidContributeListByLevelIdList([$uid]);
3724 3730
             $uidContributeUidList = array_column($uidContributeList, 'uid');
3725 3731
             $subordinatesOfCurrentLevelUidList = $this->getUserContributeByUidList($uidContributeUidList, $startTime, $endTime);
3726 3732
 

+ 93 - 0
app/controller/admin/system/config/Award.php

@@ -0,0 +1,93 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-24
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\controller\admin\system\config;
12
+
13
+
14
+use crmeb\basic\BaseController;
15
+use app\common\repositories\user\UserAwardRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use think\App;
18
+use think\db\exception\DataNotFoundException;
19
+use think\db\exception\DbException;
20
+use think\db\exception\ModelNotFoundException;
21
+
22
+/**
23
+ * Class Config
24
+ * @package app\controller\admin\system\config
25
+ * @author xaboy
26
+ * @day 2020-03-27
27
+ */
28
+class Award extends BaseController
29
+{
30
+    /**
31
+     * @var UserAwardRepository
32
+     */
33
+    protected $repository;
34
+
35
+    /**
36
+     * Config constructor.
37
+     * @param App $app
38
+     * @param UserAwardRepository $repository
39
+     */
40
+    public function __construct(App $app, UserAwardRepository $repository)
41
+    {
42
+        parent::__construct($app);
43
+        $this->repository = $repository;
44
+    }
45
+
46
+    /**
47
+     * @return mixed
48
+     * @throws DataNotFoundException
49
+     * @throws DbException
50
+     * @throws ModelNotFoundException
51
+     * @author xaboy
52
+     * @day 2020-03-31
53
+     */
54
+    public function lst()
55
+    {
56
+        $where = $this->request->params(['keyword']);
57
+        [$page, $limit] = $this->getPage();
58
+        $lst = $this->repository->getList($where, $page, $limit);
59
+
60
+        return app('json')->success($lst);
61
+    }
62
+
63
+    /**
64
+     * @return mixed
65
+     * @throws DataNotFoundException
66
+     * @throws DbException
67
+     * @throws ModelNotFoundException
68
+     * @throws FormBuilderException
69
+     * @author xaboy
70
+     * @day 2020-03-31
71
+     */
72
+    public function updateTable()
73
+    {
74
+        $data = $this->request->param();
75
+        $form = $this->repository->updateForm($data);
76
+        return app('json')->success(formToData($form));
77
+    }
78
+
79
+    /**
80
+     * @param int $key
81
+     * @return mixed
82
+     * @throws DbException
83
+     * @author xaboy
84
+     * @day 2020-03-27
85
+     */
86
+    public function update($key)
87
+    {
88
+        $data = $this->request->param();
89
+        $this->repository->updateAward($key,$data);
90
+        return app('json')->success('修改成功');
91
+    }
92
+
93
+}

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

@@ -935,7 +935,7 @@ class Auth extends BaseController
935 935
 //
936 936
 //        }
937 937
 
938
-        return Db::name('user')->where(['spread_uid'=>$teamid])->count();
938
+        return Db::name('user')->where(['level_id'=>$teamid])->count();
939 939
 
940 940
     }
941 941
 

+ 47 - 0
app/controller/api/store/merchant/Merchant.php

@@ -142,6 +142,53 @@ class Merchant extends BaseController
142 142
     }
143 143
 
144 144
     /**
145
+     * 商贸区店铺商品列表
146
+     * @return mixed
147
+     * @throws \think\db\exception\DataNotFoundException
148
+     * @throws \think\db\exception\DbException
149
+     * @throws \think\db\exception\ModelNotFoundException
150
+     */
151
+    public function commerceProductList()
152
+    {
153
+        $params= $this->request->params(['pageNum','pageSize']);
154
+        $mer_id_unset = [496,486,439,148,491];
155
+        $domain = $this->request->domain();
156
+        if(strpos($domain, 'test.hebeiyhc.com') !== false) {
157
+            // 域名中包含 "test.hebeiyhc.com'" 字符串
158
+            array_push($mer_id_unset, 486);
159
+        }else{
160
+            array_push($mer_id_unset, 497);
161
+        }
162
+
163
+        $is_commercetrade = 1;
164
+        [$page, $limit] = $this->getPage();
165
+        if($params['pageNum']!=''){
166
+            $page=$params['pageNum'];
167
+        }
168
+        if($params['pageSize']!=''){
169
+            $limit=$params['pageSize'];
170
+        }
171
+        $mer_list = Db::name('merchant')->where(['category_id' => 32,'status' => 1,'is_del' => 0])->page($page)->limit($limit)->select();
172
+        $where['is_gift_bag'] = 0;
173
+        $where['is_used'] = 1;
174
+        $where['product_type'] = 0;
175
+        $where['is_hide'] = 0;
176
+        $return_list = [];
177
+        if($mer_list) {
178
+            $mer_list = $mer_list->toArray();
179
+            foreach ($mer_list as $mer) {
180
+                if(in_array($mer['mer_id'],$mer_id_unset)) continue;
181
+                $goods = $this->repository->productList($mer['mer_id'],$where, 1, 3,$this->userInfo,false,$is_commercetrade);
182
+                if(empty($goods['list'])) continue;
183
+                $mer['goods_list'] = $goods['list'];
184
+                $return_list[] = $mer;
185
+            }
186
+        }
187
+        return app('json')->success(['list'=>$return_list]);
188
+
189
+    }
190
+
191
+    /**
145 192
      * 查询代理人商品
146 193
      * @param $type
147 194
      * @return mixed

+ 643 - 64
app/controller/api/store/merchant/Taskorderguquan.php

@@ -7,6 +7,7 @@
7 7
 
8 8
 namespace app\controller\api\store\merchant;
9 9
 
10
+use app\common\model\user\User;
10 11
 use think\facade\Db;
11 12
 
12 13
 class Taskorderguquan
@@ -14,74 +15,652 @@ class Taskorderguquan
14 15
 
15 16
     public function assignment()
16 17
     {
17
-        /**
18
-         * 周金花200(13959100621)
19
-         * 黄金花200(18603401312)
20
-         * 徐立苹100(13521438652)
21
-         * 李素红200(13701061395)
22
-         * 周行体200(13231658486)
23
-         * 刘银霞100(13161909228)
24
-         * 李卫东100(13911601230)
25
-         * 金    波100(13801358713)
26
-         * 王   玲 150(15810064711)
27
-         * 侯玉兰150(15232797965)
28
-         * 吕丽娣100(15960349667)
29
-         * 张传莲100(15332507711)
30
-         * 刘春梅100(18760167163)
31
-         * 付天如100(18863873000)
32
-         * 付绍先100(15324059286)
33
-         * 黄桂林100(15960196876)
34
-         * 温  煌100(18350134089)
35
-         * 谭英先100(13978627072)
36
-         * 陈玉珍100(19858353660)
37
-         * 黄雪云100(18650055445)
38
-         * 黄  玲100(13877193411)
39
-         * 邱佳珍100(13960379098)
40
-         * 隋彩云100(13601071082)
41
-         */
42
-        $data = [
43
-            '13959100621' => 200,
44
-            '18603401312' => 200,
45
-            '13521438652' => 100,
46
-            '13701061395' => 200,
47
-            '13231658486' => 200,
48
-            '13161909228' => 100,
49
-            '13911601230' => 100,
50
-            '13801358713' => 100,
51
-            '15810064711' => 150,
52
-            '15232797965' => 150,
53
-            '15960349667' => 100,
54
-            '15332507711' => 100,
55
-            '18760167163' => 100,
56
-            '18863873000' => 100,
57
-            '15324059286' => 100,
58
-            '15960196876' => 100,
59
-            '18350134089' => 100,
60
-            '13978627072' => 100,
61
-            '19858353660' => 100,
62
-            '18650055445' => 100,
63
-            '13877193411' => 100,
64
-            '13960379098' => 100,
65
-            '13601071082' => 100,
18
+        $result = [
19
+            'oldOrderExistGongXian' => [],
20
+            'orderExistGongXian' => [],
21
+            'oldOrderExistPv' => [],
22
+            'orderExistPv' => [],
23
+            'gongXianDataOldList' => [],
24
+            'gongXianDataList' => [],
25
+            'pvDataOldList' => [],
26
+            'pvDataList' => [],
27
+            'contributeNot' => [],
28
+            'pvNot' => [],
29
+            'userUpdateSummary' => ['success' => 0, 'failed' => 0, 'skipped' => 0], // 优化: 汇总用户更新结果
30
+            'insertGongXianSummary' => ['success' => 0, 'failed' => 0], // 优化: 汇总贡献插入结果
31
+            'insertPvSummary' => ['success' => 0, 'failed' => 0],         // 优化: 汇总PV插入结果
32
+            'errors' => [],               // 优化: 统一记录错误信息
66 33
         ];
67
-        $result = Db::name("user")
68
-            ->whereIn("account", array_keys($data))
34
+
35
+        // --- 数据库查询部分 (保持不变,已优化) ---
36
+        // 1. 查询用户
37
+        $userList = Db::name("user")
69 38
             ->where('is_del', 0)
70
-            ->field('uid, brokerage_price, account, nickname')
71
-            ->select();
72
-        $res = [];
73
-        foreach ($result as $v) {
74
-            Db::name("user")->where("uid", $v['uid'])->inc("brokerage_price", $data[$v['account']])->save();
75
-            $this->bill_user_log111111($v['uid'], "佣金补贴", $data[$v['account']], "佣金补贴", 8);//股权分佣明细2.0系统
76
-            $res[] = [
77
-                'uid' => $v['uid'],
78
-                'account' => $v['account'],
79
-                'brokerage_price_pre' => $v['brokerage_price'],
80
-                'brokerage_price' => $data[$v['account']],
81
-                'nickname' => $v['nickname']
39
+            //            ->whereIn('uid', [277, 1593])
40
+            ->column('uid, spread_uid, contribute, per_contribute, pv', 'uid');
41
+        // $userIds = array_keys($userList);
42
+
43
+        $oldUserList = Db::name("old_user_jbp")
44
+            ->column('id, amount');
45
+
46
+        // 2. 查询老订单
47
+        $userOfGoodsListRaw = Db::name("old_user_of_goods")
48
+            ->where('status', 1)
49
+            // 优化: 如果用户量大,可以考虑只查相关用户的订单
50
+            // ->whereIn('user_id', $userIds)
51
+            ->field('user_id, money, order_id, create_time')
52
+            ->select()
53
+            ->toArray();
54
+
55
+        // 3. 查询新订单
56
+        $storeOrderListRaw = Db::name("store_order")
57
+            ->whereIn('status', [0, 1, 2, 3])
58
+            // 优化: 如果用户量大,可以考虑只查相关用户的订单
59
+            // ->whereIn('uid', $userIds)
60
+            ->field('uid, pay_price, mer_id, status, order_id, create_time')
61
+            ->select()
62
+            ->toArray();
63
+
64
+        // 4. 查询已存在的贡献值记录
65
+        $gongXianListRaw = Db::name("user_sign_gongxian")
66
+            ->where('status', '<>', -1)
67
+            // 优化: 如果记录非常多,可以分批查询或只查相关用户的
68
+            // ->whereIn('uid', array_merge($userIds, array_column($userList, 'spread_uid'))) // 查询购买者和潜在推广者
69
+            ->field('uid, order_id, number, status, type')
70
+            ->select()
71
+            ->toArray();
72
+
73
+        // 5. 查询已存在的PV记录
74
+        $pvListRaw = Db::name("user_pv_log")
75
+            ->where('status', '<>', -1)
76
+            // 优化: 同上
77
+            // ->whereIn('uid', $userIds)
78
+            ->field('uid, order_id, pv, status')
79
+            ->select()
80
+            ->toArray();
81
+
82
+        // --- 数据预处理部分
83
+        $existingGongXian = [];
84
+        $existingGongXianByUid = [];
85
+        foreach ($gongXianListRaw as $gx) {
86
+            $existingGongXian[$gx['uid'] . '_' . $gx['order_id']] = ['number' => $gx['number'], 'status' => $gx['status'], 'type' => $gx['type']];
87
+            // TODO 目前老订单id 1-900 新订单ID 4868 - 6255 线下扫码订单 6870 - 8733
88
+            if ((1 <= $gx['order_id'] && $gx['order_id'] <= 900) || (4868 <= $gx['order_id'] && $gx['order_id'] <= 6869)) {
89
+                $existingGongXianByUid[$gx['uid']][] = $gx['order_id'];
90
+            }
91
+        }
92
+        unset($gongXianListRaw);
93
+
94
+        $existingPv = [];
95
+        $existingPvByUid = [];
96
+        foreach ($pvListRaw as $pv) {
97
+            $existingPv[$pv['uid'] . '_' . $pv['order_id']] = ['pv' => $pv['pv'], 'status' => $pv['status']];
98
+            // TODO 目前老订单id 1-900 新订单ID 4868 - 6255 线下扫码订单 6870 - 8733
99
+            if ((1 <= $pv['order_id'] && $pv['order_id'] <= 900) || (4868 <= $pv['order_id'] && $pv['order_id'] <= 6869)) {
100
+                $existingPvByUid[$pv['uid']][] = $pv['order_id'];
101
+            }
102
+        }
103
+        unset($pvListRaw);
104
+
105
+        $userOfGoodsByUid = [];
106
+        foreach ($userOfGoodsListRaw as $oldOrder) $userOfGoodsByUid[$oldOrder['user_id']][] = $oldOrder;
107
+        unset($userOfGoodsListRaw);
108
+
109
+        $storeOrdersByUid = [];
110
+        foreach ($storeOrderListRaw as $order) $storeOrdersByUid[$order['uid']][] = $order;
111
+        unset($storeOrderListRaw);
112
+
113
+        // *** 主逻辑处理与数据收集 ***
114
+        $gongXianDataToInsert = []; // 优化: 合并新旧贡献插入列表
115
+        $pvDataToInsert = [];       // 优化: 合并新旧PV插入列表
116
+        $userUpdateData = [];       // 优化: 收集所有需要更新的用户数据 [uid => ['contribute'=>float, 'pv'=>float, 'per_contribute'=>float]]
117
+
118
+        // 初始化所有用户的待更新数据
119
+        foreach ($userList as $uid => $user) {
120
+            // 预先设置初始值,确保即使没有订单的用户也能被包含在后续可能的更新逻辑中(如果需要)
121
+            // 如果用户没有任何订单,他们的 contribute 和 pv 应该保持数据库原始值或根据业务逻辑设为0
122
+            // 这里我们先假设如果没有订单,他们的计算值就是0
123
+            $userUpdateData[$uid] = [
124
+                'uid' => $uid,
125
+                'contribute' => 0.0,
126
+                'pv' => 0.0,
127
+                'per_contribute' => 0.0,
82 128
             ];
129
+            // 初始化推广者的 per_contribute 累加器
130
+            if (!empty($user['spread_uid'])) {
131
+                $spreadUid = $user['spread_uid'];
132
+                if (!isset($userUpdateData[$spreadUid])) {
133
+                    if (isset($userList[$spreadUid])) {
134
+                        if (!isset($userUpdateData[$spreadUid]['per_contribute'])) {
135
+                            $userUpdateData[$spreadUid]['per_contribute'] = 0.0; // 初始化推广者的累加
136
+                        }
137
+                    } else {
138
+                        // 记录或处理推广者不在当前用户列表的情况
139
+                        $result['errors'][] = "执行{$uid}时,没找到 推荐人 {$spreadUid}";
140
+                        // 可以选择跳过给这个推广者增加 per_contribute
141
+                    }
142
+
143
+                } else if (!isset($userUpdateData[$spreadUid]['per_contribute'])) {
144
+                    $userUpdateData[$spreadUid]['per_contribute'] = 0.0; // 初始化推广者的累加
145
+                }
146
+            }
147
+        }
148
+
149
+        // 遍历用户列表进行计算和数据收集
150
+        foreach ($userList as $uid => $user) {
151
+            $spreadUid = $user['spread_uid'];
152
+            $existingGongXianByUid[$uid] = $existingGongXianByUid[$uid] ?? [];
153
+            $existingPvByUid[$uid] = $existingPvByUid[$uid] ?? [];
154
+            if (isset($userOfGoodsByUid[$uid])) {
155
+                foreach ($userOfGoodsByUid[$uid] as $oldOrder) {
156
+                    switch ($oldOrder['money']) {
157
+                        case 1180:
158
+                            $totalPv = 700.0;
159
+                            break;
160
+                        case 11800:
161
+                            $totalPv = 7000.0;
162
+                            break;
163
+                        case 10620:
164
+                            $totalPv = 6300.0;
165
+                            break;
166
+                        case 2360:
167
+                            $totalPv = 1400.0;
168
+                            break;
169
+                        case 9440:
170
+                            $totalPv = 5600.0;
171
+                            break;
172
+                        default:
173
+                            $totalPv = round($oldOrder['money'] * 0.7, 2);
174
+                            break;
175
+                    }
176
+
177
+                    $settlementTimeOld = $oldOrder['create_time'] ? date('Y-m-d H:i:s', $oldOrder['create_time']) : strtotime($user['create_time']);
178
+                    // --- 收集贡献值插入数据 ---
179
+                    $orderKey = $uid . '_' . $oldOrder['order_id'];
180
+                    // 一个人 同一个订单 可能有多条记录 有问题
181
+                    if (isset($existingGongXian[$orderKey])) {
182
+                        $result['oldOrderExistGongXian'][] = ['uid' => $uid, 'order_id' => $oldOrder['order_id']];
183
+                        $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$oldOrder['order_id']]);
184
+                        if ($existingGongXian[$orderKey]['status'] == 1) {
185
+                            if ($existingGongXian[$orderKey]['type'] == 1) {
186
+                                $userUpdateData[$uid]['contribute'] += $existingGongXian[$orderKey]['number'];
187
+                            } else if ($existingGongXian[$orderKey]['type'] == 2) {
188
+                                $userUpdateData[$uid]['contribute'] -= $existingGongXian[$orderKey]['number'];
189
+                            }
190
+                        }
191
+                        if (!empty($spreadUid) && isset($userUpdateData[$spreadUid])) {
192
+                            $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$oldOrder['order_id']]);
193
+                            if (isset($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']])) {
194
+                                if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['status'] == 1) {
195
+                                    if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['type'] == 1) {
196
+                                        $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['number'];
197
+                                    } else if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['type'] == 2) {
198
+                                        $userUpdateData[$spreadUid]['per_contribute'] -= $existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['number'];
199
+                                    }
200
+                                }
201
+                            }
202
+                        }
203
+                    } else {
204
+                        if ($totalPv > 0) {
205
+                            $userUpdateData[$uid]['contribute'] += $totalPv;
206
+                            // --- 收集贡献值插入数据 ---
207
+                            $gongXianBase = [
208
+                                "number" => $totalPv, "addtime" => strtotime($settlementTimeOld), "status" => 1,
209
+                                "order_type" => 21, "order_id" => $oldOrder['order_id'],
210
+                                "desc" => '', "surplus" => 0, "type" => 1, 'settlement_time' => $settlementTimeOld
211
+                            ];
212
+                            // 本人
213
+                            $gongXianDataToInsert[] = array_merge(["uid" => $uid, "mark" => "购买会员专区商品赠送贡献值(1.0)"], $gongXianBase);
214
+                            $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$oldOrder['order_id']]);
215
+                            // 推广人
216
+                            if (!empty($user['spread_uid'])) {
217
+                                if (isset($userUpdateData[$spreadUid])) {
218
+                                    $userUpdateData[$spreadUid]['per_contribute'] += $totalPv;
219
+                                    $gongXianDataToInsert[] = array_merge(["uid" => $spreadUid, "mark" => "推广会员专区商品赠送贡献值(1.0)"], $gongXianBase);
220
+                                    $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$oldOrder['order_id']]);
221
+                                }
222
+                            }
223
+                        }
224
+                    }
225
+                    // --- 收集 PV 插入数据 ---
226
+                    if (isset($existingPv[$orderKey])) {
227
+                        $result['oldOrderExistPv'][] = ['uid' => $uid, 'order_id' => $oldOrder['order_id']];
228
+                        if ($existingPv[$orderKey]['status'] == 1) {
229
+                            $userUpdateData[$uid]['pv'] += $existingPv[$orderKey]['pv'];
230
+                        }
231
+                    } else {
232
+                        $userUpdateData[$uid]['pv'] += $totalPv;
233
+                        $pvDataToInsert[] = [
234
+                            "uid" => $uid, "pv" => $totalPv, "addtime" => strtotime($settlementTimeOld), "status" => 1,
235
+                            "order_type" => 21, "order_id" => $oldOrder['order_id'],
236
+                            "mark" => "购买会员专区商品赠送PV(1.0)", 'settlement_time' => $settlementTimeOld
237
+                        ];
238
+                    }
239
+                    if (!empty($existingPvByUid[$uid])) {
240
+                        $existingPvByUid[$uid] = array_diff($existingPvByUid[$uid], [$oldOrder['order_id']]);
241
+                    }
242
+                }
243
+            } // end if isset($userOfGoodsByUid[$uid])
244
+
245
+            // --- 处理新订单 ---
246
+            if (isset($storeOrdersByUid[$uid])) {
247
+                foreach ($storeOrdersByUid[$uid] as $order) {
248
+                    $totalPv = 0.0;
249
+                    // ... (if/else logic and switch case for $totalPv calculation - same as before)
250
+                    if ($order['mer_id'] == 496) {
251
+                        switch ($order['pay_price']) {
252
+                            case 1180:
253
+                                $totalPv = 700.0;
254
+                                break;
255
+                            case 11800:
256
+                                $totalPv = 7000.0;
257
+                                break;
258
+                            case 10620:
259
+                                $totalPv = 6300.0;
260
+                                break;
261
+                            case 2360:
262
+                                $totalPv = 1400.0;
263
+                                break;
264
+                            case 9440:
265
+                                $totalPv = 5600.0;
266
+                                break;
267
+                            default:
268
+                                $totalPv = round($order['pay_price'] * 0.7, 2);
269
+                                break;
270
+                        }
271
+                    } else if ($order['status'] == 3) {
272
+                        $totalPv = round($order['pay_price'] * 0.7, 2);
273
+                    }
274
+                    // --- 收集贡献值插入数据 ---
275
+                    $orderKey = $uid . '_' . $order['order_id'];
276
+                    $settlementTimeNew = $order['create_time'] ?: date('Y-m-d H:i:s', $user['create_time']);
277
+                    // --- 收集贡献值插入数据 ---
278
+                    if (isset($existingGongXian[$orderKey])) {
279
+                        $result['orderExistGongXian'][] = ['uid' => $uid, 'order_id' => $order['order_id']];
280
+                        $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$order['order_id']]);
281
+                        // 累加计算值
282
+                        if ($existingGongXian[$orderKey]['status'] == 1) {
283
+                            if ($existingGongXian[$orderKey]['type'] == 1) {
284
+                                $userUpdateData[$uid]['contribute'] += $existingGongXian[$orderKey]['number'];
285
+                            } else if ($existingGongXian[$orderKey]['type'] == 2) {
286
+                                $userUpdateData[$uid]['contribute'] -= $existingGongXian[$orderKey]['number'];
287
+                            }
288
+                        }
289
+                        if (!empty($spreadUid) && isset($userUpdateData[$spreadUid])) {
290
+                            $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$order['order_id']]);
291
+                            if (isset($existingGongXian[$spreadUid . '_' . $order['order_id']])) {
292
+                                if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['status'] == 1) {
293
+                                    if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['type'] == 1) {
294
+                                        $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $order['order_id']]['number'];
295
+                                    } else if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['type'] == 2) {
296
+                                        $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $order['order_id']]['number'];
297
+                                    }
298
+                                }
299
+                            }
300
+                        }
301
+
302
+                    } else {
303
+                        if ($totalPv > 0) {
304
+                            $userUpdateData[$uid]['contribute'] += $totalPv;
305
+                            $gongXianBase = [ // 优化: 提取公共字段
306
+                                "number" => $totalPv, "addtime" => strtotime($settlementTimeNew), "status" => 1,
307
+                                "order_type" => 22, "order_id" => $order['order_id'],
308
+                                "desc" => '', "surplus" => 0, "type" => 1, 'settlement_time' => $settlementTimeNew
309
+                            ];
310
+                            // 本人
311
+                            $gongXianDataToInsert[] = array_merge(["uid" => $uid, "mark" => "购买商品赠送贡献值(2.0)"], $gongXianBase);
312
+                            $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$order['order_id']]);
313
+                            // 推广人
314
+                            if (!empty($user['spread_uid'])) {
315
+                                $spreadUid = $user['spread_uid'];
316
+                                if (isset($userUpdateData[$spreadUid])) { // 确保推广者存在
317
+                                    $gongXianDataToInsert[] = array_merge(["uid" => $spreadUid, "mark" => "推广商品赠送贡献值(2.0)"], $gongXianBase);
318
+                                    $userUpdateData[$spreadUid]['per_contribute'] += $totalPv; // 累加推广者业绩
319
+                                    $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$order['order_id']]);
320
+                                }
321
+                            }
322
+                        }
323
+                    }
324
+
325
+                    // --- 收集 PV 插入数据 ---
326
+                    if (isset($existingPv[$orderKey])) {
327
+                        $result['orderExistPv'][] = ['uid' => $uid, 'order_id' => $order['order_id']];
328
+                        if ($existingPv[$orderKey]['status'] == 1) {
329
+                            $userUpdateData[$uid]['pv'] += $existingPv[$orderKey]['pv'];
330
+                        }
331
+                    } else {
332
+                        $userUpdateData[$uid]['pv'] += $totalPv;
333
+                        $pvDataToInsert[] = [
334
+                            "uid" => $uid, "pv" => $totalPv, "addtime" => strtotime($settlementTimeNew), "status" => 1,
335
+                            "order_type" => 22, // 确认 PV log 的 order_type 是否与贡献一致或有区分
336
+                            "order_id" => $order['order_id'],
337
+                            "mark" => "购买商品赠送PV(2.0)", // 标记调整为更通用
338
+                            'settlement_time' => $settlementTimeNew
339
+                        ];
340
+                    }
341
+                    if (!empty($existingPvByUid[$uid])) {
342
+                        $existingPvByUid[$uid] = array_diff($existingPvByUid[$uid], [$order['order_id']]);
343
+                    }
344
+                }
345
+            }
346
+            // end if isset($storeOrdersByUid[$uid])
347
+
348
+            // --- 比较计算值与原值 (移到循环外处理) ---
349
+            // (在此处比较并记录到 $result['contributeNot'] / $result['pvNot'])
350
+            // 注意:浮点数比较可能需要容差
351
+            $tolerance = 0.001; // 定义一个小的容差值
352
+            if (abs($userUpdateData[$uid]['contribute'] - (float)$user['contribute']) > $tolerance) {
353
+                $result['contributeNot'][] = [
354
+                    'uid' => $uid,
355
+                    'contribute_old' => (float)$user['contribute'], // 显式转换
356
+                    'contribute_new' => $userUpdateData[$uid]['contribute']
357
+                ];
358
+            }
359
+            if (abs($userUpdateData[$uid]['pv'] - (float)$user['pv']) > $tolerance) {
360
+                $result['pvNot'][] = [
361
+                    'uid' => $uid,
362
+                    'pv_old' => (float)$user['pv'], // 显式转换
363
+                    'pv_new' => $userUpdateData[$uid]['pv']
364
+                ];
365
+            }
366
+            // per_contribute 是累加的,不需要与旧值比较,直接更新
367
+
368
+        } // end foreach ($userList as $uid => $user)
369
+
370
+        // *** 数据库批量操作 ***
371
+        // 使用事务确保数据一致性
372
+        Db::startTrans();
373
+        try {
374
+            $bill = [];
375
+            foreach ($oldUserList as $item) {
376
+                $bill[] = [
377
+                    'uid' => $item['id'],
378
+                    'link_id' => 0,//关联订单id
379
+                    'pm' => 1,//0:支出,1:获得
380
+                    'title' => '佣金',//账单标题
381
+                    'category' => 'now_money',//明细种类
382
+                    'type' => 'commission',//明细类型
383
+                    'number' => $item['amount'],//明细数字
384
+                    'balance' => 0,//剩余
385
+                    'mark' => '1.0佣金记录',//备注
386
+                    'create_time' => '2025-02-04 00:00:00',//添加时间
387
+                    'status' => 1,//0待确定,1有效,-1无效
388
+                    'commission_type' => 21,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
389
+                    //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
390
+                    //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
391
+                    'order_sn' => 0,//订单号
392
+                    'tripartite' => 0,//
393
+                    'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
394
+                    'mer_id' => 0,//商户id
395
+                    'source' => 0,//1线下 0线上
396
+                    'order_type' => 1,//1自营  2 第三方  订单类型
397
+                    'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
398
+                    'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
399
+                    'take_time' => '',//结算时间
400
+                    'district_id' => '',//
401
+                    'street_id' => '',//
402
+                    'month' => '',//月份
403
+
404
+
405
+                ];
406
+            }
407
+            $chunkedBill = array_chunk($bill, 500);
408
+            foreach ($chunkedBill as $chunk) {
409
+                Db::name('user_bill')->insertAll($chunk);
410
+            }
411
+
412
+            if (!empty($existingGongXianByUid)) {
413
+                foreach ($existingGongXianByUid as $uid => $orderList) {
414
+                    if (!empty($orderList)) {
415
+                        Db::name("user_sign_gongxian")
416
+                            ->where('uid', $uid)
417
+                            ->whereIn('order_id', $orderList)
418
+                            ->update(['status' => 0]);
419
+                    }
420
+                }
421
+            }
422
+            if (!empty($existingPvByUid)) {
423
+                foreach ($existingPvByUid as $uid => $orderList) {
424
+                    if (!empty($orderList)) {
425
+                        Db::name("user_pv_log")
426
+                            ->where('uid', $uid)
427
+                            ->whereIn('order_id', $orderList)
428
+                            ->update(['status' => 0]);
429
+                    }
430
+                }
431
+            }
432
+            // --- 批量插入贡献值 ---
433
+            if (!empty($gongXianDataToInsert)) {
434
+                // 分块插入,避免单次插入过多数据 (例如一次500条)
435
+                $chunkedGongXian = array_chunk($gongXianDataToInsert, 500);
436
+                foreach ($chunkedGongXian as $chunk) {
437
+                    $insertedGongXianCount = Db::name('user_sign_gongxian')->insertAll($chunk);
438
+                    $result['insertGongXianSummary']['success'] += $insertedGongXianCount;
439
+                }
440
+
441
+                if ($result['insertGongXianSummary']['success'] < count($gongXianDataToInsert)) {
442
+                    $result['insertGongXianSummary']['failed'] = count($gongXianDataToInsert) - $result['insertGongXianSummary']['success'];
443
+                    // 可以考虑记录更详细的失败信息,但这比较复杂,需要知道哪些失败了
444
+                    $result['errors'][] = "GongXian insertion partially failed or failed completely.";
445
+                    // 根据业务决定是否回滚
446
+                    // throw new Exception("GongXian insertion failed");
447
+                }
448
+            } else {
449
+                $result['insertGongXianSummary']['skipped'] = true; // 标记为跳过(无数据)
450
+            }
451
+
452
+            // --- 批量插入PV ---
453
+            if (!empty($pvDataToInsert)) {
454
+                $chunkedPv = array_chunk($pvDataToInsert, 500);
455
+                foreach ($chunkedPv as $chunk) {
456
+                    $insertedPvCount = Db::name('user_pv_log')->insertAll($chunk);
457
+                    $result['insertPvSummary']['success'] += $insertedPvCount;
458
+                }
459
+                if ($result['insertPvSummary']['success'] < count($pvDataToInsert)) {
460
+                    $result['insertPvSummary']['failed'] = count($pvDataToInsert) - $result['insertPvSummary']['success'];
461
+                    $result['errors'][] = "PV Log insertion partially failed or failed completely.";
462
+                    // throw new Exception("PV Log insertion failed");
463
+                }
464
+            } else {
465
+                $result['insertPvSummary']['skipped'] = true; // 标记为跳过(无数据)
466
+            }
467
+
468
+            // --- 批量更新用户信息 ---
469
+            $usersToUpdate = [];
470
+            // 筛选出实际需要更新的用户数据 (值有变化或 per_contribute > 0)
471
+            foreach ($userUpdateData as $uid => $updateInfo) {
472
+                $originalUser = $userList[$uid]; // 获取原始用户信息
473
+                // 检查 contribute 或 pv 是否变化(使用容差),或者 per_contribute 是否需要更新
474
+                $needsUpdate = false;
475
+                if (abs($updateInfo['contribute'] - (float)$originalUser['contribute']) > $tolerance) $needsUpdate = true;
476
+                if (abs($updateInfo['pv'] - (float)$originalUser['pv']) > $tolerance) $needsUpdate = true;
477
+                // per_contribute 始终更新,因为它是在现有基础上累加的(除非业务定义不同)
478
+                // 如果 per_contribute 数据库设计是直接覆盖,那只有 > 0 时才需要更新
479
+                // 假设是覆盖更新,且只有大于0时才需要更新变动(如果一直是0则不用更新)
480
+                if ($updateInfo['per_contribute'] > 0.0) { // 只有当推广业绩>0时才触发更新
481
+                    // 这里需要确认 per_contribute 是覆盖还是累加?
482
+                    // 如果是数据库累加: Db::name("user")->where('uid', $uid)->inc('per_contribute', $amount)->update(); 需要单独处理
483
+                    // 如果是覆盖: 直接放入 saveAll
484
+                    // 假设是覆盖,我们只更新有变化的或per_contribute > 0 的
485
+                    $needsUpdate = true;
486
+                } else {
487
+                    // 如果 per_contribute 计算结果为0,且 contribute 和 pv 也未变,则不需要更新 per_contribute 字段
488
+                    unset($updateInfo['per_contribute']); // 移除无需更新的 per_contribute
489
+                    if (empty($updateInfo)) $needsUpdate = false; // 如果移除后为空,则不更新
490
+                }
491
+
492
+                if ($needsUpdate) {
493
+                    // 确保只包含需要更新的字段,并且包含主键 'uid'
494
+                    $finalUpdateData = ['uid' => $uid];
495
+                    if (isset($updateInfo['contribute'])) $finalUpdateData['contribute'] = $updateInfo['contribute'];
496
+                    if (isset($updateInfo['pv'])) $finalUpdateData['pv'] = $updateInfo['pv'];
497
+                    if (isset($updateInfo['per_contribute']) && $updateInfo['per_contribute'] > 0.0) { // 再次确认只更新大于0的推广业绩
498
+                        $finalUpdateData['per_contribute'] = $updateInfo['per_contribute'];
499
+                    }
500
+
501
+                    if (count($finalUpdateData) > 1) { // 确保除了uid还有其他字段要更新
502
+                        $usersToUpdate[] = $finalUpdateData;
503
+                    } else {
504
+                        $result['userUpdateSummary']['skipped']++; // 记录跳过的更新(无变化)
505
+                    }
506
+
507
+                } else {
508
+                    $result['userUpdateSummary']['skipped']++; // 记录跳过的更新(无变化)
509
+                }
510
+            }
511
+
512
+            if (!empty($usersToUpdate)) {
513
+                // 使用 saveAll 进行批量更新 (要求 PHP >= 7.1.8 for MySQL)
514
+                // saveAll 会根据主键 'uid' 更新对应记录
515
+                $userModel = new User();
516
+                $updatedCount = $userModel->saveAll($usersToUpdate); // TP6 支持 saveAll
517
+
518
+                // 注意: saveAll 返回的是成功保存或更新的 *对象集合* 或 *布尔值*,不是影响的行数。
519
+                // 需要检查返回类型并判断成功数量。通常返回集合时 count(集合) 是成功数。
520
+                // 如果是 TP5,可能需要循环 update 或构造复杂 SQL。
521
+                // 假设 TP6 saveAll 成功会返回包含更新后数据的集合或true,失败是false
522
+                if ($updatedCount !== false) {
523
+                    // 这里需要一种方法来确定实际更新了多少条记录。
524
+                    // saveAll 的返回值可能需要进一步处理。
525
+                    // 简单假设:如果返回不是 false,就认为请求中的都成功了(可能不准确)
526
+                    // 更精确的方法是 saveAll 后再查询一次确认。
527
+                    // 这里我们暂时认为 saveAll 返回非 false 即为大部分成功
528
+                    $result['userUpdateSummary']['success'] = count($usersToUpdate); // 乐观估计
529
+                } else {
530
+                    $result['userUpdateSummary']['failed'] = count($usersToUpdate); // 全部失败
531
+                    $result['errors'][] = "User batch update failed using saveAll.";
532
+                    // throw new Exception("User batch update failed");
533
+                }
534
+            }
535
+            // 更新统计:失败数等于总数减去成功和跳过的
536
+            //$result['userUpdateSummary']['failed'] = count($userList) - $result['userUpdateSummary']['success'] - $result['userUpdateSummary']['skipped'];
537
+
538
+            // 如果所有操作都成功,提交事务
539
+            Db::commit();
540
+
541
+        } catch
542
+        (\Exception $e) {
543
+            // 如果任何数据库操作失败,回滚事务
544
+            Db::rollback();
545
+            // 记录错误信息
546
+            $result['errors'][] = "Transaction failed: " . $e->getMessage();
547
+            // 可以根据需要将 insert/update 摘要设置为失败
548
+            $result['userUpdateSummary']['failed'] = count($usersToUpdate); // 假设更新失败
549
+            $result['insertGongXianSummary']['failed'] = count($gongXianDataToInsert); // 假设插入失败
550
+            $result['insertPvSummary']['failed'] = count($pvDataToInsert);      // 假设插入失败
83 551
         }
84
-        return json($res);
552
+
553
+        // --- 清理/最终结果赋值 (可选) ---
554
+        // $result['gongXianDataOldList'] = $gongXianDataOldList; // 这些已合并到 ToInsert
555
+        // $result['gongXianDataList'] = $gongXianDataList;
556
+        // $result['pvDataOldList'] = $pvDataOldList;
557
+        // $result['pvDataList'] = $pvDataList;
558
+
559
+        return json($result);
560
+
561
+        //        // 计算总业绩
562
+        //        $totalPv = [];
563
+        //        foreach ($user_team_amount as $order) {
564
+        //            if (!isset($totalPv[$order['user_id']])) {
565
+        //                $totalPv[$order['user_id']] = 0;
566
+        //            }
567
+        //            switch ($order['money']) {
568
+        //                case 1180:
569
+        //                    $totalPv[$order['user_id']] += 700;
570
+        //                    break;
571
+        //                case 11800:
572
+        //                    $totalPv[$order['user_id']] += 7000;
573
+        //                    break;
574
+        //                case 10620:
575
+        //                    $totalPv[$order['user_id']] += 6300;
576
+        //                    break;
577
+        //                case 2360:
578
+        //                    $totalPv[$order['user_id']] += 1400;
579
+        //                    break;
580
+        //                case 9440:
581
+        //                    $totalPv[$order['user_id']] += 5600;
582
+        //                    break;
583
+        //                default:
584
+        //                    if ($order['money'] == 2344.99) {
585
+        //                        break;
586
+        //                    }
587
+        //                    $totalPv[$order['user_id']] += round($order['money'] * 0.7, 2);
588
+        //                    break;
589
+        //            }
590
+        //        }
591
+        //        foreach ($totalPv as $uid => $pv) {
592
+        //            Db::name("user")->where('is_old', 1)->where("uid", $uid)->update(['pv' => $pv]);
593
+        //        }
594
+        //
595
+        //        return;
596
+        //        /**
597
+        //         * 周金花200(13959100621)
598
+        //         * 黄金花200(18603401312)
599
+        //         * 徐立苹100(13521438652)
600
+        //         * 李素红200(13701061395)
601
+        //         * 周行体200(13231658486)
602
+        //         * 刘银霞100(13161909228)
603
+        //         * 李卫东100(13911601230)
604
+        //         * 金    波100(13801358713)
605
+        //         * 王   玲 150(15810064711)
606
+        //         * 侯玉兰150(15232797965)
607
+        //         * 吕丽娣100(15960349667)
608
+        //         * 张传莲100(15332507711)
609
+        //         * 刘春梅100(18760167163)
610
+        //         * 付天如100(18863873000)
611
+        //         * 付绍先100(15324059286)
612
+        //         * 黄桂林100(15960196876)
613
+        //         * 温  煌100(18350134089)
614
+        //         * 谭英先100(13978627072)
615
+        //         * 陈玉珍100(19858353660)
616
+        //         * 黄雪云100(18650055445)
617
+        //         * 黄  玲100(13877193411)
618
+        //         * 邱佳珍100(13960379098)
619
+        //         * 隋彩云100(13601071082)
620
+        //         */
621
+        //        $data = [
622
+        //            '13959100621' => 200,
623
+        //            '18603401312' => 200,
624
+        //            '13521438652' => 100,
625
+        //            '13701061395' => 200,
626
+        //            '13231658486' => 200,
627
+        //            '13161909228' => 100,
628
+        //            '13911601230' => 100,
629
+        //            '13801358713' => 100,
630
+        //            '15810064711' => 150,
631
+        //            '15232797965' => 150,
632
+        //            '15960349667' => 100,
633
+        //            '15332507711' => 100,
634
+        //            '18760167163' => 100,
635
+        //            '18863873000' => 100,
636
+        //            '15324059286' => 100,
637
+        //            '15960196876' => 100,
638
+        //            '18350134089' => 100,
639
+        //            '13978627072' => 100,
640
+        //            '19858353660' => 100,
641
+        //            '18650055445' => 100,
642
+        //            '13877193411' => 100,
643
+        //            '13960379098' => 100,
644
+        //            '13601071082' => 100,
645
+        //        ];
646
+        //        $result = Db::name("user")
647
+        //            ->whereIn("account", array_keys($data))
648
+        //            ->where('is_del', 0)
649
+        //            ->field('uid, brokerage_price, account, nickname')
650
+        //            ->select();
651
+        //        $res = [];
652
+        //        foreach ($result as $v) {
653
+        //            Db::name("user")->where("uid", $v['uid'])->inc("brokerage_price", $data[$v['account']])->save();
654
+        //            $this->bill_user_log111111($v['uid'], "佣金补贴", $data[$v['account']], "佣金补贴", 8);//股权分佣明细2.0系统
655
+        //            $res[] = [
656
+        //                'uid' => $v['uid'],
657
+        //                'account' => $v['account'],
658
+        //                'brokerage_price_pre' => $v['brokerage_price'],
659
+        //                'brokerage_price' => $data[$v['account']],
660
+        //                'nickname' => $v['nickname']
661
+        //            ];
662
+        //        }
663
+        //        return json($res);
85 664
 
86 665
     }
87 666
 

+ 7 - 7
app/controller/api/store/product/Jt.php

@@ -589,13 +589,13 @@ class Jt extends BaseController
589 589
 
590 590
             $formatData['materialUrl'] = '';
591 591
             if($userId!=''){
592
-            //加入转链地址
593
-            $clparams = [
594
-                'positionid' => pow(10, 5) + $userId,
595
-                'gid' => $goodsId,
596
-                'coupon_url' => $detail['couponInfo']['couponList'][0]['discount_link'] ?? '',
597
-            ];
598
-            $formatData['materialUrl'] = $this->changLink($clparams);
592
+                //加入转链地址 此步骤可优化 分两个步骤
593
+                $clparams = [
594
+                    'positionid' => pow(10, 5) + $userId,
595
+                    'gid' => $goodsId,
596
+                    'coupon_url' => $detail['couponInfo']['couponList'][0]['discount_link'] ?? '',
597
+                ];
598
+                $formatData['materialUrl'] = $this->changLink($clparams);
599 599
             }
600 600
 
601 601
             $return[] = $formatData;

Разница между файлами не показана из-за своего большого размера
+ 300 - 263
app/controller/api/user/User.php


+ 7 - 0
route/admin.php

@@ -93,6 +93,13 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
93 93
             Route::get('lst', '/lst')->name('configIdentityLst');
94 94
         })->prefix('admin.system.config.Identity');
95 95
 
96
+        //用户奖励配置
97
+        Route::group('config/award', function () {
98
+            Route::get('lst', '/lst')->name('configAwardLst');
99
+            Route::post('update/:key', '/update')->name('configAwardUpdate');
100
+            Route::get('update/table', '/updateTable')->name('configAwardUpdateForm');
101
+        })->prefix('admin.system.config.award');    
102
+
96 103
         Route::group('config/others', function () {
97 104
             Route::get('lst', 'ConfigOthers/lst')->name('configOthersSettingLst');
98 105
             Route::post('update', 'ConfigOthers/update')->name('configOthersSettingUpdate');

+ 2 - 0
route/api.php

@@ -298,6 +298,7 @@ Route::group('api/', function () {
298 298
 
299 299
             Route::get('green_integral_list', 'User/green_integral_list');//积分明细
300 300
             Route::get('team_list', 'User/team_list');//一壶茶-团队列表
301
+            Route::get('team_list_old', 'User/team_list_old');//一壶茶-团队列表
301 302
             Route::get('team_details', 'User/team_details');//一壶茶-团队详情
302 303
             Route::get('user_invite_profit_list', 'User/user_invite_profit_list');//一壶茶-团队详情
303 304
 
@@ -729,6 +730,7 @@ Route::group('api/', function () {
729 730
             Route::get('listindex', 'Merchant/listindex');
730 731
             Route::get('/product/lst/:id', 'Merchant/productList');
731 732
             Route::get('/product/type_lst', 'Merchant/productTypeList');//特殊-根据商户查询商品
733
+            Route::get('/product/commerce_list', 'Merchant/commerceProductList');//特殊-根据商户查询商品
732 734
             Route::get('/areaProduct/lst', 'Merchant/areaProductList');
733 735
             Route::get('/category/lst/:id', 'Merchant/categoryList');
734 736
             Route::get('/detail/:id', 'Merchant/detail');