diff --git a/app/admin/controller/Statistics.php b/app/admin/controller/Statistics.php index fddc515..1984ec9 100755 --- a/app/admin/controller/Statistics.php +++ b/app/admin/controller/Statistics.php @@ -1353,4 +1353,248 @@ class Statistics extends Base ]; } + /** + * 抽奖用户列表页面 + */ + public function lotteryUsers() + { + return View::fetch("Statistics/lotteryUsers"); + } + + /** + * 抽奖用户数据接口 + */ + public function lotteryUsersData() + { + $goodsId = input('goods_id', 0, 'intval'); + if(empty($goodsId)) { + return json(['code' => 1, 'msg' => '参数错误']); + } + + // 获取盒子信息 + $boxInfo = \app\common\model\Goods::where('id', $goodsId)->field('id,title')->find(); + + // 获取测试用户ID + $testUsers = \app\common\model\User::where('istest', '>', 0) + ->whereOr('status', '=', 2) + ->column('id'); + $testUserIds = empty($testUsers) ? [0] : $testUsers; + + // 构建分页查询 + $query = Db::name('order_list') + ->alias('ol') + ->join('user u', 'ol.user_id = u.id') + ->where('ol.goods_id', $goodsId) + ->where('ol.user_id', 'not in', $testUserIds) + ->field([ + 'ol.user_id', + 'u.nickname', + 'COUNT(DISTINCT ol.id) as lottery_count', + 'SUM(ol.goodslist_money) as output_value', + '0 as wx_payment', + '0 as diamond_payment' + ]) + ->group('ol.user_id') + ->order('lottery_count', 'desc') + ->paginate(input('limit', 20)) + ->toArray(); + + // 获取每个用户的支付信息 + if (!empty($query['data'])) { + $userIds = array_column($query['data'], 'user_id'); + + // 获取微信支付金额 + $wxPayments = Db::name('order') + ->where('goods_id', $goodsId) + ->where('user_id', 'in', $userIds) + ->where('price', '>', 0) + ->where('status', 1) + ->field('user_id, SUM(price) as payment') + ->group('user_id') + ->select() + ->toArray(); + + $wxPaymentMap = []; + foreach ($wxPayments as $payment) { + $wxPaymentMap[$payment['user_id']] = $payment['payment']; + } + + // 获取钻石支付金额 + $diamondPayments = Db::name('order') + ->where('goods_id', $goodsId) + ->where('user_id', 'in', $userIds) + ->where('use_money', '>', 0) + ->where('status', 1) + ->field('user_id, SUM(use_money) as payment') + ->group('user_id') + ->select() + ->toArray(); + + $diamondPaymentMap = []; + foreach ($diamondPayments as $payment) { + $diamondPaymentMap[$payment['user_id']] = $payment['payment']; + } + + // 更新用户支付信息 + foreach ($query['data'] as &$user) { + $user['wx_payment'] = isset($wxPaymentMap[$user['user_id']]) ? floatval($wxPaymentMap[$user['user_id']]) : 0; + $user['diamond_payment'] = isset($diamondPaymentMap[$user['user_id']]) ? floatval($diamondPaymentMap[$user['user_id']]) : 0; + $user['total_payment'] = $user['wx_payment'] + $user['diamond_payment']; + $user['output_value'] = floatval($user['output_value']); + } + } + + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'count' => $query['total'], + 'data' => $query['data'], + 'boxInfo' => $boxInfo + ]); + } + + /** + * 用户抽奖详情页面 + */ + public function userLotteryDetail() + { + return View::fetch("Statistics/userLotteryDetail"); + } + + /** + * 用户抽奖详情数据接口 + */ + public function userLotteryDetailData() + { + $goodsId = input('goods_id', 0, 'intval'); + $userId = input('user_id', 0, 'intval'); + + if(empty($goodsId) || empty($userId)) { + return json(['code' => 1, 'msg' => '参数错误']); + } + + // 获取用户和盒子信息 + $userInfo = \app\common\model\User::where('id', $userId)->field('id,nickname')->find(); + $boxInfo = \app\common\model\Goods::where('id', $goodsId)->field('id,title')->find(); + + if(!$userInfo || !$boxInfo) { + return json(['code' => 1, 'msg' => '用户或盒子不存在']); + } + + // 获取用户的抽奖记录 + $records = Db::name('order_list') + ->alias('ol') + ->leftJoin('goods_list gl', 'ol.goodslist_id = gl.id') + ->leftJoin('order o', 'ol.order_id = o.id') + ->where('ol.goods_id', $goodsId) + ->where('ol.user_id', $userId) + ->field([ + 'ol.id', + 'ol.addtime', + 'ol.goodslist_id', + 'gl.title as goodslist_title', + 'ol.goodslist_money', + 'ol.order_id', + 'o.price', + 'o.use_money', + 'ol.send_num', + 'CASE WHEN o.price > 0 THEN "wx" WHEN o.use_money > 0 THEN "diamond" ELSE "other" END as payment_type', + 'CASE WHEN o.price > 0 THEN o.price WHEN o.use_money > 0 THEN o.use_money ELSE 0 END as payment_amount', + 'IF(LENGTH(ol.send_num) > 0, 1, 0) as is_shipped' + ]) + ->order('ol.addtime', 'desc') + ->paginate(input('limit', 20)) + ->toArray(); + + // 获取用户抽奖汇总信息 + $summary = $this->getUserLotterySummaryData($goodsId, $userId); + + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'count' => $records['total'], + 'data' => $records['data'], + 'userInfo' => $userInfo, + 'boxInfo' => $boxInfo, + 'summary' => $summary + ]); + } + + /** + * 用户抽奖汇总数据 + */ + public function userLotterySummary() + { + $goodsId = input('goods_id', 0, 'intval'); + $userId = input('user_id', 0, 'intval'); + + if(empty($goodsId) || empty($userId)) { + return json(['code' => 1, 'msg' => '参数错误']); + } + + // 获取用户和盒子信息 + $userInfo = \app\common\model\User::where('id', $userId)->field('id,nickname')->find(); + $boxInfo = \app\common\model\Goods::where('id', $goodsId)->field('id,title')->find(); + + if(!$userInfo || !$boxInfo) { + return json(['code' => 1, 'msg' => '用户或盒子不存在']); + } + + // 获取用户抽奖汇总数据 + $data = $this->getUserLotterySummaryData($goodsId, $userId); + + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => $data, + 'userInfo' => $userInfo, + 'boxInfo' => $boxInfo + ]); + } + + /** + * 获取用户抽奖汇总数据 + */ + private function getUserLotterySummaryData($goodsId, $userId) + { + // 获取抽奖次数 + $totalCount = Db::name('order_list') + ->where('goods_id', $goodsId) + ->where('user_id', $userId) + ->count(); + + // 获取出货价值 + $totalOutput = Db::name('order_list') + ->where('goods_id', $goodsId) + ->where('user_id', $userId) + ->sum('goodslist_money'); + + // 获取微信支付金额 + $wxPayment = Db::name('order') + ->where('goods_id', $goodsId) + ->where('user_id', $userId) + ->where('price', '>', 0) + ->where('status', 1) + ->sum('price'); + + // 获取钻石支付金额 + $diamondPayment = Db::name('order') + ->where('goods_id', $goodsId) + ->where('user_id', $userId) + ->where('use_money', '>', 0) + ->where('status', 1) + ->sum('use_money'); + + // 总支付金额 + $totalPayment = $wxPayment + $diamondPayment; + + return [ + 'totalCount' => intval($totalCount), + 'totalOutput' => floatval($totalOutput), + 'wxPayment' => floatval($wxPayment), + 'diamondPayment' => floatval($diamondPayment), + 'totalPayment' => floatval($totalPayment) + ]; + } + } diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 4bb1129..977b981 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -432,6 +432,10 @@ Route::rule('statistics_productsOverview', 'Statistics/productsOverview', 'GET') Route::rule('statistics_getBoxStatistics', 'Statistics/getBoxStatistics', 'GET'); Route::rule('statistics_getSummaryStatistics', 'Statistics/getSummaryStatistics', 'GET'); Route::rule('statistics_exportProfit', 'Statistics/exportProfit', 'GET'); +Route::rule('statistics_lotteryUsers', 'Statistics/lotteryUsers', 'GET'); +Route::rule('statistics_userLotteryDetail', 'Statistics/userLotteryDetail', 'GET'); +Route::rule('statistics_userLotteryDetailData', 'Statistics/userLotteryDetailData', 'GET'); +Route::rule('statistics_lotteryUsersData', 'Statistics/lotteryUsersData', 'GET'); // 盒子下架日志相关路由 Route::post('goods_offshelf_read', 'GoodsOffshelfController/read'); diff --git a/app/admin/view/Statistics/lotteryUsers.html b/app/admin/view/Statistics/lotteryUsers.html new file mode 100644 index 0000000..3f46f44 --- /dev/null +++ b/app/admin/view/Statistics/lotteryUsers.html @@ -0,0 +1,67 @@ +{include file="Public:header3"/} + + +
+
+
+ 抽奖用户列表 + +
+
+
+
+
+
+ {include file="Public:footer3"/} + + + \ No newline at end of file diff --git a/app/admin/view/Statistics/profit.html b/app/admin/view/Statistics/profit.html index d68f9a3..3502ddf 100755 --- a/app/admin/view/Statistics/profit.html +++ b/app/admin/view/Statistics/profit.html @@ -111,6 +111,7 @@ @@ -318,7 +319,7 @@ return '
' + d.profit_rate.toFixed(2) + '%
'; } }, - { title: '操作', width: 110, toolbar: '#operationTpl', fixed: 'right' } + { title: '操作', width: 180, toolbar: '#operationTpl', fixed: 'right' } ]], done: function (res) { // 清空加载队列 @@ -562,6 +563,16 @@ area: ['90%', '90%'], content: '{:url("/admin/statistics_productsOverview")}?goods_id=' + data.id }); + } else if (obj.event === 'viewLotteryUsers') { + // 查看抽奖用户 + layer.open({ + type: 2, + title: data.title + ' - 抽奖用户列表', + shadeClose: false, + shade: 0.3, + area: ['90%', '90%'], + content: '{:url("/admin/statistics_lotteryUsers")}?goods_id=' + data.id + }); } }); diff --git a/app/admin/view/Statistics/userLotteryDetail.html b/app/admin/view/Statistics/userLotteryDetail.html new file mode 100644 index 0000000..d450484 --- /dev/null +++ b/app/admin/view/Statistics/userLotteryDetail.html @@ -0,0 +1,153 @@ +{include file="Public:header3"/} + + +
+
+
+ 用户抽奖详情 + + +
+
+ +
+
+
+
抽奖次数
+
+ 0 +
+
+
+
+
+
出货价值
+
+ ¥ 0.00 +
+
+
+
+
+
总支付金额
+
+ ¥ 0.00 +
+
+
+
+
+
微信/钻石支付
+
+ ¥ 0.00 / + ¥ 0.00 +
+
+
+
+ + +
+
+
+
+ {include file="Public:footer3"/} + + + + \ No newline at end of file