Przeglądaj źródła

Merge branch 'dev' into dev-sxb

# Conflicts:
#	route/api.php
sunxbiao 1 rok temu
rodzic
commit
4b5374c5f3

+ 2 - 0
app/common/dao/user/UserDao.php

@@ -167,6 +167,8 @@ class UserDao extends BaseDao
167 167
             $query->where('userRich.stockholder' , $where['stockholder']);
168 168
         })->when( (isset($where['subIdentify']) && $where['subIdentify']!='') , function ($query) use ($where) {
169 169
             $query->where('areaManage.type' ,  $where['subIdentify']);
170
+        })->when(isset($where['uid']) , function ($query) use ($where) {
171
+            $query->whereIn('User.uid' ,  $where['uid']);
170 172
         });
171 173
         $company = input('company','');
172 174
         $identify = input('identify','');

+ 3 - 3
app/common/repositories/store/order/StoreRefundOrderRepository.php

@@ -1361,9 +1361,9 @@ class StoreRefundOrderRepository extends BaseRepository
1361 1361
         if(in_array($order['douhuomall_status'],[8,0,9])){
1362 1362
             return ['code'=>1];
1363 1363
         }
1364
-        if($order['supply_type'] == ''){
1365
-            return ['code'=>-1,'message'=>'这个订单暂时无法处理'];
1366
-        }
1364
+        // if($order['supply_type'] == ''){
1365
+        //     return ['code'=>-1,'message'=>'这个订单暂时无法处理'];
1366
+        // }
1367 1367
         //京东、云商特卖、云仓订单特殊处理
1368 1368
 //        if(in_array($order['supply_type'],[1,4,5])){
1369 1369
 //            return ['code'=>-1,'message'=>'这个订单需要提交客服处理'];

+ 12 - 0
app/common/repositories/user/UserRepository.php

@@ -451,6 +451,18 @@ class UserRepository extends BaseRepository
451 451
 
452 452
     public function getList(array $where, $page, $limit)
453 453
     {
454
+        if (!empty($where['zero_line_uid'])) {
455
+            $sql = "select getUserLevelId({$where['zero_line_uid']}) as uids";
456
+            //\think\facade\Log::info("lplpDB".$sql);
457
+            try {
458
+                $spread_user_list = Db::query($sql);
459
+            } catch (\Exception $exception) {
460
+                $spread_user_list = '';
461
+            }
462
+            $spread_user_list = explode(",", trim($spread_user_list[0]['uids'], '$,'));
463
+            $where['uid'] = $spread_user_list;
464
+        }
465
+        unset($where['zero_line_uid']);
454 466
         if(isset($where['user_card']) && $where['user_card'] !=''){
455 467
             $user_card = $where['user_card'];
456 468
             $query = $this->dao->search($where)->with(['spread' => function ($query) {

+ 138 - 1
app/controller/admin/user/User.php

@@ -100,7 +100,8 @@ class User extends BaseController
100 100
             'stockholder',
101 101
             'subIdentify',
102 102
             'user_group',
103
-            'is_show'
103
+            'is_show',
104
+            'zero_line_uid'
104 105
         ]);
105 106
 
106 107
         [$page, $limit] = $this->getPage();
@@ -1825,4 +1826,140 @@ class User extends BaseController
1825 1826
         Db::name('old_user_stock')->where('id',$id)->delete();
1826 1827
         return app('json')->success('删除成功');
1827 1828
     }
1829
+
1830
+    /**
1831
+     * 获取零号线用户列表
1832
+     * @return mixed
1833
+     * @throws DataNotFoundException
1834
+     * @throws DbException
1835
+     * @throws ModelNotFoundException
1836
+     */
1837
+    public function getZeroLineUserList()
1838
+    {
1839
+        $team_name = request()->param('team_name', null);
1840
+        $status = request()->param('status', null);
1841
+        $user_account = request()->param('account', null);
1842
+
1843
+        $query = Db::name('user_zero_line')
1844
+            ->alias('uzl')
1845
+            ->leftJoin('user u', 'u.uid = uzl.team_uid');
1846
+        if (!is_null($status)) {
1847
+            $query->where('uzl.status', '=', $status);
1848
+        }
1849
+
1850
+        if (!is_null($team_name)) {
1851
+            $query->whereLike('uzl.team_name', '%' . $team_name . '%');
1852
+        }
1853
+
1854
+        if (!is_null($user_account)) {
1855
+            $query
1856
+                ->whereLike('u.account', '%' . $user_account . '%');
1857
+        }
1858
+
1859
+        $result = $query
1860
+            ->field('uzl.*, u.account')
1861
+            ->select()
1862
+            ->toArray();
1863
+
1864
+        foreach ($result as &$team_data) {
1865
+            //查询当前团队的用户列表
1866
+            $sql = "select getUserLevelId({$team_data['team_uid']}) as uids";
1867
+            try {
1868
+                $spread_user_list = Db::query($sql);
1869
+            } catch (\Exception $exception) {
1870
+                $team_data['team_user_num'] = 0;
1871
+                continue;
1872
+            }
1873
+            $spread_user_list = explode(",", trim($spread_user_list[0]['uids'], '$,'));
1874
+            $team_data['team_user_num'] = count($spread_user_list);
1875
+        }
1876
+
1877
+
1878
+        return app('json')->success('获取成功', $result);
1879
+    }
1880
+
1881
+    /**
1882
+     * 获取零号线用户列表
1883
+     * @return mixed
1884
+     * @throws DataNotFoundException
1885
+     * @throws DbException
1886
+     * @throws ModelNotFoundException
1887
+     */
1888
+    public function setZeroLineUser()
1889
+    {
1890
+        $team_uid = request()->param('team_uid', 0);
1891
+        $team_name = request()->param('team_name', null);
1892
+        $status = request()->param('status', null);
1893
+
1894
+        $userData = Db::name('user')
1895
+            ->where('uid', '=', $team_uid)
1896
+            ->where('is_del', '=', 0)
1897
+            ->find();
1898
+        if (!$userData) {
1899
+            return app('json')->fail('用户不存在');
1900
+        }
1901
+
1902
+        if ($team_name === '') {
1903
+            $team_name = $userData['nickname'] . '0号线';
1904
+        }
1905
+
1906
+        $isExist = Db::name('user_zero_line')
1907
+            ->where('team_uid', '=', $team_uid)
1908
+            ->find();
1909
+
1910
+        Db::startTrans();
1911
+        try {
1912
+            Db::name('user')
1913
+                ->where('uid', '=', $team_uid)
1914
+                ->where('is_del', '=', 0)
1915
+                ->update(['level_id' => 0]);
1916
+            if ($isExist) {
1917
+                $result = Db::name('user_zero_line')
1918
+                    ->where('team_uid', '=', $team_uid)
1919
+                    ->update([
1920
+                        'team_name' => $team_name,
1921
+                        'status' => $status
1922
+                    ]);
1923
+            } else {
1924
+                $result = Db::name('user_zero_line')
1925
+                    ->insert([
1926
+                        'team_uid' => $team_uid,
1927
+                        'team_name' => $team_name,
1928
+                        'status' => $status
1929
+                    ]);
1930
+            }
1931
+            Db::commit();
1932
+        } catch (\Exception $exception) {
1933
+            Db::rollback();
1934
+            return app('json')->fail('设置失败');
1935
+        }
1936
+        if ($result) {
1937
+            return app('json')->success('设置成功', $result);
1938
+        }
1939
+        return app('json')->fail('设置失败');
1940
+    }
1941
+
1942
+    /**
1943
+     * @return mixed
1944
+     * @throws DataNotFoundException
1945
+     * @throws DbException
1946
+     * @throws ModelNotFoundException
1947
+     */
1948
+    public function getUserListByFuzzy()
1949
+    {
1950
+        $fuzzy = request()->param('fuzzy', null);
1951
+        if (is_null($fuzzy)) {
1952
+            return app('json')->success('查询成功', []);
1953
+        }
1954
+        $userData = Db::name('user')
1955
+            ->where('is_del', '=', 0)
1956
+            ->where(function ($query) use ($fuzzy) {
1957
+                $query->where('nickname', 'like', '%' . $fuzzy . '%')
1958
+                    ->whereOr('account', 'like', '%' . $fuzzy . '%');
1959
+            })
1960
+            ->field('uid, nickname, account')
1961
+            ->select()
1962
+            ->toArray();
1963
+        return app('json')->success('查询成功', $userData);
1964
+    }
1828 1965
 }

+ 16 - 1
app/controller/api/store/merchant/TaskPartnerProfits.php

@@ -128,6 +128,20 @@ class TaskPartnerProfits
128 128
             ->toArray();
129 129
         $removeUserIdList = array_column($removeUserList, 'uid');
130 130
 
131
+        $zeroLineUidList = [37];
132
+        foreach ($zeroLineUidList as $uid) {
133
+
134
+            //查询当前团队的用户列表
135
+            $sql = "select getUserLevelId($uid) as uids";
136
+            //\think\facade\Log::info("lplpDB".$sql);
137
+            try {
138
+                $spread_user_list = Db::query($sql);
139
+            } catch (\Exception $exception) {
140
+                return json($exception->getMessage());
141
+            }
142
+            $removeUserIdList = array_merge(explode(",", trim($spread_user_list[0]['uids'], '$,')), $removeUserIdList);
143
+        }
144
+
131 145
         if (empty($startTime) || empty($endTime)) {
132 146
             $timeMap = $this->getTime('last_week');
133 147
             $startTime = $timeMap['startTime'] . ' 00:00:00';
@@ -163,7 +177,7 @@ class TaskPartnerProfits
163 177
 
164 178
         // 3、获取 分红用户 信息 (`user_group` tinyint(1) DEFAULT '1' COMMENT '1消费者 2,推广业务员 3,业务经理 4初级合伙人5中级合伙人 6高级合伙人 7.懂事',)
165 179
         $list = Db::name("user")
166
-            //            ->whereNotIn('uid', $removeUserIdList)
180
+            ->whereNotIn('uid', $removeUserIdList)
167 181
             ->where("user_group", "IN", [4, 5, 6])
168 182
             ->where("status", "<>", 0)
169 183
             ->where('is_del', '<>', 1)
@@ -671,6 +685,7 @@ class TaskPartnerProfits
671 685
         }
672 686
         return $money1180Sum + $money11800Sum + $money10620Sum + $money9440Sum + $money2360Sum + (floor($otherMoneySum * 70) / 100);
673 687
     }
688
+
674 689
     // 获取用户PV值
675 690
     public function getPvNew($userIdList, $removeUserIdList = [])
676 691
     {

+ 688 - 0
app/controller/api/store/merchant/TaskZeroLineOrderLianc.php

@@ -0,0 +1,688 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ * @Author: Qinii
5
+ * @Date: 2020/5/28
6
+ */
7
+
8
+namespace app\controller\api\store\merchant;
9
+
10
+use think\facade\Db;
11
+use think\Request;
12
+
13
+class TaskZeroLineOrderLianc
14
+{
15
+
16
+    /**
17
+     * 会员升级
18
+     */
19
+    public function member_update($orderInfo, $goods_of_info, $user_id)
20
+    {
21
+        //
22
+        //$user_id = $userInfo['id'];
23
+        $order_id = $orderInfo['id'];
24
+
25
+        //code...
26
+        $pay_gb = round($orderInfo['num'] * $orderInfo['gb_num'], 2);
27
+        //$pay_vr =  round($orderInfo['num'] * $orderInfo['vr_num'],2);
28
+        //付款按照700的VR付款 start
29
+        $vr_num = 0;
30
+        if ($orderInfo['price'] == 1180) {
31
+            $vr_num = 700;
32
+        } elseif ($orderInfo['price'] == 11800) {
33
+            $vr_num = 7000;
34
+        } elseif ($orderInfo['price'] == 11800) {
35
+            $vr_num = 2100;
36
+        } elseif ($orderInfo['price'] == 10620) {
37
+            $vr_num = 6300;
38
+        }
39
+
40
+
41
+        $pay_gb1 = $vr_num;
42
+        $pay_vr1 = $orderInfo['price'];//记录VR值
43
+
44
+
45
+        // $result = Db::name("old_user_jbp")->where("id",$user_id)->dec("vr",$orderInfo['price'])->save();//1.0jbp旧表
46
+        // Db::name("user")->where("uid",$user_id)->dec("vr",$orderInfo['price'])->save();//2.0新表
47
+
48
+
49
+        $result = true;
50
+        if ($result) {
51
+            $invite_id = $goods_of_info['spread_id'];
52
+
53
+
54
+            $zs_ylj = 0; //养老金赋值
55
+
56
+
57
+            if ($goods_of_info['money'] == 1180) {
58
+                //修改订单到账状态
59
+                $zs_ylj = round(700 * 0.05, 2);//计算的养老金 金额
60
+            } elseif ($goods_of_info['money'] == 11800) {
61
+                $zs_ylj = round(7000 * 0.05, 2);//计算的养老金 金额
62
+            } elseif ($goods_of_info['money'] == 3540) {
63
+                $zs_ylj = round(2100 * 0.05, 2);//计算的养老金 金额
64
+            } elseif ($goods_of_info['money'] == 10620) {
65
+                $zs_ylj = round(6300 * 0.05, 2);//计算的养老金 金额
66
+            } elseif ($goods_of_info['money'] == 9440) {
67
+                $zs_ylj = round(5600 * 0.05, 2);//八单计算的养老金 金额
68
+            } elseif ($goods_of_info['money'] == 2360) {
69
+                $zs_ylj = round(1400 * 0.05, 2);//两单计算的养老金 金额
70
+            }
71
+
72
+
73
+            $uid = $user_id;
74
+            $new_user_id = $uid;
75
+            if (empty($new_user_id)) {
76
+                abort(0, "当前绑定会员查询错误");
77
+            }
78
+
79
+            $new_nums = Db::name("old_user_of_goods")->where("user_id", $uid)->sum("money");
80
+
81
+            //增加过后权益对比 获取当前权益等级
82
+            $old_level_id = Db::name("old_user_jbp")->where("id", $uid)->find();
83
+
84
+            $old_level_info = Db::name("old_user_level")->where("id", $old_level_id['user_level_id'])->find();
85
+
86
+
87
+            $level_info = [];
88
+            $level_list = Db::name("old_user_level")->order("money desc")->select();
89
+
90
+
91
+            //计算会员等级 升级
92
+            foreach ($level_list as $key => $value) {
93
+                # code...
94
+                if ($new_nums >= $value['money']) {
95
+                    $level_info = $value;
96
+                    break;
97
+                }
98
+            }
99
+
100
+            $zs_gb = $orderInfo['price'] * 3;
101
+            $zs_withdraw_quota = $orderInfo['price'];
102
+
103
+
104
+            if ($old_level_info['id'] == $level_info['id']) {
105
+                //未到达升级权益 不改变用户等级
106
+                $update_status = false;
107
+            } else {
108
+                $update_status = true;
109
+                $user_level = $level_info['id'];
110
+                //var_dump( $user_level);
111
+                Db::name("old_user_jbp")->where("id", $new_user_id)->save(['user_level_id' => $user_level]);//1.0jbp旧表
112
+                Db::name("user")->where("uid", $new_user_id)->save(['user_level_id_old' => $user_level]);//2.0新表
113
+
114
+                // todo 同时改变他的权益
115
+            }
116
+
117
+
118
+            // Db::name("old_user_jbp")->where("id",$new_user_id)->inc("withdraw_quota",$zs_withdraw_quota)->save();//1.0jbp旧表
119
+            // Db::name("user")->where("uid",$new_user_id)->save(['withdraw_quota_old'=>$zs_withdraw_quota]);//2.0新表
120
+
121
+            // 下发邀请人赠送的GB
122
+            // $zs_invite_gb = round($orderInfo['price']*0.3,2);
123
+            // //todo
124
+            // Db::name("old_user_jbp")->where("id",$invite_id)->inc("gb",$zs_invite_gb)->save();//1.0jbp旧表
125
+            // Db::name("user")->where("uid",$invite_id)->inc("score",$zs_invite_gb)->save();//2.0新表
126
+
127
+            //$old_have_pension = Db::name("old_user_jbp")->where("id",$invite_id)->value("have_pension");
128
+
129
+
130
+            //检查是不是订单价格是1180或者11800,更改VR
131
+            if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
132
+                //修改订单到账状态
133
+
134
+
135
+                Db::name("old_user_of_goods")->where("order_id", $goods_of_info1['id'])->save(['status' => 1, 'pay_gb' => 0, 'pay_vr' => $pay_vr1, 'pay_bt' => 0, 'create_time' => time()]);
136
+
137
+
138
+            }
139
+        }
140
+
141
+
142
+        if ($result) {
143
+            //更改订单状态
144
+
145
+            Db::commit();
146
+            $new_user_name = Db::name("old_user_jbp")->where("id", $new_user_id)->value("user_name");
147
+            $new_user_name = empty($new_user_name) ? "" : $new_user_name;
148
+
149
+            //记录日志信息
150
+
151
+            if ($user_id == $invite_id) {
152
+                //报单中心=推荐人 GB记录日志有问题需要传入指定参数去计算
153
+                //$money = Db::name("old_user_jbp")->where("id",$user_id)->value("gb");
154
+                //$appoint_money = $money - $zs_invite_gb;
155
+
156
+                if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
157
+
158
+
159
+                    $this->change_user_log66($user_id, "vr", 2, $pay_vr1, "declare_expend", '权益消费VR-' . $new_user_name);
160
+
161
+                }
162
+            } else {
163
+
164
+                if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
165
+
166
+
167
+                    $this->change_user_log66($user_id, "vr", 2, $pay_vr1, "declare_expend", '权益消费VR-' . $new_user_name);
168
+
169
+                }
170
+            }
171
+            // $this->change_user_log66($new_user_id,'gb',1,$zs_gb,"levle_update_zs","权益升级达标赠送");
172
+            $this->change_user_log66($new_user_id, 'withdraw_quota_old', 1, $zs_withdraw_quota, "levle_update_zs", "权益升级达标赠送");
173
+            // $this->change_user_log66($invite_id,'gb',1,$zs_invite_gb,"levle_update_zs","邀请-".$new_user_name);
174
+            // echo 123;return;
175
+            //处理查看是否有待发放佣金
176
+            // $zs_withdraw_quota
177
+            Db::name("old_user_jbp")->where("id", $new_user_id)->inc("total_withdraw_quota", $zs_withdraw_quota)->save();//1.0jbp旧表
178
+            Db::name("user")->where("uid", $new_user_id)->inc("total_withdraw_quota_old", $zs_withdraw_quota)->save();
179
+            // $this->releaseTobeAmount($new_user_id,$zs_withdraw_quota);
180
+            // $this->success("支付成功",['is_cash'=>0]);
181
+        }
182
+        Db::rollback();
183
+        // $this->error("操作失败");
184
+    }
185
+
186
+    function change_user_log66($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
187
+    {
188
+        $transition = [
189
+            'pv' => 1,
190
+            "gb" => 2,
191
+            "df" => 3,
192
+            "vr" => 4,
193
+            "bt" => 5,
194
+            "withdraw_quota_old" => 6,
195
+            "unsettled_pension" => 7,
196
+            "amount_old" => 8
197
+        ];
198
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
199
+        if (empty($routineInfo)) {
200
+            return false;
201
+        }
202
+        $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
203
+        //再去查询变更前的 金额
204
+        if ($appoint_money > 0) {
205
+            $alter_money = $appoint_money;
206
+        } else {
207
+            //再去查询变更前的 金额
208
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
209
+        }
210
+        if ($change_status == 1) {
211
+            //新增前
212
+            $alter_money = $alter_money - $money;
213
+        } else if ($change_status == 2) {
214
+            //减少前
215
+            $alter_money = $alter_money + $money;
216
+        }
217
+        $inser_data = [];
218
+        $inser_data['user_id'] = $user_id;
219
+        $inser_data['type'] = $transition[$type];
220
+        $inser_data['change_status'] = $change_status;
221
+        $inser_data['money'] = $money;
222
+        $inser_data['routine_log_of_key_id'] = $key_id;
223
+        $inser_data['remark'] = $remark;
224
+        $inser_data['is_admin'] = $is_admin;
225
+        $inser_data['create_time'] = time();
226
+        $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
227
+        Db::name("old_user_log")->insert($inser_data);
228
+    }
229
+
230
+    //添加推广佣金/养老金日志(养老金金额)
231
+    public function bill_user_log($uid, $name, $num, $mark)
232
+    {
233
+
234
+        $con_data = Db::name('user')->where("uid", $uid)->find();
235
+        //如果是会员专区就即刻到账
236
+
237
+        Db::name('user')->where("uid", $con_data['uid'])->update(['brokerage_price' => $con_data['brokerage_price'] + $num]);
238
+
239
+
240
+        $bill = [
241
+            'uid' => $uid,
242
+            'link_id' => 0,//关联订单id
243
+            'pm' => 1,//0:支出,1:获得
244
+            'title' => $name,//账单标题
245
+            'category' => 'now_money',//明细种类
246
+            'type' => 'commission',//明细类型
247
+            'number' => $num,//明细数字
248
+            'balance' => 0,//剩余
249
+            'mark' => $mark,//备注
250
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
251
+            'status' => 1,//0待确定,1有效,-1无效
252
+            'commission_type' => 8,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
253
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
254
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
255
+            'order_sn' => 0,//订单号
256
+            'tripartite' => 0,//
257
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
258
+            'mer_id' => 0,//商户id
259
+            'source' => 0,//1线下 0线上
260
+            'order_type' => 1,//1自营  2 第三方  订单类型
261
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
262
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
263
+            'take_time' => '',//结算时间
264
+            'district_id' => '',//
265
+            'street_id' => '',//
266
+            'month' => '',//月份
267
+
268
+
269
+        ];
270
+
271
+        Db::name('user_bill')->insert($bill);
272
+    }
273
+
274
+
275
+    public function lst2(Request $request)
276
+    {
277
+        $startTime = $request->param('startTime', null);
278
+        $endTime = $request->param('endTime', null);
279
+        $isTest = $request->param('isTest', 1);
280
+        $maxAllocationAmount = $request->param('maxAllocationAmount', null);
281
+        // 查询测试人员账号信息
282
+        //18973958920
283
+        //15186694339
284
+        //18833633835
285
+        //19525470098
286
+        //17756507016
287
+        //18226705337
288
+        $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337', '17855366921'];
289
+        $removeUserList = Db::name("user")
290
+            ->whereIn('account', $testAccount)
291
+            ->where("status", "<>", 0)
292
+            ->where('is_del', '<>', 1)
293
+            ->select()
294
+            ->toArray();
295
+        $removeUserIdList = array_column($removeUserList, 'uid');
296
+
297
+        if (empty($startTime) || empty($endTime)) {
298
+            $timeMap = $this->getTime('last_week');
299
+            $startTime = $timeMap['startTime'] . ' 00:00:00';
300
+            $endTime = $timeMap['endTime'] . ' 23:59:59';
301
+        }
302
+
303
+        $zeroLineUidList = [17];
304
+        $result = [];
305
+        foreach ($zeroLineUidList as $uid) {
306
+
307
+            //查询当前团队的用户列表
308
+            $sql = "select getUserLevelId($uid) as uids";
309
+            //\think\facade\Log::info("lplpDB".$sql);
310
+            try {
311
+                $spread_user_list = Db::query($sql);
312
+            } catch (\Exception $exception) {
313
+                $result[$uid] = $exception->getMessage();
314
+                continue;
315
+            }
316
+            $spread_user_list = array_diff(explode(",", trim($spread_user_list[0]['uids'], '$,')), $removeUserIdList);
317
+            if (empty($spread_user_list)) {
318
+                $result[$uid] = '无团队成员1';
319
+                continue;
320
+            }
321
+            // 定义分红金额
322
+            $performance = $this->getTeamPvByTime($startTime, $endTime, $spread_user_list);
323
+            // 分红金额 - 红包金额
324
+            // $redEnvelope = $this->getRedEnvelopeByTime($startTime, $endTime, $spread_user_list);
325
+            $redEnvelope = 0.00;
326
+            $weekRecord = bcsub($performance, $redEnvelope, 2);
327
+            if (!is_null($maxAllocationAmount)) {
328
+                $weekRecord = $maxAllocationAmount;
329
+            }
330
+
331
+            if ($weekRecord <= 0) {
332
+                $result[$uid] = '无效分红金额';
333
+                continue;
334
+            }
335
+
336
+            $originator_award = round(($weekRecord * 0.05), 2);
337
+
338
+
339
+            $lianc_list = Db::name("old_user_lianc")->order("id desc")->field("id,number,title")->select()->toArray();
340
+
341
+            $lianc_list_arr = array_column($lianc_list, null, 'id');
342
+
343
+            $list = Db::name("user")
344
+                ->whereIn('uid', $spread_user_list)
345
+                ->where("originator_id_old", ">", 0)
346
+                ->where("status", 1)
347
+                ->field("uid,originator_id_old")
348
+                ->select()
349
+                ->toArray();
350
+            $user_arr = [];
351
+            foreach ($list as $key => $value) {
352
+                # code...
353
+                $user_arr[$value['originator_id_old']]['people'][] = $value['uid'];
354
+                $user_arr[$value['originator_id_old']]['money'] = $lianc_list_arr[$value['originator_id_old']]['number'];
355
+                $user_arr[$value['originator_id_old']]['title'] = $lianc_list_arr[$value['originator_id_old']]['title'];
356
+                $user_arr[$value['originator_id_old']]['id'] = $lianc_list_arr[$value['originator_id_old']]['id'];
357
+            }
358
+
359
+            //处理计算权重 和平均分配的金额
360
+            $total_num = 0;
361
+            $count_num = 0;
362
+            foreach ($user_arr as $key => $value) {
363
+                $user_arr[$key]['people_count'] = count($user_arr[$key]['people']);
364
+                # code...
365
+                // floor(($weekRecord * ($value['profit_rate'] / 100)) * 100) / 100;
366
+                // $total_num += round($value['money'] * count($value['people']) / 1000, 2);
367
+                $total_num += floor(($value['money'] * count($value['people'])) * 100) / 100;
368
+
369
+                if (isset($user_arr[$key]['total_num'])) {
370
+                    $user_arr[$key]['total_num'] += floor(($value['money'] * count($value['people'])) * 100) / 100;
371
+                } else {
372
+                    $user_arr[$key]['total_num'] = 0;
373
+                }
374
+                $count_num += count($value['people']);
375
+            }
376
+            foreach ($user_arr as $key => $value) {
377
+                # code...
378
+                // $rate = round((count($value['people']) * $value['money']) / $total_num, 2) / 1000;
379
+                $rate = floor(($value['money'] * count($value['people']) / $total_num) * 100) / 100;
380
+                $user_arr[$key]['rate'] = $rate;
381
+                $distribution_money = floor($originator_award * $rate * 100) / 100;
382
+                $user_arr[$key]['distribution_money'] = $distribution_money;
383
+                // $user_arr[$key]['people_award'] = round($distribution_money / count($value['people']), 2);//可分配佣金
384
+                $user_arr[$key]['people_award'] = floor($distribution_money / count($value['people']) * 100) / 100;//可分配佣金
385
+            }
386
+
387
+            $count = 0;
388
+            foreach ($user_arr as $key => $value) {
389
+                $distribution_money = $value['distribution_money'];
390
+                # code...
391
+                foreach ($value['people'] as $k => $v) {
392
+                    # code...
393
+                    $award = $value['people_award'];
394
+                    //90给佣金,10给复购金
395
+                    $yj_90 = $award * 0.9;
396
+                    $fg_10 = $award * 0.1;
397
+                    if ($isTest == 0) {
398
+                        Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
399
+                        $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
400
+                        Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
401
+                        $res3 = Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
402
+
403
+                        $res = true;
404
+                        if ($res) {
405
+                            $$count = $count + 1;
406
+                            $this->change_user_log($v, 'amount_old', 1, $yj_90, "relation_profits", "联创分红入账" . "-" . $value['title']);
407
+                            //入账
408
+                            $week_data = [];
409
+                            $week_data['user_id'] = $v;
410
+                            $week_data['user_lianc_id'] = $value['id'];
411
+                            $week_data['money'] = $yj_90;
412
+                            $week_data['remark'] = "联创分红入账主动执行" . $yj_90;
413
+                            $week_data['all_record'] = $originator_award;
414
+                            $week_data['all_amount'] = $distribution_money;
415
+                            $week_data['create_time'] = time();
416
+                            Db::name("old_user_originator")->insert($week_data);
417
+
418
+                            $userdatassss = db::name("user")->where("uid", $v)->find();
419
+                            $datas_log = [
420
+                                'note' => "名称:" . $userdatassss['nickname'] . " 用户:" . $v . " 新增联创佣金:" . $yj_90,
421
+                                'create_time' => date('Y-m-d H:i:s')
422
+                            ];
423
+                            Db::name('test_log')->insert($datas_log);   //数据存到2.0数据表中
424
+                            $this->bill_user_log111111($v, "联创分佣", $yj_90, "联创明细入账", 12);//股权分佣明细2.0系统
425
+
426
+                            $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
427
+
428
+                        } else {
429
+                            // ..
430
+                        }
431
+                    }
432
+                }
433
+            }
434
+            $result[$uid] = $user_arr;
435
+        }
436
+        return json($result);
437
+    }
438
+
439
+    //添加复购金
440
+    public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
441
+    {
442
+
443
+        $fugou_data = Db::name('user')->where("uid", $uid)->find();
444
+
445
+
446
+        $bill = [
447
+            'uid' => $uid,
448
+            'number' => $num,//数量
449
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
450
+            'mark' => "复购金",//备注
451
+            'desc' => "10%作为复购金",//描述
452
+            'order_id' => $order_id,//订单id
453
+            'surplus' => 0,//剩余
454
+            'order_type' => 11,//关联订单ID
455
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
456
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
457
+            'addtime' => time(),
458
+        ];
459
+
460
+        Db::name('user_sign_fugou')->insert($bill);
461
+    }
462
+
463
+    //添加平台分佣2.0系统收益明细日志(养老金金额)
464
+    public function bill_user_log111111($uid, $name, $num, $mark, $comm)
465
+    {
466
+
467
+        $con_data = Db::name('user')->where("uid", $uid)->find();
468
+        //如果是会员专区就即刻到账
469
+
470
+        // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
471
+
472
+
473
+        $bill = [
474
+            'uid' => $uid,
475
+            'link_id' => 0,//关联订单id
476
+            'pm' => 1,//0:支出,1:获得
477
+            'title' => $name,//账单标题
478
+            'category' => 'now_money',//明细种类
479
+            'type' => 'commission',//明细类型
480
+            'number' => $num,//明细数字
481
+            'balance' => 0,//剩余
482
+            'mark' => $mark,//备注
483
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
484
+            'status' => 1,//0待确定,1有效,-1无效
485
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
486
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
487
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
488
+            'order_sn' => 0,//订单号
489
+            'tripartite' => 0,//
490
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
491
+            'mer_id' => 0,//商户id
492
+            'source' => 0,//1线下 0线上
493
+            'order_type' => 1,//1自营  2 第三方  订单类型
494
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
495
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
496
+            'take_time' => '',//结算时间
497
+            'district_id' => '',//
498
+            'street_id' => '',//
499
+            'month' => '',//月份
500
+
501
+
502
+        ];
503
+
504
+        Db::name('user_bill')->insert($bill);
505
+    }
506
+
507
+
508
+    //上周
509
+    public function getWeekStartEnd()
510
+    {
511
+        $now = time();
512
+        // 计算上周日 00:00 的时间戳
513
+        $last_sunday_start = strtotime('last Sunday', $now);
514
+        // 计算这周一 00:00 的时间戳
515
+        $this_monday_start = strtotime('this Monday', $last_sunday_start);
516
+        // 上周日 23:59:59 的时间戳,即这周一 00:00
517
+        $last_sunday_end = $this_monday_start - 1;
518
+        // 上周一 00:00 的时间戳,即上周日 24:00
519
+        $last_monday_start = $this_monday_start - 604800;
520
+
521
+        return [$last_monday_start, $last_sunday_end];
522
+    }
523
+
524
+
525
+    //本周
526
+    // public function getWeekStartEnd()
527
+    // {
528
+    //     $now = time();
529
+    //     // 计算本周一 00:00 的时间戳
530
+    //     $monday_start = strtotime('last Monday', $now);
531
+    //     if (date('w', $now) == 1) {
532
+    //         // 如果今天是周一,直接取今天的 00:00
533
+    //         $monday_start = strtotime('today', $now);
534
+    //     }
535
+    //     // 计算本周日 23:59:59 的时间戳
536
+    //     $sunday_end = strtotime('next Sunday', $now) + 86399;
537
+
538
+    //     return [$monday_start,$sunday_end];
539
+    // }
540
+
541
+
542
+    public function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
543
+    {
544
+        $transition = [
545
+            'pv' => 1,
546
+            "gb" => 2,
547
+            "df" => 3,
548
+            "vr" => 4,
549
+            "bt" => 5,
550
+            "withdraw_quota" => 6,
551
+            "unsettled_pension" => 7,
552
+            "amount_old" => 8
553
+        ];
554
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
555
+        if (empty($routineInfo)) {
556
+            return false;
557
+        }
558
+        $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
559
+
560
+        if ($appoint_money > 0) {
561
+            $alter_money = $appoint_money;
562
+        } else {
563
+            //再去查询变更前的 金额
564
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
565
+        }
566
+        if ($change_status == 1) {
567
+            //新增前
568
+            $alter_money = $alter_money - $money;
569
+        } else if ($change_status == 2) {
570
+            //减少前
571
+            $alter_money = $alter_money + $money;
572
+        }
573
+        if ($alter_money < 0) {
574
+            $alter_money = 0;
575
+        }
576
+        $inser_data = [];
577
+        $inser_data['user_id'] = $user_id;
578
+        $inser_data['type'] = $transition[$type];
579
+        $inser_data['change_status'] = $change_status;
580
+        $inser_data['money'] = $money;
581
+        $inser_data['routine_log_of_key_id'] = $key_id;
582
+        $inser_data['remark'] = $remark;
583
+        $inser_data['is_admin'] = $is_admin;
584
+        $inser_data['create_time'] = time();
585
+        $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
586
+        Db::name("old_user_log")->insert($inser_data);
587
+    }
588
+
589
+
590
+    /**
591
+     * 释放待发放佣金
592
+     */
593
+    public function releaseTobeAmount($user_id, $amount, $output)
594
+    {
595
+        $userInfo = Db::name("user")->find($user_id);
596
+        if (empty($userInfo)) {
597
+            return false;
598
+        }
599
+        $withdraw_quota = empty($userInfo['withdraw_quota_old']) ? 0 : $userInfo['withdraw_quota_old'];
600
+        $old_amount = empty($userInfo['tobe_amount_old']) ? 0 : $userInfo['tobe_amount_old'];
601
+        Db::name("user")->where("uid", $user_id)->save(['tobe_amount_old' => 0]);
602
+        $amount += $old_amount;
603
+        $inc_amount = 0;
604
+        $inc_tobe_amount = 0;
605
+        $dec_withdraw_quota = 0;
606
+
607
+        if (($amount - $withdraw_quota) > 0) {
608
+            $diff_money = $amount - $withdraw_quota;
609
+            $inc_amount = $withdraw_quota;
610
+            $dec_withdraw_quota = $withdraw_quota;
611
+            $inc_tobe_amount = $diff_money;
612
+        } elseif (($amount - $withdraw_quota) == 0) {
613
+            $inc_amount = $withdraw_quota;
614
+            $dec_withdraw_quota = $withdraw_quota;
615
+        } else {
616
+            // <0的情况
617
+            $diff_money = $withdraw_quota - $amount;
618
+            $inc_amount = $amount;
619
+            $dec_withdraw_quota = $amount;
620
+        }
621
+        if ($inc_tobe_amount != 0) {
622
+
623
+            $res = Db::name("user")->where("uid", $user_id)->inc("tobe_amount_old", $inc_tobe_amount)->fetchSql()->inc("amount", $inc_amount)->dec("withdraw_quota_old", $dec_withdraw_quota)->save();
624
+
625
+
626
+        } else {
627
+            $res = Db::name("user")->where("uid", $user_id)->inc("amount_old", $inc_amount)->fetchSql()->dec("withdraw_quota_old", $dec_withdraw_quota)->save();
628
+
629
+        }
630
+        //记录日志 提现额度消费
631
+        if ($dec_withdraw_quota > 0) {
632
+            $this->change_user_log($user_id, 'withdraw_quota', 2, $dec_withdraw_quota, "conversion_tobe_amount", "佣金额度兑换佣金");
633
+        }
634
+    }
635
+
636
+    public function getTime($timePeriod)
637
+    {
638
+        // 定义时间区间
639
+        $now = time();
640
+        $startTime = '';
641
+        $endTime = '';
642
+        if ($timePeriod == 'last_week') {
643
+            // 上周的时间区间
644
+            $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
645
+            $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
646
+        } elseif ($timePeriod == 'this_week') {
647
+            // 这周的时间区间
648
+            $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
649
+            $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
650
+        }
651
+        //        return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
652
+        return ['startTime' => $startTime, 'endTime' => $endTime];
653
+    }
654
+
655
+    public function getTeamPvByTime($startTime, $endTime, $userIdList = [])
656
+    {
657
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
658
+        // 0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上9话费10线下
659
+        $pvLogList = Db::name("user_pv_log")
660
+            ->whereIn('uid', $userIdList)
661
+            // ->whereIn('order_type', [0])
662
+            ->where('status', '=', 1)
663
+            ->whereBetween("settlement_time", [$startTime, $endTime])
664
+            ->whereNotNull("settlement_time") // 排除 pay_time 为 NULL 的订单
665
+            ->select()
666
+            ->toArray();
667
+
668
+        // 计算总业绩
669
+        $totalPv = 0;
670
+        foreach ($pvLogList as $pvLog) {
671
+            $totalPv = bcadd($totalPv, $pvLog['pv'], 2);
672
+        }
673
+
674
+        return $totalPv;
675
+    }
676
+
677
+    public function getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList = [])
678
+    {
679
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
680
+        $redEnvelopeList = Db::name("user_sign_hongbao")
681
+            ->whereNotIn('uid', $removeUserIdList)
682
+            ->where('status', 1)
683
+            ->whereBetween("settlement_time", [$startTime, $endTime])
684
+            ->select()
685
+            ->toArray();
686
+        return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
687
+    }
688
+}

+ 777 - 0
app/controller/api/store/merchant/TaskZeroLinePartnerProfits.php

@@ -0,0 +1,777 @@
1
+<?php
2
+
3
+
4
+namespace app\controller\api\store\merchant;
5
+
6
+
7
+use think\facade\Db;
8
+use think\Request;
9
+
10
+class TaskZeroLinePartnerProfits
11
+{
12
+    public function getTime($timePeriod)
13
+    {
14
+        // 定义时间区间
15
+        $now = time();
16
+        $startTime = '';
17
+        $endTime = '';
18
+        if ($timePeriod == 'last_week') {
19
+            // 上周的时间区间
20
+            $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
21
+            $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
22
+        } elseif ($timePeriod == 'this_week') {
23
+            // 这周的时间区间
24
+            $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
25
+            $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
26
+        }
27
+        //        return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
28
+        return ['startTime' => $startTime, 'endTime' => $endTime];
29
+    }
30
+
31
+    public function getTeamPvByTime($startTime, $endTime, $userIdList = [])
32
+    {
33
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
34
+        // 0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上9话费10线下
35
+        $pvLogList = Db::name("user_pv_log")
36
+            ->whereIn('uid', $userIdList)
37
+            // ->whereIn('order_type', [0])
38
+            ->where('status', '=', 1)
39
+            ->whereBetween("settlement_time", [$startTime, $endTime])
40
+            ->whereNotNull("settlement_time") // 排除 pay_time 为 NULL 的订单
41
+            ->select()
42
+            ->toArray();
43
+
44
+        // 计算总业绩
45
+        $totalPv = 0;
46
+        foreach ($pvLogList as $pvLog) {
47
+            $totalPv = bcadd($totalPv, $pvLog['pv'], 2);
48
+        }
49
+
50
+        return $totalPv;
51
+    }
52
+
53
+    public function getRedEnvelopeByTime($startTime, $endTime, $userIdList = [])
54
+    {
55
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
56
+        $redEnvelopeList = Db::name("user_sign_hongbao")
57
+            ->whereIn('uid', $userIdList)
58
+            ->where('status', 1)
59
+            ->whereBetween("settlement_time", [$startTime, $endTime])
60
+            ->select()
61
+            ->toArray();
62
+        return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
63
+    }
64
+
65
+    public function partnerProfitsByZeroLine(Request $request)
66
+    {
67
+
68
+        $startTime = $request->param('startTime', null);
69
+        $endTime = $request->param('endTime', null);
70
+        $isTest = $request->param('isTest', 1);
71
+        $maxAllocationAmount = $request->param('maxAllocationAmount', null);
72
+
73
+        // 查询测试人员账号信息
74
+        $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337', '17855366921'];
75
+        $removeUserList = Db::name("user")
76
+            ->whereIn('account', $testAccount)
77
+            ->where("status", "<>", 0)
78
+            ->where('is_del', '<>', 1)
79
+            ->select()
80
+            ->toArray();
81
+        $removeUserIdList = array_column($removeUserList, 'uid');
82
+
83
+        if (empty($startTime) || empty($endTime)) {
84
+            $timeMap = $this->getTime('last_week');
85
+            $startTime = $timeMap['startTime'] . ' 00:00:00';
86
+            $endTime = $timeMap['endTime'] . ' 23:59:59';
87
+        }
88
+
89
+        $zeroLineUidList = [32];
90
+        $result = [];
91
+        foreach ($zeroLineUidList as $uid) {
92
+
93
+            //查询当前团队的用户列表
94
+            $sql = "select getUserLevelId($uid) as uids";
95
+            //\think\facade\Log::info("lplpDB".$sql);
96
+            try {
97
+                $spread_user_list = Db::query($sql);
98
+            } catch (\Exception $exception) {
99
+                $result[$uid] = $exception->getMessage();
100
+                continue;
101
+            }
102
+            $spread_user_list = array_diff(explode(",", trim($spread_user_list[0]['uids'], '$,')), $removeUserIdList);
103
+            if (empty($spread_user_list)) {
104
+                $result[$uid] = '无团队成员1';
105
+                continue;
106
+            }
107
+
108
+            // 定义分红金额
109
+            $performance = $this->getTeamPvByTime($startTime, $endTime, $spread_user_list);
110
+            // 分红金额 - 红包金额
111
+            // $redEnvelope = $this->getRedEnvelopeByTime($startTime, $endTime, $spread_user_list);
112
+            $redEnvelope = 0.00;
113
+            $weekRecord = bcsub($performance, $redEnvelope, 2);
114
+            if (!is_null($maxAllocationAmount)) {
115
+                $weekRecord = $maxAllocationAmount;
116
+            }
117
+
118
+            if ($weekRecord <= 0) {
119
+                $result[$uid] = '无效分红金额';
120
+                continue;
121
+                // return json('无效分红金额');
122
+            }
123
+
124
+            // 1、获取用户星级信息
125
+            //$star_list = Db::name("user_star")->order("statement_all_num desc")->select()->toArray();//旧星级等级
126
+            $starList = Db::name("old_user_starlevel")
127
+                ->whereIn('title', ['初级', '中级', '高级'])
128
+                ->order("statement_all_num desc")
129
+                ->select()
130
+                ->toArray();//星级等级
131
+
132
+            // 2、循环星级信息 并分组归类
133
+            $salesArr = array_column($starList, null, 'title');
134
+
135
+            // 3、获取 分红用户 信息 (`user_group` tinyint(1) DEFAULT '1' COMMENT '1消费者 2,推广业务员 3,业务经理 4初级合伙人5中级合伙人 6高级合伙人 7.懂事',)
136
+            $list = Db::name("user")
137
+                ->whereIn('uid', $spread_user_list)
138
+                ->where("user_group", "IN", [4, 5, 6])
139
+                ->where("status", "<>", 0)
140
+                ->where('is_del', '<>', 1)
141
+                ->select()
142
+                ->toArray();
143
+
144
+            if (empty($list)) {
145
+                $result[$uid] = '无有效分红人员';
146
+                continue;
147
+            }
148
+
149
+            // 4、将用户装载到 星级等级 分红数据中
150
+            $salesArr['初级']['user_group'] = 4;
151
+            $salesArr['初级']['divider_people']= [] ;
152
+            $salesArr['中级']['user_group'] = 5;
153
+            $salesArr['中级']['divider_people'] = [];
154
+            $salesArr['高级']['user_group'] = 6;
155
+            $salesArr['高级']['divider_people'] = [];
156
+
157
+            foreach ($list as $key => $value) {
158
+                if ($value['user_group'] == 4) {
159
+                    $salesArr['初级']['user_group'] = $value['user_group'];
160
+                    $salesArr['初级']['divider_people'][] = $value['uid'];
161
+                } else if ($value['user_group'] == 5) {
162
+                    $salesArr['中级']['user_group'] = $value['user_group'];
163
+                    $salesArr['中级']['divider_people'][] = $value['uid'];
164
+                } else if ($value['user_group'] == 6) {
165
+                    $salesArr['高级']['user_group'] = $value['user_group'];
166
+                    $salesArr['高级']['divider_people'][] = $value['uid'];
167
+                }
168
+            }
169
+            $salesArr['初级']['divider_people_count'] = count($salesArr['初级']['divider_people']);
170
+            $salesArr['中级']['divider_people_count'] = count($salesArr['中级']['divider_people']);
171
+            $salesArr['高级']['divider_people_count'] = count($salesArr['高级']['divider_people']);
172
+
173
+            if (!empty($salesArr['高级']['divider_people']) && in_array($uid, $salesArr['高级']['divider_people'])) {
174
+                $result[$uid] = '已有高级合伙人';
175
+                continue;
176
+            }
177
+
178
+            // 5、移除特定人员
179
+
180
+            // 6、执行分开发放
181
+            $partnerProfitsPvListByUid = [];
182
+            foreach ($salesArr as $key => $value) {
183
+                // 6.1 计算可分红金额
184
+                //比如这个周的总业绩是 8400
185
+                //周总业绩(8400) * 合伙人级别的分佣比例(15%) = 可分红的佣金(1260)
186
+                //            $salesArr[$key]['fs_money_nums'] = round($weekRecord * $value['profit_rate'], 2);
187
+                $salesArr[$key]['fs_money_nums'] = floor(($weekRecord * ($value['profit_rate'] / 100)) * 100) / 100;
188
+                //可分红的业绩(分为两半,各50%,一部分是分给双联盟比例,一部分是小业绩比例)
189
+                //把本周的业绩(8400) * 合伙人级别的分佣比例(15%) * 0.5 = 630(可分红佣金的 50%)
190
+                //            $salesArr[$key]['fs_money'] = round($salesArr[$key]['fs_money_nums'] / 2, 2);
191
+                $salesArr[$key]['fs_money'] = floor(($salesArr[$key]['fs_money_nums'] / 2) * 100) / 100;
192
+
193
+                // 6.2 计算所有人的 PV值
194
+                $salesArr[$key]['weekRecord'] = $weekRecord;
195
+                $salesArr[$key]['redEnvelope'] = $redEnvelope;
196
+                $salesArr[$key]['maxValueAll'] = 0;
197
+                $salesArr[$key]['sumOfOthersAll'] = 0;
198
+                $salesArr[$key]['dividerPeoplePv'] = [];
199
+                foreach ($value['divider_people'] as $k => $v) {
200
+                    // 6.2.1 查出分红人的所有部门 即 下级用户
201
+                    $spreadUserUidList = $this->getSpreadUserUidListByUidList([$v]);
202
+                    if (empty($spreadUserUidList[$v])) {
203
+                        continue;
204
+                    }
205
+
206
+                    // 6.2.2 获取当前分红人的所有部门 内的下级成员,递归获取至最低一级
207
+                    $subordinatesBatch = $this->getSubordinatesBatch($spreadUserUidList[$v]);
208
+                    // 6.2.3 获取所有部门(下线)的PV值
209
+                    foreach ($subordinatesBatch as $k1 => $v1) {
210
+                        $partnerProfitsPvListByUid[$v][$k1] = 0;
211
+                        // 获取当前下线的PV值, 忽略测试人员的账号
212
+                        // $pv = $this->getPv(array_merge($v1, [$k1]), $removeUserIdList);
213
+                        // $partnerProfitsPvListByUid[$v][$k1] += $pv;
214
+                        $pvNew = $this->getPvNew(array_merge($v1, [$k1]), $removeUserIdList);
215
+                        $partnerProfitsPvListByUid[$v][$k1] += $pvNew;
216
+                    }
217
+
218
+                    // 6.2.4 将PV值进行记录 以便后续计算
219
+                    if (!empty($partnerProfitsPvListByUid[$v])) {
220
+                        // 获取数组中的最大值
221
+                        $maxValue = max($partnerProfitsPvListByUid[$v]);
222
+                        // 计算总和
223
+                        $totalSum = array_sum($partnerProfitsPvListByUid[$v]);
224
+                        // 计算除最大值外其余值的和
225
+                        $sumOfOthers = $totalSum - $maxValue;
226
+
227
+                        $salesArr[$key]['dividerPeoplePv'][$v]['maxValue'] = $maxValue;
228
+                        $salesArr[$key]['dividerPeoplePv'][$v]['sumOfOthers'] = $sumOfOthers;
229
+                        $salesArr[$key]['maxValueAll'] += $maxValue;
230
+                        $salesArr[$key]['sumOfOthersAll'] += $sumOfOthers;
231
+                    }
232
+                }
233
+            }
234
+
235
+            // 7、执行分红
236
+            $testRecord = [];
237
+            foreach ($salesArr as $key => $value) {
238
+                $amount = $value['fs_money'];//可分红的总佣金,分红佣金的一半,中级合伙61.95
239
+                $fsMoneyNums = $value['fs_money_nums'];//中级合伙人级别,可分红的总佣金
240
+                $maxValueAll = $value['maxValueAll'];//当前级别合伙人下面所有的双联盟业绩
241
+                $sumOfOthersAll = $value['sumOfOthersAll'];//当前级别合伙人下面所有的小区(业绩小的部分)总业绩
242
+
243
+                if (count($value['divider_people']) <= 0) {
244
+                    continue;
245
+                }
246
+                //每人分红金额
247
+                foreach ($value['divider_people'] as $v) {
248
+
249
+                    //个人小区(佣金少的一部分) 权重 计算权重
250
+                    //返回是数组,下标0是最小的值(业绩小的),下标1是最大的值(业绩大的)
251
+                    $userPvSmallNum = $value['dividerPeoplePv'][$v]['sumOfOthers'] ?? 0;
252
+                    //                $myMixMoney = round($amount * ($userPvSmallNum / $sumOfOthersAll), 2);
253
+                    $myMixMoney = floor(($amount * (floor(($userPvSmallNum / $sumOfOthersAll) * 100000) / 100000)) * 100) / 100;
254
+
255
+                    //个人双区总佣金 权重 计算
256
+                    $myBill = $value['dividerPeoplePv'][$v]['maxValue'] ?? 0;
257
+                    //中级合伙人。userid=17可以分到双区可分红的金额
258
+                    //可分红的佣金 * (中级合伙人个人的双区总业绩 / 当前等级所有合伙人的双联盟业绩) = 当前用户可以获取到的分红佣金(双区联盟总业绩加权佣金),287742 * (61.95/431032)=41.36
259
+                    //                $myWeightMoney = round($amount * ($myBill / $maxValueAll), 2);
260
+                    $myWeightMoney = floor(($amount * (floor((($myBill + $userPvSmallNum) / ($maxValueAll + $sumOfOthersAll)) * 100000) / 100000)) * 100) / 100;
261
+
262
+
263
+                    $salesArr[$key]['dividerPeoplePv'][$v]['myWeightMoney'] = $myWeightMoney;
264
+                    $salesArr[$key]['dividerPeoplePv'][$v]['myMixMoney'] = $myMixMoney;
265
+                    $salesArr[$key]['dividerPeoplePv'][$v]['maxValueAll'] = $maxValueAll;
266
+                    $salesArr[$key]['dividerPeoplePv'][$v]['sumOfOthersAll'] = $sumOfOthersAll;
267
+
268
+                    # code...
269
+                    $allAward = $myWeightMoney + $myMixMoney;
270
+
271
+                    //90%给佣金,10给复购金
272
+                    $yj_90 = floor($allAward * 0.9 * 100) / 100;
273
+                    $fg_10 = floor($allAward * 0.1 * 100) / 100;
274
+
275
+                    //                $yj_90 = bcsub($yj_90, $user_bill_uid_list[$v]['number'] ?? 0.00, 2);
276
+                    //
277
+                    //                $fg_10 = bcsub($fg_10, $user_sign_fugou_uid_list[$v]['number'] ?? 0.00, 2);
278
+                    //
279
+                    //                if ($yj_90 < 0) {
280
+                    //                    $testRecord['yj_fushu'][] = ['uid' => $v, 'num' => floor($allAward * 0.9 * 100) / 100, 'exist' => $user_bill_uid_list[$v]['number'] ?? 0.00, 'yj' => $yj_90];
281
+                    //                }
282
+                    //                if ($fg_10 < 0) {
283
+                    //                    $testRecord['fg_fushu'][] = ['uid' => $v, 'num' => floor($allAward * 0.1 * 100) / 100, 'exist' => $user_sign_fugou_uid_list[$v]['number'] ?? 0.00, 'fg' => $fg_10];
284
+                    //                }
285
+
286
+                    if ($isTest == 0) {
287
+                        $userdatassss = db::name("old_user_jbp")->where("id", $v)->find();
288
+                        $datas_log = [
289
+                            'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v . " 双联盟总业绩:" . $maxValueAll . " 我的双区业绩:" . $myBill . " 小区总业绩:" . $userPvSmallNum . " 我的业绩小的:" . $myMixMoney . "  可分红佣金:" . $amount . "  可分红总佣金:" . $fsMoneyNums . "  小区业绩可分红:" . $myMixMoney . " 双区业绩可分红:" . $myWeightMoney . " 实际分得:" . $yj_90,
290
+                            'create_time' => date('Y-m-d H:i:s')
291
+                        ];
292
+                        $con_data = Db::name('test_log')->insert($datas_log);   //数据存到2.0数据表中
293
+
294
+                        # code...
295
+                        $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
296
+
297
+                        Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
298
+                        Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
299
+
300
+                        Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
301
+
302
+
303
+                        //if($res) {
304
+                        $this->change_user_log($v, 'amount_old', 1, $yj_90, "member_award", "星级分红入账" . "-" . $value['title']);//释放佣金
305
+                        // //入账星级分红记录表
306
+                        // $week_data = [];
307
+                        // $week_data['user_id'] = $v;
308
+                        // $week_data['user_star_id'] = $value['id'];
309
+                        // $week_data['award_num'] = $myWeightMoney;
310
+                        // $week_data['award_num_sm'] = $myMixMoney;
311
+                        // $week_data['remark'] = "星级分红主动执行:" . $yj_90;
312
+                        // $week_data['week_record'] = $weekRecord;
313
+                        // $week_data['all_amount'] = $fsMoneyNums;
314
+                        // $week_data['radio'] = 2;
315
+                        // $week_data['owner_bill'] = $maxValueAll;  //总流水金额
316
+                        // $week_data['my_bill'] = $myBill;  //我的流水
317
+                        // $week_data['create_time'] = time();
318
+                        // Db::name("old_user_weekaward")->insert($week_data);
319
+
320
+                        // 入账记录
321
+                        $week_data = [];
322
+                        $week_data['user_id'] = $v;
323
+                        $week_data['user_group'] = $value['user_group'];
324
+                        $week_data['start_time'] = $startTime;
325
+                        $week_data['end_time'] = $endTime;
326
+                        $week_data['performance'] = $performance;
327
+                        $week_data['red_envelope'] = $redEnvelope;
328
+                        $week_data['reality_performance'] = $weekRecord;
329
+                        $week_data['dividend_ratio'] = $value['profit_rate'];
330
+                        $week_data['dividend'] = $fsMoneyNums;
331
+                        $week_data['performance_part'] = $userPvSmallNum;
332
+                        $week_data['performance_part_all'] = $sumOfOthersAll;
333
+                        $week_data['part_money'] = $myMixMoney;
334
+                        $week_data['performance_total'] = ($myBill + $userPvSmallNum);
335
+                        $week_data['performance_total_all'] = ($maxValueAll + $sumOfOthersAll);
336
+                        $week_data['total_money'] = $myWeightMoney;
337
+                        $week_data['brokerage'] = $yj_90;
338
+                        $week_data['fugou'] = $fg_10;
339
+                        $week_data['radio'] = 2;
340
+                        $week_data['create_time'] = date('Y-m-d H:i:s');
341
+                        Db::name("partner_profit_records")->insert($week_data);
342
+
343
+                        $this->bill_user_log111111($v, "合伙人分佣", $yj_90, "合伙人分佣明细入账", 11);//联创分佣明细2.0系统
344
+                        $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
345
+                    }
346
+                }
347
+                $salesArr['cs'] = $testRecord;
348
+            }
349
+            $result[$uid] = $salesArr;
350
+
351
+        }
352
+        return json($result);
353
+    }
354
+
355
+    /**
356
+     * 获取该会员的所有下级会员
357
+     */
358
+    public function getSpreadUserUidListByUidList(array $uidList)
359
+    {
360
+        $son_ids = Db::name("user")
361
+            ->whereIn("level_id", $uidList)
362
+            ->field("uid,level_id")
363
+            ->select()
364
+            ->toArray();
365
+        $new_array_ids = [];
366
+        foreach ($son_ids as $key => $value) {
367
+            $new_array_ids[$value['level_id']][] = $value['uid'];
368
+        }
369
+        return $new_array_ids;
370
+    }
371
+
372
+    /**
373
+     * 递归查询下级用户并分组
374
+     *
375
+     * @param array $uids 初始用户ID数组
376
+     * @return array 分组后的下级用户ID数组
377
+     */
378
+    public function getSubordinates(array $uids): array
379
+    {
380
+        $result = [];
381
+
382
+        foreach ($uids as $uid) {
383
+            $result[$uid] = $this->getSubordinatesRecursively($uid);
384
+        }
385
+
386
+        return $result;
387
+    }
388
+
389
+    /**
390
+     * 获取该会员的所有下级会员
391
+     */
392
+    public function getSpreadUserUidAccountListByUidList($uid, $account = '')
393
+    {
394
+        $son_ids = Db::name("user")
395
+            ->where("level_id", $uid)
396
+            ->field("uid,level_id,account")
397
+            ->select()
398
+            ->toArray();
399
+        $new_array_ids = [];
400
+        foreach ($son_ids as $key => $value) {
401
+            $childList = $this->getSpreadUserUidAccountListByUidList($value['uid'], $value['account']);
402
+            $new_array_ids[] = [
403
+                '当前用户ID' => $value['uid'],
404
+                '当前用户的上级用户ID' => $value['level_id'],
405
+                '用户账号(手机号)' => $value['account'],
406
+                '当前用户的下级用户列表' => $childList
407
+            ];
408
+        }
409
+        return $new_array_ids;
410
+    }
411
+
412
+    /**
413
+     * 递归查询单个用户的下级用户
414
+     *
415
+     * @param int $uid 用户ID
416
+     * @param array $subordinates 用于存储下级用户ID的数组(内部使用, 递归传递)
417
+     * @return array 下级用户ID数组
418
+     */
419
+    private function getSubordinatesRecursively(int $uid, array &$subordinates = []): array
420
+    {
421
+        $subUidList = Db::name("user")
422
+            ->where("level_id", $uid)  // 直接使用 $uid, 不需要 whereIn
423
+            ->field("uid") //只需要查询uid
424
+            ->select()
425
+            ->toArray();
426
+
427
+        if (!empty($subUidList)) {
428
+            foreach ($subUidList as $subUser) {
429
+                $subUid = $subUser['uid'];
430
+                $subordinates[] = $subUid; // 添加到下级用户数组
431
+                $this->getSubordinatesRecursively($subUid, $subordinates); // 递归查询下级的下级
432
+            }
433
+        }
434
+        return $subordinates;
435
+    }
436
+
437
+    /**
438
+     * 递归获取所有下级ID(不分组)
439
+     * @param int $uid
440
+     * @param array $allSubordinates
441
+     * @return array
442
+     */
443
+    public function getAllSubordinates(int $uid, array &$allSubordinates = []): array
444
+    {
445
+        $subUidList = Db::name("user")
446
+            ->where("level_id", $uid)
447
+            ->column("uid");  // 使用 column 方法直接获取 uid 数组
448
+
449
+        if (!empty($subUidList)) {
450
+            foreach ($subUidList as $subUid) {
451
+                $allSubordinates[] = $subUid;
452
+                $this->getAllSubordinates($subUid, $allSubordinates);
453
+            }
454
+        }
455
+
456
+        return $allSubordinates;
457
+    }
458
+
459
+    /**
460
+     *  更高效的获取所有下级 (使用循环代替递归, 避免栈溢出)
461
+     * @param array $uids
462
+     * @return array
463
+     */
464
+    public function getAllSubordinatesIterative(array $uids): array
465
+    {
466
+        $result = [];
467
+
468
+        foreach ($uids as $uid) {
469
+            $result[$uid] = [];
470
+            $queue = [$uid];  // 使用队列来存储待处理的 UID
471
+            $processed = []; // 记录已经处理过的
472
+
473
+            while (!empty($queue)) {
474
+                $currentUid = array_shift($queue); // 从队列头部取出 UID
475
+                if (in_array($currentUid, $processed)) {
476
+                    continue; // 已经处理过
477
+                }
478
+                $processed[] = $currentUid;
479
+                $subUidList = Db::name("user")
480
+                    ->where("level_id", $currentUid)
481
+                    ->column("uid");
482
+
483
+                if (!empty($subUidList)) {
484
+                    $result[$uid] = array_merge($result[$uid], $subUidList); //合并
485
+                    $queue = array_merge($queue, $subUidList);  // 将新找到的下级 UID 加入队列尾部
486
+                }
487
+            }
488
+            $result[$uid] = array_unique($result[$uid]);//去重
489
+        }
490
+        return $result;
491
+    }
492
+
493
+    /**
494
+     * 获取多个用户的所有下级,  返回分组后的数组.  (更高效, 使用循环, 减少数据库查询次数)
495
+     * @param array $uids
496
+     * @return array 形如 ['A1' => [A11, A12, ...], 'A2' => [...]]
497
+     */
498
+    public function getSubordinatesBatch(array $uids): array
499
+    {
500
+        $result = [];
501
+        $allSubordinates = [];
502
+        $queue = $uids;
503
+        $processed = [];
504
+        //1. 找出所有的下级ID (不去重)
505
+        while (!empty($queue)) {
506
+            $currentUids = array_splice($queue, 0, 500); // 一次最多处理500个,防止in太多.  可以根据实际情况调整.
507
+            $currentUids = array_diff($currentUids, $processed); //去除已经查询过的
508
+            if (empty($currentUids)) continue;  //没有新的需要处理的
509
+            $processed = array_merge($processed, $currentUids);//记录
510
+            $subUidList = Db::name("user")
511
+                ->whereIn("level_id", $currentUids)
512
+                ->field("uid,level_id") // 需要查询 level_id 用于后续分组
513
+                ->select()
514
+                ->toArray();
515
+
516
+            if (!empty($subUidList)) {
517
+                $allSubordinates = array_merge($allSubordinates, $subUidList); //所有下级
518
+                $nextLevelUids = array_column($subUidList, 'uid');
519
+                $queue = array_merge($queue, $nextLevelUids);  //放到队列中
520
+            }
521
+        }
522
+        //2. 分组
523
+        foreach ($uids as $uid) {
524
+            $result[$uid] = []; // 初始化每个用户的下级数组
525
+        }
526
+        $allSubordinatesMap = [];
527
+        foreach ($allSubordinates as $item) {
528
+            $allSubordinatesMap[$item['level_id']][] = $item['uid'];
529
+        }
530
+
531
+        //3. 递归的将查到的下级进行分组
532
+        $group = function ($spreadUid) use (&$group, &$allSubordinatesMap, &$result) {
533
+            if (isset($allSubordinatesMap[$spreadUid])) {
534
+                foreach ($allSubordinatesMap[$spreadUid] as $subUid) {
535
+                    if (isset($result[$spreadUid])) {
536
+                        $result[$spreadUid][] = $subUid; //直接添加到结果中
537
+                    } else { //不属于直接上级, 查找上级的上级
538
+                        foreach ($result as $rootUid => &$subordinates) {
539
+                            if (in_array($spreadUid, $subordinates) || $rootUid == $spreadUid) {
540
+                                $subordinates[] = $subUid;
541
+                                break;
542
+                            }
543
+                        }
544
+                    }
545
+                    $group($subUid); //递归下一层
546
+                }
547
+            }
548
+        };
549
+        foreach ($uids as $uid) {
550
+            $group($uid);
551
+        }
552
+
553
+        // 4. 去重 (如果需要)
554
+        foreach ($result as $key => $value) {
555
+            $result[$key] = array_values(array_unique($value));
556
+        }
557
+        return $result;
558
+    }
559
+
560
+    // 获取用户PV值
561
+    public function getPv($userIdList, $removeUserIdList = [])
562
+    {
563
+        if (!empty($removeUserIdList)) {
564
+            $userIdList = array_values(array_diff($userIdList, $removeUserIdList));
565
+        }
566
+        // 基础查询构建器
567
+        $user_team_amount = Db::name("old_user_of_goods")
568
+            ->whereIn("user_id", $userIdList)
569
+            ->where('status', 1)
570
+            ->where('money', 1180)
571
+            ->select();
572
+        //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
573
+        // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
574
+        $money1180Sum = 0;
575
+        foreach ($user_team_amount as $record) {
576
+            $money1180Sum += $record['money'] - 300 - 180;
577
+        }
578
+
579
+        // 获取 status 为 1 且 money 为 11800 的记录集合
580
+        $money11800Records = Db::name("old_user_of_goods")
581
+            ->whereIn("user_id", $userIdList)
582
+            ->where('status', 1)
583
+            ->where('money', 11800)
584
+            ->select();
585
+        // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
586
+        $money11800Sum = 0;
587
+        foreach ($money11800Records as $record) {
588
+            $money11800Sum += $record['money'] - 3000 - 1800;
589
+        }
590
+
591
+        $money10620Records = Db::name("old_user_of_goods")
592
+            ->whereIn("user_id", $userIdList)
593
+            ->where('status', 1)
594
+            ->where('money', 10620)
595
+            ->select();
596
+        // 计算 status 为 1 且 money 为 10620 的记录总和(减去相应值后)
597
+        $money10620Sum = 0;
598
+        foreach ($money10620Records as $record) {
599
+            $money10620Sum += $record['money'] - 2700 - 1620;
600
+        }
601
+
602
+
603
+        $money9440Records = Db::name("old_user_of_goods")
604
+            ->whereIn("user_id", $userIdList)
605
+            ->where('status', 1)
606
+            ->where('money', 9440)
607
+            ->select();
608
+        // 计算 status 为 1 且 money 为 9440 的记录总和(减去相应值后)
609
+        $money9440Sum = 0;
610
+        foreach ($money9440Records as $record) {
611
+            $money9440Sum += $record['money'] - 2400 - 1440;
612
+        }
613
+
614
+        $money2360Records = Db::name("old_user_of_goods")
615
+            ->whereIn("user_id", $userIdList)
616
+            ->where('status', 1)
617
+            ->where('money', 2360)
618
+            ->select();
619
+        // 计算 status 为 1 且 money 为 2360 的记录总和(减去相应值后)
620
+        $money2360Sum = 0;
621
+        foreach ($money2360Records as $record) {
622
+            $money2360Sum += $record['money'] - 600 - 360;
623
+        }
624
+
625
+        // 计算除去特定值后的总和
626
+        $otherMoneyRecords = [];
627
+        //        $otherMoneyRecords = Db::name("old_user_of_goods")
628
+        //            ->whereIn("user_id", $userIdList)
629
+        //            ->whereNotIn('money', [1180, 11800, 10620, 9440, 2360])
630
+        //            ->select();
631
+        $otherMoneySum = 0;
632
+        foreach ($otherMoneyRecords as $record) {
633
+            $otherMoneySum += $record['money'];
634
+        }
635
+        return $money1180Sum + $money11800Sum + $money10620Sum + $money9440Sum + $money2360Sum + (floor($otherMoneySum * 70) / 100);
636
+    }
637
+
638
+    // 获取用户PV值
639
+    public function getPvNew($userIdList, $removeUserIdList = [])
640
+    {
641
+        if (!empty($removeUserIdList)) {
642
+            $userIdList = array_values(array_diff($userIdList, $removeUserIdList));
643
+        }
644
+        $pvLogList = Db::name("user_pv_log")
645
+            ->whereIn('uid', $userIdList)
646
+            // ->whereIn('order_type', [0])
647
+            ->where('status', '=', 1)
648
+            // ->whereBetween("settlement_time", [$startTime, $endTime])
649
+            // ->whereNotNull("settlement_time") // 排除 pay_time 为 NULL 的订单
650
+            ->select()
651
+            ->toArray();
652
+
653
+        // 计算总业绩
654
+        $totalPv = 0;
655
+        foreach ($pvLogList as $pvLog) {
656
+            $totalPv = bcadd($totalPv, $pvLog['pv'], 2);
657
+        }
658
+
659
+        return $totalPv;
660
+    }
661
+
662
+    //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金
663
+    function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
664
+    {
665
+        $transition = [
666
+            'pv' => 1,
667
+            "gb" => 2,
668
+            "df" => 3,
669
+            "vr" => 4,
670
+            "bt" => 5,
671
+            "withdraw_quota_old" => 6,//提现
672
+            "unsettled_pension" => 7,
673
+            "amount_old" => 8//发放佣金
674
+        ];
675
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
676
+        if (empty($routineInfo)) {
677
+            return false;
678
+        }
679
+        $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
680
+
681
+        if ($appoint_money > 0) {
682
+            $alter_money = $appoint_money;
683
+        } else {
684
+            //再去查询变更前的 金额
685
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
686
+        }
687
+        if ($change_status == 1) {
688
+            //新增前
689
+            $alter_money = $alter_money - $money;
690
+        } else if ($change_status == 2) {
691
+            //减少前
692
+            $alter_money = $alter_money + $money;
693
+        }
694
+        if ($alter_money < 0) {
695
+            $alter_money = 0;
696
+        }
697
+        $inser_data = [];
698
+        $inser_data['user_id'] = $user_id;
699
+        $inser_data['type'] = $transition[$type];
700
+        $inser_data['change_status'] = $change_status;
701
+        $inser_data['money'] = $money;
702
+        $inser_data['routine_log_of_key_id'] = $key_id;
703
+        $inser_data['remark'] = $remark;
704
+        $inser_data['is_admin'] = $is_admin;
705
+        $inser_data['create_time'] = time();
706
+        $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
707
+        Db::name("old_user_log")->insert($inser_data);
708
+    }
709
+
710
+    //添加平台分佣2.0系统收益明细日志(养老金金额)
711
+    public function bill_user_log111111($uid, $name, $num, $mark, $comm)
712
+    {
713
+
714
+        $con_data = Db::name('user')->where("uid", $uid)->find();
715
+        //如果是会员专区就即刻到账
716
+
717
+        // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
718
+
719
+
720
+        $bill = [
721
+            'uid' => $uid,
722
+            'link_id' => 0,//关联订单id
723
+            'pm' => 1,//0:支出,1:获得
724
+            'title' => $name,//账单标题
725
+            'category' => 'now_money',//明细种类
726
+            'type' => 'commission',//明细类型
727
+            'number' => $num,//明细数字
728
+            'balance' => 0,//剩余
729
+            'mark' => $mark,//备注
730
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
731
+            'status' => 1,//0待确定,1有效,-1无效
732
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
733
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
734
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
735
+            'order_sn' => 0,//订单号
736
+            'tripartite' => 0,//
737
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
738
+            'mer_id' => 0,//商户id
739
+            'source' => 0,//1线下 0线上
740
+            'order_type' => 1,//1自营  2 第三方  订单类型
741
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
742
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
743
+            'take_time' => '',//结算时间
744
+            'district_id' => '',//
745
+            'street_id' => '',//
746
+            'month' => '',//月份
747
+
748
+
749
+        ];
750
+
751
+        Db::name('user_bill')->insert($bill);
752
+    }
753
+
754
+    //添加复购金
755
+    public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
756
+    {
757
+
758
+        $fugou_data = Db::name('user')->where("uid", $uid)->find();
759
+
760
+
761
+        $bill = [
762
+            'uid' => $uid,
763
+            'number' => $num,//数量
764
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
765
+            'mark' => "复购金",//备注
766
+            'desc' => "10%复购金",//描述
767
+            'order_id' => $order_id,//订单id
768
+            'surplus' => 0,//剩余
769
+            'order_type' => 11,//关联订单ID
770
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
771
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
772
+            'addtime' => time(),
773
+        ];
774
+
775
+        Db::name('user_sign_fugou')->insert($bill);
776
+    }
777
+}

+ 39 - 26
app/controller/api/store/merchant/Taskorderguquan.php

@@ -17,32 +17,32 @@ class Taskorderguquan
17 17
     public function assignment()
18 18
     {
19 19
         /**
20
-        8000元补贴下面人员
21
-        13231658486周行体1000
22
-        13333069689魏惠新1000
23
-        13959100621周金花500
24
-        13701061395李素红300
25
-        17501006833邢艳丽300
26
-        15631982690魏震洪400
27
-        18603401312黄金花400
28
-        13521438652徐立苹300
29
-        15832971815孟晓玮500
30
-        18600200909陈冠霖500
31
-        18001316701闫旭400
32
-        13811180929周京晨500
33
-        15810064711 王玲 300
34
-        15321221558李伟300
35
-        15373282785天一500
36
-        15232797965侯玉兰50
37
-        13601071082隋彩云100
38
-        13161909228刘银霞50
39
-        18760167163刘春梅50
40
-        13215917919李小秋50
41
-        18715313601大饼500
42
-
43
-        共计8000元
44
-
45
-        5.7万做股权,联创,合伙人分红
20
+         * 8000元补贴下面人员
21
+         * 13231658486周行体1000
22
+         * 13333069689魏惠新1000
23
+         * 13959100621周金花500
24
+         * 13701061395李素红300
25
+         * 17501006833邢艳丽300
26
+         * 15631982690魏震洪400
27
+         * 18603401312黄金花400
28
+         * 13521438652徐立苹300
29
+         * 15832971815孟晓玮500
30
+         * 18600200909陈冠霖500
31
+         * 18001316701闫旭400
32
+         * 13811180929周京晨500
33
+         * 15810064711 王玲 300
34
+         * 15321221558李伟300
35
+         * 15373282785天一500
36
+         * 15232797965侯玉兰50
37
+         * 13601071082隋彩云100
38
+         * 13161909228刘银霞50
39
+         * 18760167163刘春梅50
40
+         * 13215917919李小秋50
41
+         * 18715313601大饼500
42
+         *
43
+         * 共计8000元
44
+         *
45
+         * 5.7万做股权,联创,合伙人分红
46 46
          */
47 47
         $data = [
48 48
             '13231658486' => 1000,
@@ -765,6 +765,19 @@ class Taskorderguquan
765 765
             ->toArray();
766 766
         $removeUserIdList = array_column($removeUserList, 'uid');
767 767
 
768
+        $zeroLineUidList = [37];
769
+        foreach ($zeroLineUidList as $uid) {
770
+            //查询当前团队的用户列表
771
+            $sql = "select getUserLevelId($uid) as uids";
772
+            //\think\facade\Log::info("lplpDB".$sql);
773
+            try {
774
+                $spread_user_list = Db::query($sql);
775
+            } catch (\Exception $exception) {
776
+                return json($exception->getMessage());
777
+            }
778
+            $removeUserIdList = array_merge(explode(",", trim($spread_user_list[0]['uids'], '$,')), $removeUserIdList);
779
+        }
780
+
768 781
         if (empty($startTime) || empty($endTime)) {
769 782
             $timeMap = $this->getTime('last_week');
770 783
             $startTime = $timeMap['startTime'] . ' 00:00:00';

+ 14 - 0
app/controller/api/store/merchant/Taskorderlianc.php

@@ -294,6 +294,19 @@ class Taskorderlianc
294 294
             ->toArray();
295 295
         $removeUserIdList = array_column($removeUserList, 'uid');
296 296
 
297
+        $zeroLineUidList = [37];
298
+        foreach ($zeroLineUidList as $uid) {
299
+            //查询当前团队的用户列表
300
+            $sql = "select getUserLevelId($uid) as uids";
301
+            //\think\facade\Log::info("lplpDB".$sql);
302
+            try {
303
+                $spread_user_list = Db::query($sql);
304
+            } catch (\Exception $exception) {
305
+                return json($exception->getMessage());
306
+            }
307
+            $removeUserIdList = array_merge(explode(",", trim($spread_user_list[0]['uids'], '$,')), $removeUserIdList);
308
+        }
309
+
297 310
         if (empty($startTime) || empty($endTime)) {
298 311
             $timeMap = $this->getTime('last_week');
299 312
             $startTime = $timeMap['startTime'] . ' 00:00:00';
@@ -331,6 +344,7 @@ class Taskorderlianc
331 344
         $lianc_list_arr = array_column($lianc_list, null, 'id');
332 345
 
333 346
         $list = Db::name("user")
347
+            ->whereNotIn('uid', $removeUserIdList)
334 348
             ->where("originator_id_old", ">", 0)
335 349
             ->where("status", 1)
336 350
             ->field("uid,originator_id_old")

+ 1 - 1
cc.txt

@@ -1 +1 @@
1
-12
1
+123

+ 3 - 2
composer.json

@@ -17,7 +17,7 @@
17 17
         {
18 18
             "name": "yunwuxin",
19 19
             "email": "448901948@qq.com"
20
-        }        
20
+        }
21 21
     ],
22 22
     "require": {
23 23
         "php": ">=7.1.0",
@@ -48,7 +48,8 @@
48 48
         "phpoffice/phpspreadsheet": "^1.14",
49 49
         "phpseclib/phpseclib": "~3.0",
50 50
         "alibabacloud/client": "^1.5",
51
-        "maniac/easemob-php": "^1.0"
51
+        "maniac/easemob-php": "^1.0",
52
+        "phpmailer/phpmailer": "^6.9"
52 53
     },
53 54
     "require-dev": {
54 55
         "symfony/var-dumper": "^4.2"

+ 4 - 0
config/swoole.php

@@ -2,6 +2,10 @@
2 2
 
3 3
 use think\swoole\websocket\socketio\Parser;
4 4
 
5
+if (!extension_loaded('swoole')) {
6
+    return [];
7
+}
8
+
5 9
 return [
6 10
     'server'     => [
7 11
         'host'      => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址

+ 3 - 0
route/admin.php

@@ -455,6 +455,9 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
455 455
             Route::post('stock/update/:id', '/stockUpdate')->name('systemUserStockUpdate');
456 456
             Route::post('stock/create', '/stockCreate')->name('systemUserStockCreate');
457 457
             Route::delete('stock/delete/:id', '/stockDelete')->name('systemUserStockDelete');
458
+            Route::get('getZeroLineUserList', '/getZeroLineUserList')->name('systemGetZeroLineUserList');
459
+            Route::post('setZeroLineUser', '/setZeroLineUser')->name('systemSetZeroLineUser');
460
+            Route::get('getUserListByFuzzy', '/getUserListByFuzzy')->name('systemGetUserListByFuzzy');
458 461
 
459 462
         })->prefix('admin.user.User');
460 463
 

+ 2 - 0
route/api.php

@@ -1306,8 +1306,10 @@ Route::group('api/', function () {
1306 1306
     ->middleware(\app\common\middleware\CheckSiteOpenMiddleware::class);
1307 1307
 Route::get('/test/assignment', 'api.store.merchant.Taskorderguquan/assignment');
1308 1308
 Route::get('test_hehuoren', 'api.store.merchant.TaskPartnerProfits/partnerProfits');
1309
+Route::get('test_hehuoren_zero', 'api.store.merchant.TaskZeroLinePartnerProfits/partnerProfitsByZeroLine');
1309 1310
 Route::get('test_guquan', 'api.store.merchant.Taskorderguquan/lst6');
1310 1311
 Route::get('test_lianchuang', 'api.store.merchant.Taskorderlianc/lst2');
1312
+Route::get('test_lianchuang_zero', 'api.store.merchant.TaskZeroLineOrderLianc/lst2');
1311 1313
 Route::any('/share', function () {
1312 1314
     return view(app()->getRootPath() . 'public/share/register.html');
1313 1315
 });