|
|
@@ -8,30 +8,38 @@ use think\facade\Db;
|
|
8
|
8
|
|
|
9
|
9
|
class TaskPartnerProfits
|
|
10
|
10
|
{
|
|
11
|
|
-
|
|
12
|
|
- public function getTeamPvByTime($timePeriod = 'last_week')
|
|
|
11
|
+ public function getTime($timePeriod)
|
|
13
|
12
|
{
|
|
14
|
13
|
// 定义时间区间
|
|
|
14
|
+ $now = time();
|
|
15
|
15
|
$startTime = '';
|
|
16
|
16
|
$endTime = '';
|
|
17
|
|
-
|
|
18
|
17
|
if ($timePeriod == 'last_week') {
|
|
19
|
18
|
// 上周的时间区间
|
|
20
|
|
- $startTime = '2025-03-17 00:00:00'; // 上周星期一的开始时间
|
|
21
|
|
- $endTime = '2025-03-23 23:59:59'; // 上周星期日的结束时间
|
|
|
19
|
+ $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
|
|
|
20
|
+ $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
|
|
22
|
21
|
} elseif ($timePeriod == 'this_week') {
|
|
23
|
22
|
// 这周的时间区间
|
|
24
|
|
- $startTime = '2025-02-17 00:00:00'; // 这周星期一的开始时间
|
|
25
|
|
- $endTime = '2025-02-23 23:59:59'; // 这周星期日的结束时间
|
|
26
|
|
- } else {
|
|
27
|
|
- return "Invalid time period specified.";
|
|
|
23
|
+ $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
|
|
|
24
|
+ $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
|
|
28
|
25
|
}
|
|
|
26
|
+// return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
|
|
|
27
|
+ return ['startTime' => $startTime, 'endTime' => $endTime];
|
|
|
28
|
+ }
|
|
|
29
|
+
|
|
|
30
|
+ public function getTeamPvByTime($timePeriod = 'last_week', $removeUserIdList = [])
|
|
|
31
|
+ {
|
|
|
32
|
+ $timeMap = $this->getTime($timePeriod);
|
|
|
33
|
+ $startTime = $timeMap['startTime'];
|
|
|
34
|
+ $endTime = $timeMap['endTime'];
|
|
29
|
35
|
|
|
30
|
36
|
// 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
|
|
31
|
37
|
$orders = Db::name("store_order")
|
|
|
38
|
+ ->where('mer_id', 496)
|
|
|
39
|
+ ->whereNotIn('uid', $removeUserIdList)
|
|
32
|
40
|
->whereIn('status', [0, 1, 2, 3])
|
|
33
|
41
|
->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
|
|
34
|
|
- ->whereBetween("pay_time", [$startTime, $endTime])
|
|
|
42
|
+ ->whereBetween("pay_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
|
|
35
|
43
|
->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
|
|
36
|
44
|
->select();
|
|
37
|
45
|
|
|
|
@@ -60,12 +68,49 @@ class TaskPartnerProfits
|
|
60
|
68
|
return $totalPv;
|
|
61
|
69
|
}
|
|
62
|
70
|
|
|
|
71
|
+ public function getRedEnvelopeByTime($timePeriod = 'last_week', $removeUserIdList = [])
|
|
|
72
|
+ {
|
|
|
73
|
+ $timeMap = $this->getTime($timePeriod);
|
|
|
74
|
+ $startTime = $timeMap['startTime'];
|
|
|
75
|
+ $endTime = $timeMap['endTime'];
|
|
|
76
|
+
|
|
|
77
|
+ // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
|
|
|
78
|
+ $redEnvelopeList = Db::name("user_sign_hongbao")
|
|
|
79
|
+ ->whereNotIn('uid', $removeUserIdList)
|
|
|
80
|
+ ->where('status', 1)
|
|
|
81
|
+ ->whereBetween("settlement_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
|
|
|
82
|
+ ->select()
|
|
|
83
|
+ ->toArray();
|
|
|
84
|
+ return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
63
|
87
|
public function partnerProfits()
|
|
64
|
88
|
{
|
|
65
|
|
-// $a = $this->getSpreadUserUidAccountListByUidList(1);
|
|
66
|
|
-// return json($a);
|
|
|
89
|
+ // 查询测试人员账号信息
|
|
|
90
|
+ //18973958920
|
|
|
91
|
+ //15186694339
|
|
|
92
|
+ //18833633835
|
|
|
93
|
+ //19525470098
|
|
|
94
|
+ //17756507016
|
|
|
95
|
+ //18226705337
|
|
|
96
|
+ $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
|
|
|
97
|
+ $removeUserList = Db::name("user")
|
|
|
98
|
+ ->whereIn('account', $testAccount)
|
|
|
99
|
+ ->where("status", "<>", 0)
|
|
|
100
|
+ ->where('is_del', '<>', 1)
|
|
|
101
|
+ ->select()
|
|
|
102
|
+ ->toArray();
|
|
|
103
|
+ $removeUserIdList = array_column($removeUserList, 'uid');
|
|
67
|
104
|
// 定义分红金额
|
|
68
|
|
- $weekRecord = $this->getTeamPvByTime('last_week');
|
|
|
105
|
+ $weekRecord = $this->getTeamPvByTime('last_week', $removeUserIdList);
|
|
|
106
|
+ // 分红金额 - 红包金额
|
|
|
107
|
+ $redEnvelope = $this->getRedEnvelopeByTime('last_week', $removeUserIdList);
|
|
|
108
|
+
|
|
|
109
|
+ $weekRecord -= $redEnvelope;
|
|
|
110
|
+ if ($weekRecord <= 0) {
|
|
|
111
|
+ return json('无效分红金额');
|
|
|
112
|
+ }
|
|
|
113
|
+
|
|
69
|
114
|
|
|
70
|
115
|
// 1、获取用户星级信息
|
|
71
|
116
|
//$star_list = Db::name("user_star")->order("statement_all_num desc")->select()->toArray();//旧星级等级
|
|
|
@@ -80,8 +125,10 @@ class TaskPartnerProfits
|
|
80
|
125
|
|
|
81
|
126
|
// 3、获取 分红用户 信息 (`user_group` tinyint(1) DEFAULT '1' COMMENT '1消费者 2,推广业务员 3,业务经理 4初级合伙人5中级合伙人 6高级合伙人 7.懂事',)
|
|
82
|
127
|
$list = Db::name("user")
|
|
|
128
|
+// ->whereNotIn('uid', $removeUserIdList)
|
|
83
|
129
|
->where("user_group", "IN", [4, 5, 6])
|
|
84
|
130
|
->where("status", "<>", 0)
|
|
|
131
|
+ ->where('is_del', '<>', 1)
|
|
85
|
132
|
->select()
|
|
86
|
133
|
->toArray();
|
|
87
|
134
|
|
|
|
@@ -98,29 +145,29 @@ class TaskPartnerProfits
|
|
98
|
145
|
|
|
99
|
146
|
// 5、移除特定人员
|
|
100
|
147
|
// 要移动的ID数组
|
|
101
|
|
- $ids_to_remove_from_junior = array(12, 69, 144); // 从初级中移除的ID
|
|
102
|
|
- $ids_to_remove_from_intermediate = array(49); // 从中级中移除的ID
|
|
103
|
|
- // 查找初级并获取其divider_people
|
|
104
|
|
- $junior = &$salesArr['初级']['divider_people']; // 使用引用,以便直接修改数组
|
|
105
|
|
- // 查找中级并获取其divider_people
|
|
106
|
|
- $intermediate = &$salesArr['中级']['divider_people']; // 使用引用,以便直接修改数组
|
|
107
|
|
- // 从初级的divider_people中移除特定的ID
|
|
108
|
|
- foreach ($ids_to_remove_from_junior as $id) {
|
|
109
|
|
- $key = array_search($id, $junior);
|
|
110
|
|
- if ($key !== false) {
|
|
111
|
|
- unset($junior[$key]); // 移除初级中的特定ID
|
|
112
|
|
- }
|
|
113
|
|
- }
|
|
114
|
|
- // 从中级的divider_people中移除特定的ID
|
|
115
|
|
- foreach ($ids_to_remove_from_intermediate as $id) {
|
|
116
|
|
- $key = array_search($id, $intermediate);
|
|
117
|
|
- if ($key !== false) {
|
|
118
|
|
- unset($intermediate[$key]); // 移除中级中的特定ID
|
|
119
|
|
- }
|
|
120
|
|
- }
|
|
121
|
|
- // 重置数组的索引,因为unset会留下空位
|
|
122
|
|
- $salesArr['初级']['divider_people'] = array_values($junior);
|
|
123
|
|
- $salesArr['中级']['divider_people'] = array_values($intermediate);
|
|
|
148
|
+// $ids_to_remove_from_junior = array(12, 69, 144); // 从初级中移除的ID
|
|
|
149
|
+// $ids_to_remove_from_intermediate = array(49); // 从中级中移除的ID
|
|
|
150
|
+// // 查找初级并获取其divider_people
|
|
|
151
|
+// $junior = &$salesArr['初级']['divider_people']; // 使用引用,以便直接修改数组
|
|
|
152
|
+// // 查找中级并获取其divider_people
|
|
|
153
|
+// $intermediate = &$salesArr['中级']['divider_people']; // 使用引用,以便直接修改数组
|
|
|
154
|
+// // 从初级的divider_people中移除特定的ID
|
|
|
155
|
+// foreach ($ids_to_remove_from_junior as $id) {
|
|
|
156
|
+// $key = array_search($id, $junior);
|
|
|
157
|
+// if ($key !== false) {
|
|
|
158
|
+// unset($junior[$key]); // 移除初级中的特定ID
|
|
|
159
|
+// }
|
|
|
160
|
+// }
|
|
|
161
|
+// // 从中级的divider_people中移除特定的ID
|
|
|
162
|
+// foreach ($ids_to_remove_from_intermediate as $id) {
|
|
|
163
|
+// $key = array_search($id, $intermediate);
|
|
|
164
|
+// if ($key !== false) {
|
|
|
165
|
+// unset($intermediate[$key]); // 移除中级中的特定ID
|
|
|
166
|
+// }
|
|
|
167
|
+// }
|
|
|
168
|
+// // 重置数组的索引,因为unset会留下空位
|
|
|
169
|
+// $salesArr['初级']['divider_people'] = array_values($junior);
|
|
|
170
|
+// $salesArr['中级']['divider_people'] = array_values($intermediate);
|
|
124
|
171
|
|
|
125
|
172
|
|
|
126
|
173
|
// 6、执行分开发放
|
|
|
@@ -151,8 +198,8 @@ class TaskPartnerProfits
|
|
151
|
198
|
$subordinatesBatch = $this->getSubordinatesBatch($spreadUserUidList[$v]);
|
|
152
|
199
|
// 6.2.3 获取所有部门(下线)的PV值
|
|
153
|
200
|
foreach ($subordinatesBatch as $k1 => $v1) {
|
|
154
|
|
- // 获取当前下线的PV值
|
|
155
|
|
- $pv = $this->getPv(array_merge($v1, [$k1]));
|
|
|
201
|
+ // 获取当前下线的PV值, 忽略测试人员的账号
|
|
|
202
|
+ $pv = $this->getPv(array_merge($v1, [$k1]), $removeUserIdList);
|
|
156
|
203
|
if (!empty($pv)) {
|
|
157
|
204
|
$partnerProfitsPvListByUid[$v][$k1] = $pv;
|
|
158
|
205
|
}
|
|
|
@@ -217,47 +264,46 @@ class TaskPartnerProfits
|
|
217
|
264
|
$fg_10 = $allAward * 0.1;
|
|
218
|
265
|
|
|
219
|
266
|
|
|
220
|
|
-// $userdatassss = db::name("old_user_jbp")->where("id", $v)->find();
|
|
221
|
|
-// $datas_log = [
|
|
222
|
|
-// 'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v . " 双联盟总业绩:" . $maxValueAll . " 我的双区业绩:" . $myBill . " 小区总业绩:" . $sumOfOthersAll . " 我的业绩小的:" . $userPvSmallNum[0] . " 可分红佣金:" . $amount . " 可分红总佣金:" . $fsMoneyNums . " 小区业绩可分红:" . $myMixMoney . " 大区业绩可分红:" . $myWeightMoney . " 实际分得:" . $yj_90,
|
|
223
|
|
-// 'create_time' => date('Y-m-d H:i:s')
|
|
224
|
|
-// ];
|
|
225
|
|
-// $con_data = Db::name('test_log')->insert($datas_log); //数据存到2.0数据表中
|
|
226
|
|
-//
|
|
227
|
|
-// # code...
|
|
228
|
|
-// $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
|
|
229
|
|
-//
|
|
230
|
|
-// Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
|
|
231
|
|
-// Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
|
|
232
|
|
-//
|
|
233
|
|
-// Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
|
|
234
|
|
-//
|
|
235
|
|
-//
|
|
236
|
|
-// //if($res) {
|
|
237
|
|
-// $this->change_user_log($v, 'amount_old', 1, $yj_90, "member_award", "星级分红入账" . "-" . $value['title']);//释放佣金
|
|
238
|
|
-// //入账星级分红记录表
|
|
239
|
|
-// $week_data = [];
|
|
240
|
|
-// $week_data['user_id'] = $v;
|
|
241
|
|
-// $week_data['user_star_id'] = $key;
|
|
242
|
|
-// $week_data['award_num'] = $myWeightMoney;
|
|
243
|
|
-// $week_data['award_num_sm'] = $myMixMoney;
|
|
244
|
|
-// $week_data['remark'] = "星级分红主动执行:" . $yj_90;
|
|
245
|
|
-// $week_data['week_record'] = $weekRecord;
|
|
246
|
|
-// $week_data['all_amount'] = $fsMoneyNums;
|
|
247
|
|
-// $week_data['radio'] = 2;
|
|
248
|
|
-// $week_data['owner_bill'] = $maxValueAll; //总流水金额
|
|
249
|
|
-// $week_data['my_bill'] = $myBill; //我的流水
|
|
250
|
|
-// $week_data['create_time'] = time();
|
|
251
|
|
-//
|
|
252
|
|
-// Db::name("old_user_weekaward")->insert($week_data);
|
|
253
|
|
-//
|
|
254
|
|
-// $this->bill_user_log111111($v, "合伙人分佣", $yj_90, "合伙人分佣明细入账", 11);//联创分佣明细2.0系统
|
|
255
|
|
-// $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
|
|
|
267
|
+ $userdatassss = db::name("old_user_jbp")->where("id", $v)->find();
|
|
|
268
|
+ $datas_log = [
|
|
|
269
|
+ 'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v . " 双联盟总业绩:" . $maxValueAll . " 我的双区业绩:" . $myBill . " 小区总业绩:" . $sumOfOthersAll . " 我的业绩小的:" . $userPvSmallNum[0] . " 可分红佣金:" . $amount . " 可分红总佣金:" . $fsMoneyNums . " 小区业绩可分红:" . $myMixMoney . " 大区业绩可分红:" . $myWeightMoney . " 实际分得:" . $yj_90,
|
|
|
270
|
+ 'create_time' => date('Y-m-d H:i:s')
|
|
|
271
|
+ ];
|
|
|
272
|
+ $con_data = Db::name('test_log')->insert($datas_log); //数据存到2.0数据表中
|
|
|
273
|
+
|
|
|
274
|
+ # code...
|
|
|
275
|
+ $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
|
|
|
276
|
+
|
|
|
277
|
+ Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
|
|
|
278
|
+ Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
|
|
|
279
|
+
|
|
|
280
|
+ Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
|
|
|
281
|
+
|
|
|
282
|
+
|
|
|
283
|
+ //if($res) {
|
|
|
284
|
+ $this->change_user_log($v, 'amount_old', 1, $yj_90, "member_award", "星级分红入账" . "-" . $value['title']);//释放佣金
|
|
|
285
|
+ //入账星级分红记录表
|
|
|
286
|
+ $week_data = [];
|
|
|
287
|
+ $week_data['user_id'] = $v;
|
|
|
288
|
+ $week_data['user_star_id'] = $key;
|
|
|
289
|
+ $week_data['award_num'] = $myWeightMoney;
|
|
|
290
|
+ $week_data['award_num_sm'] = $myMixMoney;
|
|
|
291
|
+ $week_data['remark'] = "星级分红主动执行:" . $yj_90;
|
|
|
292
|
+ $week_data['week_record'] = $weekRecord;
|
|
|
293
|
+ $week_data['all_amount'] = $fsMoneyNums;
|
|
|
294
|
+ $week_data['radio'] = 2;
|
|
|
295
|
+ $week_data['owner_bill'] = $maxValueAll; //总流水金额
|
|
|
296
|
+ $week_data['my_bill'] = $myBill; //我的流水
|
|
|
297
|
+ $week_data['create_time'] = time();
|
|
|
298
|
+
|
|
|
299
|
+ Db::name("old_user_weekaward")->insert($week_data);
|
|
|
300
|
+
|
|
|
301
|
+ $this->bill_user_log111111($v, "合伙人分佣", $yj_90, "合伙人分佣明细入账", 11);//联创分佣明细2.0系统
|
|
|
302
|
+ $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
|
|
256
|
303
|
}
|
|
257
|
304
|
|
|
258
|
305
|
}
|
|
259
|
306
|
return json($salesArr);
|
|
260
|
|
-
|
|
261
|
307
|
}
|
|
262
|
308
|
|
|
263
|
309
|
/**
|
|
|
@@ -466,8 +512,11 @@ class TaskPartnerProfits
|
|
466
|
512
|
}
|
|
467
|
513
|
|
|
468
|
514
|
// 获取用户PV值
|
|
469
|
|
- public function getPv($userIdList)
|
|
|
515
|
+ public function getPv($userIdList, $removeUserIdList = [])
|
|
470
|
516
|
{
|
|
|
517
|
+ if (!empty($removeUserIdList)) {
|
|
|
518
|
+ $userIdList = array_values(array_diff($userIdList, $removeUserIdList));
|
|
|
519
|
+ }
|
|
471
|
520
|
// 基础查询构建器
|
|
472
|
521
|
$user_team_amount = Db::name("old_user_of_goods")
|
|
473
|
522
|
->whereIn("user_id", $userIdList)
|
|
|
@@ -529,11 +578,10 @@ class TaskPartnerProfits
|
|
529
|
578
|
|
|
530
|
579
|
// 计算除去特定值后的总和
|
|
531
|
580
|
$otherMoneyRecords = [];
|
|
532
|
|
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
|
|
533
|
|
- $otherMoneyRecords = Db::name("old_user_of_goods")
|
|
534
|
|
- ->whereIn("user_id", $userIdList)
|
|
535
|
|
- ->whereNotIn('money', [1180, 11800, 10620, 9440, 2360])
|
|
536
|
|
- ->select();
|
|
|
581
|
+// $otherMoneyRecords = Db::name("old_user_of_goods")
|
|
|
582
|
+// ->whereIn("user_id", $userIdList)
|
|
|
583
|
+// ->whereNotIn('money', [1180, 11800, 10620, 9440, 2360])
|
|
|
584
|
+// ->select();
|
|
537
|
585
|
$otherMoneySum = 0;
|
|
538
|
586
|
foreach ($otherMoneyRecords as $record) {
|
|
539
|
587
|
$otherMoneySum += $record['money'];
|