From 910979ca65a506a6628a8036c07738c75f10b2d6 Mon Sep 17 00:00:00 2001 From: youda Date: Fri, 4 Jul 2025 15:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E7=BA=A7=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/User.php | 256 +++++++++++++++++++++++------ app/admin/route/app.php | 3 + app/admin/view/User/user_team.html | 236 +++++++++++++------------- 3 files changed, 332 insertions(+), 163 deletions(-) diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 8e99dd1..114fa93 100755 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -594,7 +594,7 @@ class User extends Base $v['tx_money'] = $tx_money; $v['profit_loss'] = $profit_loss; $v['lirun'] = $lirun; - $v['liruntips'] = '收入('.$shouru.')- 发货金额('.$fh_money.') - 用户剩余达达券('.$money2.') - 盒柜剩余('.$shang_money.' ) ;'; + $v['liruntips'] = '收入(' . $shouru . ')- 发货金额(' . $fh_money . ') - 用户剩余达达券(' . $money2 . ') - 盒柜剩余(' . $shang_money . ' ) ;'; $v['shouru'] = $shouru; $cz_money_total += $cz_yue; @@ -750,6 +750,8 @@ class User extends Base public function user_team(Request $request) { $id = $request->param('id'); + $addtime = $request->param('addtime'); + // 将UID转换为用户ID $id = $this->convertUidToUserId($id); // dd($id); @@ -772,14 +774,39 @@ class User extends Base $data['list'] = $list->toArray()['data']; $data['count'] = $list->total(); $data['page'] = $page; + $start_time = 0; + $end_time = 0; + if ($addtime) { + $addtime = explode(' - ', $addtime); + $start_time = strtotime($addtime[0]); + $end_time = strtotime($addtime[1]); + // $where[] = ['addtime', 'BETWEEN', [$start_time, $end_time]]; + } foreach ($data['list'] as &$value) { $value['total'] = ProfitMoney::where('type', 5) ->where('user_id', $id) ->where('share_uid', $value['id']) ->sum('change_money'); - // dd(); + $order_user_id = $value['id']; + // select IFNULL(sum(price),0) price,IFNULL(sum(use_money),0) use_money from `order` where user_id=23796 and status=1 addtime> 1745550000 and addtime<1746374399 ; + + // 订单统计查询 + $orderQuery = \app\common\model\Order::where('user_id', $value['id']) + ->where('status', 1); + + // 添加时间筛选条件 + if ($start_time > 0 && $end_time > 0) { + $orderQuery->where('addtime', 'between', [$start_time, $end_time]); + } + + // 执行查询并获取结果 + $orderStats = $orderQuery->field('IFNULL(sum(price),0) as price, IFNULL(sum(use_money),0) as use_money') + ->find(); + + $value['order_price'] = $orderStats['price']; + $value['order_use_money'] = $orderStats['use_money']; } - // dd($data['list']); + View::assign('list', $data['list']); View::assign('count', $data['count']); View::assign('page', $page); @@ -1521,7 +1548,7 @@ class User extends Base public function getUserProfitLoss() { $param = input(); - + // 构建查询条件 $where = []; $whereUser = 'u.status=1 and u.istest=0 and o.status=1'; @@ -1542,7 +1569,7 @@ class User extends Base $whereUser3 = " and addtime < {$end_time} "; } } - + // 处理用户ID/UID参数 if (!empty($param['uid'])) { $uid = trim($param['uid']); @@ -1559,9 +1586,9 @@ class User extends Base } } } - + // 构建SQL查询 - // 构建SQL查询 - 不应用分页限制,获取全部数据 + // 构建SQL查询 - 不应用分页限制,获取全部数据 $sql = "select c.* from ( select t.*, (CASE @@ -1583,28 +1610,28 @@ class User extends Base (TRUNCATE(IFNULL((SELECT money FROM profit_money2 where user_id=o.user_id {$whereUser1} order by id desc LIMIT 1),0)/100, 2)) sy_money FROM `order` o LEFT join `user` u ON o.user_id=u.id where {$whereUser} group by o.user_id ) t where use_money>0 ) c order by yue_money desc"; - //添加日志记录 - \think\facade\Log::info($sql); - + //添加日志记录 + \think\facade\Log::info($sql); + // 分页处理 $page = isset($param['page']) ? intval($param['page']) : 1; $limit = isset($param['limit']) ? intval($param['limit']) : 20; - + // 获取总记录数 $countSql = "SELECT COUNT(*) as count FROM ({$sql}) as temp"; $count = \think\facade\Db::query($countSql)[0]['count']; - + // 添加分页 $sql .= " LIMIT " . (($page - 1) * $limit) . ", {$limit}"; - + // 执行查询 $list = \think\facade\Db::query($sql); - + // 处理结果数据 foreach ($list as &$item) { // 处理图片URL $item['headimg'] = empty($item['headimg']) ? '' : imageUrl($item['headimg']); - + // 格式化数值 $item['money'] = floatval($item['money']); $item['integral'] = floatval($item['integral']); @@ -1616,12 +1643,12 @@ class User extends Base $item['fh_money'] = floatval($item['fh_money']); $item['bb_money'] = floatval($item['bb_money']); $item['yue_money'] = floatval($item['yue_money']); - + // 处理盈亏状态 $item['profit_status'] = $item['yue_money'] > 0 ? '亏损' : '盈利'; $item['profit_value'] = abs($item['yue_money']); } - + return json([ 'code' => 0, 'msg' => '', @@ -1636,7 +1663,7 @@ class User extends Base public function exportUserProfitLoss() { $param = input(); - + // 构建查询条件 $where = []; $whereUser = 'u.status=1 and u.istest=0 and o.status=1'; @@ -1657,7 +1684,7 @@ class User extends Base $whereUser3 = " and addtime < {$end_time} "; } } - + // 处理用户ID/UID参数 if (!empty($param['uid'])) { $uid = trim($param['uid']); @@ -1674,7 +1701,7 @@ class User extends Base } } } - + // 构建SQL查询 - 不应用分页限制,获取全部数据 $sql = "select c.* from ( select t.*, @@ -1697,18 +1724,18 @@ class User extends Base (TRUNCATE(IFNULL((SELECT money FROM profit_money2 where user_id=o.user_id {$whereUser1} order by id desc LIMIT 1),0)/100, 2)) sy_money FROM `order` o LEFT join `user` u ON o.user_id=u.id where {$whereUser} group by o.user_id ) t where use_money>0 ) c order by yue_money desc"; - + //添加日志记录 \think\facade\Log::info($sql); - + // 执行查询 $list = \think\facade\Db::query($sql); - + // 处理结果数据 foreach ($list as &$item) { // 处理图片URL $item['headimg'] = empty($item['headimg']) ? '' : imageUrl($item['headimg']); - + // 格式化数值 $item['money'] = floatval($item['money']); $item['integral'] = floatval($item['integral']); @@ -1720,22 +1747,22 @@ class User extends Base $item['fh_money'] = floatval($item['fh_money']); $item['bb_money'] = floatval($item['bb_money']); $item['yue_money'] = floatval($item['yue_money']); - + // 处理盈亏状态 $item['profit_status'] = $item['yue_money'] > 0 ? '亏损' : '盈利'; $item['profit_value'] = abs($item['yue_money']); } - + // 引入PHPExcel // ThinkPHP 6.0使用composer自动加载 if (!class_exists('\\PhpOffice\\PhpSpreadsheet\\Spreadsheet')) { return json(['code' => 1, 'msg' => '请先安装PhpSpreadsheet扩展']); } - + // 使用PhpSpreadsheet $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - + // 设置文档属性 $spreadsheet->getProperties() ->setCreator("系统") @@ -1743,7 +1770,7 @@ class User extends Base ->setTitle("用户盈亏列表") ->setSubject("用户盈亏列表") ->setDescription("用户盈亏列表导出数据"); - + // 设置表头 $headers = [ 'A' => '序号', @@ -1766,14 +1793,14 @@ class User extends Base 'R' => '亏损/盈利金额', // 'S' => '利润值' ]; - + foreach ($headers as $key => $val) { $sheet->setCellValue($key . '1', $val); // 设置表头单元格样式 $sheet->getStyle($key . '1')->getFont()->setBold(true); $sheet->getStyle($key . '1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); } - + // 写入数据 $row = 2; foreach ($list as $index => $item) { @@ -1796,7 +1823,7 @@ class User extends Base $sheet->setCellValue('Q' . $row, $item['profit_status']); $sheet->setCellValue('R' . $row, $item['profit_value']); $sheet->setCellValue('S' . $row, $item['yue_money']); - + // 为亏损和盈利设置不同颜色 if ($item['yue_money'] > 0) { // 亏损标红 @@ -1809,23 +1836,23 @@ class User extends Base $sheet->getStyle('R' . $row)->getFont()->getColor()->setARGB('FF008000'); // $sheet->getStyle('S' . $row)->getFont()->getColor()->setARGB('FF008000'); } - + $row++; } - + // 调整列宽 foreach ($headers as $key => $val) { $sheet->getColumnDimension($key)->setAutoSize(true); } - + // 设置sheet名称 $sheet->setTitle('用户盈亏列表'); - + // 输出Excel文件 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="用户盈亏列表_' . date('YmdHis') . '.xlsx"'); header('Cache-Control: max-age=0'); - + $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); exit; @@ -1839,7 +1866,7 @@ class User extends Base if (empty($uid)) { return 0; } - + // 如果是数字,可能是用户ID或UID if (is_numeric($uid)) { $user = \app\common\model\User::where('id', $uid)->whereOr('uid', $uid)->find(); @@ -1857,17 +1884,17 @@ class User extends Base public function getUserMoney2Records() { $param = input(); - + // 验证参数 if (empty($param['user_id'])) { return json(['code' => 1, 'msg' => '缺少用户ID参数']); } - + // 分页参数 $page = isset($param['page']) ? intval($param['page']) : 1; $limit = isset($param['limit']) ? intval($param['limit']) : 10; $offset = ($page - 1) * $limit; - + // 时间范围处理 $whereTime = ''; if (!empty($param['time_range'])) { @@ -1878,27 +1905,27 @@ class User extends Base $whereTime = " and addtime > {$start_time} and addtime < {$end_time}"; } } - + // 获取总记录数 $countSql = "SELECT COUNT(*) as count FROM profit_money2 WHERE user_id = :user_id {$whereTime}"; $count = \think\facade\Db::query($countSql, ['user_id' => $param['user_id']])[0]['count']; - + // 构建SQL查询并添加分页 $sql = "SELECT (change_money/100) change_money, (money/100) money, content, FROM_UNIXTIME(addtime) as addtime_fmt, addtime FROM profit_money2 WHERE user_id = :user_id {$whereTime} ORDER BY id desc LIMIT {$offset}, {$limit}"; - + // 执行查询 $list = \think\facade\Db::query($sql, ['user_id' => $param['user_id']]); - + // 处理数据,将达达券值转换为显示格式(乘以100) foreach ($list as &$item) { $item['change_money'] = floatval($item['change_money']) * 100; $item['money'] = floatval($item['money']) * 100; } - + return json([ 'code' => 0, 'msg' => '', @@ -1906,4 +1933,141 @@ class User extends Base 'data' => $list ]); } + + /** + * 导出团队用户列表到Excel + */ + public function exportUserTeam(Request $request) + { + $id = $request->param('id'); + $addtime = $request->param('addtime'); + + // 将UID转换为用户ID + $id = $this->convertUidToUserId($id); + + // 查询数据(不分页,获取全部) + $list = \app\common\model\User::where('pid', $id)->select(); + + $start_time = 0; + $end_time = 0; + if ($addtime) { + $addtime = explode(' - ', $addtime); + $start_time = strtotime($addtime[0]); + $end_time = strtotime($addtime[1]); + } + + // 处理数据 + foreach ($list as &$value) { + $value['total'] = ProfitMoney::where('type', 5) + ->where('user_id', $id) + ->where('share_uid', $value['id']) + ->sum('change_money'); + + // 订单统计查询 + $orderQuery = \app\common\model\Order::where('user_id', $value['id']) + ->where('status', 1); + + // 添加时间筛选条件 + if ($start_time > 0 && $end_time > 0) { + $orderQuery->where('addtime', 'between', [$start_time, $end_time]); + } + + // 执行查询并获取结果 + $orderStats = $orderQuery->field('IFNULL(sum(price),0) as price, IFNULL(sum(use_money),0) as use_money') + ->find(); + + $value['order_price'] = $orderStats['price']; + $value['order_use_money'] = $orderStats['use_money']; + + // 格式化时间 + // $value['addtime_format'] = date('Y-m-d H:i:s', $value['addtime']); + + // 处理状态 + $value['status_text'] = $value['status'] == 1 ? '正常' : '封号'; + } + + // 引入PHPExcel + if (!class_exists('\\PhpOffice\\PhpSpreadsheet\\Spreadsheet')) { + return json(['code' => 1, 'msg' => '请先安装PhpSpreadsheet扩展']); + } + + // 使用PhpSpreadsheet + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + // 设置文档属性 + $spreadsheet->getProperties() + ->setCreator("系统") + ->setLastModifiedBy("系统") + ->setTitle("下级用户列表") + ->setSubject("下级用户列表") + ->setDescription("下级用户列表导出数据"); + + // 设置表头 + $headers = [ + 'A' => '序号', + 'B' => '用户ID', + 'C' => 'UID', + 'D' => '手机号', + 'E' => '昵称', + 'F' => 'RMB消费', + 'G' => '钻石消费', + 'H' => '钻石', + 'I' => 'UU币', + 'J' => '达达卷', + 'K' => '佣金', + 'L' => '状态', + // 'M' => '时间' + ]; + + foreach ($headers as $key => $val) { + $sheet->setCellValue($key . '1', $val); + // 设置表头单元格样式 + $sheet->getStyle($key . '1')->getFont()->setBold(true); + $sheet->getStyle($key . '1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); + } + + // 写入数据 + $row = 2; + foreach ($list as $index => $item) { + $sheet->setCellValue('A' . $row, $index + 1); + $sheet->setCellValue('B' . $row, $item['id']); + $sheet->setCellValue('C' . $row, isset($item['uid']) ? $item['uid'] : $item['id']); + $sheet->setCellValue('D' . $row, $item['mobile']); + $sheet->setCellValue('E' . $row, $item['nickname']); + $sheet->setCellValue('F' . $row, $item['order_price']); + $sheet->setCellValue('G' . $row, $item['order_use_money']); + $sheet->setCellValue('H' . $row, $item['money']); + $sheet->setCellValue('I' . $row, $item['integral']); + $sheet->setCellValue('J' . $row, $item['money2']); + $sheet->setCellValue('K' . $row, $item['total']); + $sheet->setCellValue('L' . $row, $item['status_text']); + // $sheet->setCellValue('M' . $row, $item['addtime_format']); + + // 为不同状态设置不同颜色 + if ($item['status'] != 1) { + // 封号标红 + $sheet->getStyle('L' . $row)->getFont()->getColor()->setARGB('FFFF0000'); + } + + $row++; + } + + // 调整列宽 + foreach ($headers as $key => $val) { + $sheet->getColumnDimension($key)->setAutoSize(true); + } + + // 设置sheet名称 + $sheet->setTitle('下级用户列表'); + + // 输出Excel文件 + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="下级用户列表_' .$id.'_' . date('YmdHis') . '.xlsx"'); + header('Cache-Control: max-age=0'); + + $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer->save('php://output'); + exit; + } } diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 2b24297..8b917b7 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -36,6 +36,8 @@ Route::rule('chongzhi', 'User/chongzhi', 'GET|POST'); Route::rule('userdel', 'User/userdel', 'GET|POST'); Route::rule('usertest', 'User/usertest', 'GET|POST'); +Route::rule('user_exportUserTeam', 'User/exportUserTeam', 'GET|POST'); + Route::rule('user_profit_loss', 'User/user_profit_loss', 'GET|POST'); Route::rule('user_profit_loss_list', 'User/userProfitLossList', 'GET'); Route::rule('get_user_profit_loss', 'User/getUserProfitLoss', 'POST'); @@ -517,3 +519,4 @@ Route::rule('ff_products_status', 'FFProductsController/status', 'POST'); Route::rule('ff_products_hot', 'FFProductsController/hot', 'POST'); Route::rule('ff_products_new', 'FFProductsController/new', 'POST'); Route::rule('ff_products_recommend', 'FFProductsController/recommend', 'POST'); + diff --git a/app/admin/view/User/user_team.html b/app/admin/view/User/user_team.html index 0060c10..16db2f5 100755 --- a/app/admin/view/User/user_team.html +++ b/app/admin/view/User/user_team.html @@ -1,130 +1,132 @@ {include file="Public:header2"/} + -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+
+
+
- -
- -
- 共有数据: {$count}条 -
-
- - - - - - - - - - - - - - - - {volist name="list" id="vo" key="index"} - - - + + +
+ +
+ + - - - - - +
序号用户信息钻石UU币达达卷佣金状态时间
{$start_index + $index} -
-
-
-

真实ID:{$vo['id']}

-

UID:{:isset($vo['uid']) ? $vo['uid'] : $vo['id']}

-

{$vo['mobile']}

-

{$vo['nickname']}

-
+
+
+
-
{$vo['money']} - - {$vo['integral']} - - {$vo['money2']} - - {$vo['total']} - - - {if condition="$vo['status'] eq 1"} - - {else /} - + +
+ +
+ + 共有数据: {$count}条 +
+
+ + + + + + + + + + + + + + + + + {volist name="list" id="vo" key="index"} + + + + + + + + + + + + + + {/volist} + {if condition="empty($list)"} + + + {/if} - - - - - - {/volist} - {if condition="empty($list)"} - - - - {/if} - -
序号用户信息实际消费钻石UU币达达卷佣金状态时间
{$start_index + $index} +
+
+
+

真实ID:{$vo['id']}

+

UID:{:isset($vo['uid']) ? $vo['uid'] : + $vo['id']}

+

{$vo['mobile']}

+

{$vo['nickname']}

+
+
+
+

RMB消费:{$vo['order_price']}

+

+

钻石消费:{$vo['order_use_money']}

+
{$vo['money']} + + {$vo['integral']} + + {$vo['money2']} + + {$vo['total']} + + + {if condition="$vo['status'] eq 1"} + + {else /} + + {/if} + {$vo['addtime']|date="Y-m-d H:i:s"}
暂时没有数据!
{$vo['addtime']|date="Y-m-d H:i:s"}
暂时没有数据!
-
- {$page|raw} +
+
+ {$page|raw} +
-
-{include file="Public:footer"/} - + // 导出Excel函数 + function exportExcel() { + var addtime = $('#addtime').val(); + var id = $('input[name="id"]').val(); + // 构建URL并打开新窗口 + var url = '/admin/user_exportUserTeam?id=' + id; + if (addtime) { + url += '&addtime=' + encodeURIComponent(addtime); + } + window.location.href = url; + } + - - - - - + \ No newline at end of file