sunxbiao пре 1 година
родитељ
комит
e33b1b2ff9

+ 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
+}

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

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

+ 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")

+ 5 - 3
route/api.php

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