diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 179bdae..2a42b3a 100755 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -1711,21 +1711,18 @@ class Goods extends Base return $this->renderError('请求方式错误'); } - $id = $request->post('id/d'); - $url = $request->post('url/s'); - - // 验证URL格式 - if (!filter_var($url, FILTER_VALIDATE_URL)) { - return $this->renderError('URL格式不正确'); + $id = $request->post('id/d', 0); + if ($id == 0) { + $id = $request->post('goods_id/d', 0); } - - // 确保URL以/结尾 - if (substr($url, -1) !== '/') { - $url .= '/'; + + // 获取targets数组参数 + $targets = $request->post('targets/a', []); + + if (empty($targets)) { + return $this->renderError('同步目标URL不能为空'); } - $url .= 'api/goods/receive_sync'; - // 获取盒子数据 $goods = GoodsModel::where(['id' => $id])->find(); if (!$goods) { @@ -1771,42 +1768,88 @@ class Goods extends Base $postData['goodsExtend'] = $goodsExtend->toArray(); } - // 发送同步请求 - try { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Content-Length: ' . strlen(json_encode($postData)) - ]); + // 同步结果统计 + $results = [ + 'success' => [], + 'failed' => [] + ]; + $anySuccess = false; + $syncUrls = []; - $response = curl_exec($ch); - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - if ($status !== 200) { - return $this->renderError('同步失败,服务器返回状态码: ' . $status); + // 循环发送到每个目标URL + foreach ($targets as $target) { + // 验证URL格式 + if (!filter_var($target, FILTER_VALIDATE_URL)) { + $results['failed'][] = [ + 'url' => $target, + 'message' => 'URL格式不正确' + ]; + continue; } - $responseData = json_decode($response, true); - if (!$responseData || $responseData['code'] !== 1) { - $errorMsg = isset($responseData['msg']) ? $responseData['msg'] : '服务器未返回预期响应'; - return $this->renderError('同步失败: ' . $errorMsg); - } + // 确保URL格式正确 + $url = rtrim($target, '/') . '/api/goods_receive_sync?is_test=true'; + + // 发送同步请求 + try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置30秒超时 + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Content-Length: ' . strlen(json_encode($postData)) + ]); - // 更新同步状态 + $response = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($status !== 200) { + $results['failed'][] = [ + 'url' => $url, + 'message' => '服务器返回状态码: ' . $status + ]; + continue; + } + + $responseData = json_decode($response, true); + if (!$responseData || $responseData['code'] !== 1) { + $errorMsg = isset($responseData['msg']) ? $responseData['msg'] : '服务器未返回预期响应'; + $results['failed'][] = [ + 'url' => $url, + 'message' => $errorMsg + ]; + continue; + } + + // 记录成功URL + $results['success'][] = $url; + $syncUrls[] = $url; + $anySuccess = true; + + } catch (\Exception $e) { + $results['failed'][] = [ + 'url' => $url, + 'message' => $e->getMessage() + ]; + } + } + + // 如果有任何成功的同步,更新商品同步状态 + if ($anySuccess) { $goods->save([ 'sync_status' => 1, - 'sync_url' => $url, + 'sync_url' => implode(',', $syncUrls), 'sync_time' => date('Y-m-d H:i:s') ]); - - return $this->renderSuccess('同步成功'); - } catch (\Exception $e) { - return $this->renderError('同步失败: ' . $e->getMessage()); + + return $this->renderSuccess('同步完成:' . count($results['success']) . '个站点同步成功,' . + count($results['failed']) . '个站点同步失败', $results); + } else { + return $this->renderError('同步失败:所有目标站点同步均失败', $results); } } diff --git a/app/admin/controller/Statistics.php b/app/admin/controller/Statistics.php index 9402419..09e1cb8 100755 --- a/app/admin/controller/Statistics.php +++ b/app/admin/controller/Statistics.php @@ -430,7 +430,7 @@ class Statistics extends Base View::assign('ranges', $ranges); - + return View::fetch("Statistics/dataStand"); } @@ -1598,4 +1598,239 @@ class Statistics extends Base ]; } + /** + * 获取用户数据统计 + * @return \think\response\Json + */ + public function getUserStatisticsData() + { + // 用户注册人数 + $user_register_count = User::where('status', 1) + ->where('istest', 0) + ->where('mobile', '<>', '') + ->count(); + + // 消费人数 + $consuming_user_count = Db::query("SELECT COUNT(DISTINCT(user_id)) as count + FROM `order` ol + LEFT JOIN `user` us ON ol.user_id=us.id + WHERE us.status=1 AND us.istest=0"); + $consuming_user_count = isset($consuming_user_count[0]['count']) ? $consuming_user_count[0]['count'] : 0; + + // 用户货币统计 + $user_currency = Db::query("SELECT sum(money) as money, sum(money2) as money2, sum(integral) as integral + FROM `user` + WHERE status=1 AND istest=0"); + $user_money = isset($user_currency[0]['money']) ? round($user_currency[0]['money'], 2) : 0; + $user_money2 = isset($user_currency[0]['money2']) ? round($user_currency[0]['money2'], 2) : 0; + $user_integral = isset($user_currency[0]['integral']) ? round($user_currency[0]['integral'], 2) : 0; + + // 订单统计 + $order_stats = Db::query("SELECT sum(ol.price) as price, count(1) as c + FROM `order` ol + LEFT JOIN `user` us ON ol.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND ol.status=1"); + $order_price_total = isset($order_stats[0]['price']) ? round($order_stats[0]['price'], 2) : 0; + $order_total_count = isset($order_stats[0]['c']) ? $order_stats[0]['c'] : 0; + + // 盒柜剩余价值 + $box_remaining = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.status=0 AND oll.goodslist_type<3"); + $box_remaining_value = isset($box_remaining[0]['total']) ? round($box_remaining[0]['total'], 2) : 0; + + // 已兑换的达达券 + $exchanged = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.status=1 AND oll.goodslist_type<3"); + $exchanged_coupon = isset($exchanged[0]['total']) ? round($exchanged[0]['total']*100, 2) : 0; + + // 已发货金额 + $shipped = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.status=2 AND oll.goodslist_type<3"); + $shipped_amount = isset($shipped[0]['total']) ? round($shipped[0]['total'], 2) : 0; + + // 出货总金额 + $total_goods = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.goodslist_type<3"); + $total_goods_amount = isset($total_goods[0]['total']) ? round($total_goods[0]['total'], 2) : 0; + + // 返回JSON数据 + return json([ + 'code' => 0, + 'msg' => '获取数据成功', + 'data' => [ + 'user_register_count' => $user_register_count, + 'consuming_user_count' => $consuming_user_count, + 'user_money' => $user_money, + 'user_money2' => $user_money2, + 'user_integral' => $user_integral, + 'order_price_total' => $order_price_total, + 'order_total_count' => $order_total_count, + 'box_remaining_value' => $box_remaining_value, + 'exchanged_coupon' => $exchanged_coupon, + 'shipped_amount' => $shipped_amount, + 'total_goods_amount' => $total_goods_amount + ] + ]); + } + + /** + * 获取新的利润计算数据 + * @return \think\response\Json + */ + public function getProfitData() + { + // 当天收入:当日微信支付+当日钻石消费 + $today_income = Db::query("SELECT IFNULL(sum(ol.price),0)+IFNULL(sum(ol.use_money),0) as total + FROM `order` ol + LEFT JOIN `user` us ON ol.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND ol.status=1 + AND ol.pay_time>UNIX_TIMESTAMP(CURDATE())"); + $today_income = isset($today_income[0]['total']) ? round($today_income[0]['total'], 2) : 0; + + // 当日发货金额 + $today_shipped = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.status=2 + AND oll.goodslist_type<3 AND oll.choice_time>UNIX_TIMESTAMP(CURDATE())"); + $today_shipped = isset($today_shipped[0]['total']) ? round($today_shipped[0]['total'], 2) : 0; + + // 用户盒柜剩余 + $box_remaining = Db::query("SELECT sum(goodslist_money) as total + FROM order_list oll + LEFT JOIN `user` us ON oll.user_id=us.id + WHERE us.status=1 AND us.istest=0 AND oll.status=0 + AND oll.goodslist_type<3"); + $box_remaining = isset($box_remaining[0]['total']) ? round($box_remaining[0]['total'], 2) : 0; + + // 用户还剩多少达达券(查询出来后,需要除以100,达达券和emb的比例为100:1,1块钱兑换100rmb) + $remaining_coupon = Db::query("SELECT sum(money2) as money2 + FROM `user` + WHERE status=1 AND istest=0"); + $remaining_coupon = isset($remaining_coupon[0]['money2']) ? round($remaining_coupon[0]['money2'] / 100, 2) : 0; + + // 计算利润 + $profit = round($today_income - $today_shipped - $remaining_coupon - $box_remaining, 2); + + // 返回JSON数据 + return json([ + 'code' => 0, + 'msg' => '获取数据成功', + 'data' => [ + 'profit' => $profit, + 'today_income' => $today_income, + 'today_shipped' => $today_shipped, + 'remaining_coupon' => $remaining_coupon, + 'box_remaining' => $box_remaining, + 'formula' => "利润({$profit}) = 当天收入({$today_income}) - 当天发货金额({$today_shipped}) - 当天用户剩余达达券({$remaining_coupon}) - 盒柜剩余({$box_remaining})" + ] + ]); + } + + /** + * 获取用户注册相关数据 + * @return \think\response\Json + */ + public function getUserRegisterData() + { + // 获取测试用户ID列表 + $userList = User::where('istest', '>', 0)->field('id')->select(); + $userArray = array_column($userList->toArray(), 'id'); + + // 总注册人数 + $userCount = User::count("id"); + + // 设置时间范围 + $ranges = [ + // 今日时间 + 'today_start' => strtotime('today'), + 'today_end' => strtotime('tomorrow') - 1, + + // 昨日时间 + 'yesterday_start' => strtotime('yesterday'), + 'yesterday_end' => strtotime('today') - 1, + + // 本周时间(周一到周日) + 'this_week_start' => strtotime('monday this week'), + 'this_week_end' => strtotime('sunday this week') + 86399, + + // 上周时间(上周一到上周日) + 'last_week_start' => strtotime('monday last week'), + 'last_week_end' => strtotime('sunday last week') + 86399, + + // 本月时间(1号到月末) + 'this_month_start' => strtotime(date('Y-m-01')), + 'this_month_end' => strtotime(date('Y-m-t')) + 86399, + + // 上月时间(上个月1号到月末) + 'last_month_start' => strtotime(date('Y-m-01', strtotime('-1 month'))), + 'last_month_end' => strtotime(date('Y-m-t', strtotime('-1 month'))) + 86399 + ]; + + // 今日注册人数 + $user_today = User::whereBetweenTime('addtime', $ranges['today_start'], $ranges['today_end'])->count('id'); + + // 昨日注册人数 + $user_yesterday = User::whereBetweenTime('addtime', $ranges['yesterday_start'], $ranges['yesterday_end'])->count('id'); + + // 本周注册人数 + $user_this_week = User::whereBetweenTime('addtime', $ranges['this_week_start'], $ranges['this_week_end'])->count('id'); + + // 上周注册人数 + $user_last_week = User::whereBetweenTime('addtime', $ranges['last_week_start'], $ranges['last_week_end'])->count('id'); + + // 本月注册人数 + $user_this_month = User::whereBetweenTime('addtime', $ranges['this_month_start'], $ranges['this_month_end'])->count('id'); + + // 上月注册人数 + $user_last_month = User::whereBetweenTime('addtime', $ranges['last_month_start'], $ranges['last_month_end'])->count('id'); + + // 本日充值金额 + $order_today = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['today_start'], $ranges['today_end'])->sum('price'); + + // 昨日充值金额 + $order_yesterday = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['yesterday_start'], $ranges['yesterday_end'])->sum('price'); + + // 本周充值金额 + $order_this_week = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['this_week_start'], $ranges['this_week_end'])->sum('price'); + + // 上周充值金额 + $order_last_week = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['last_week_start'], $ranges['last_week_end'])->sum('price'); + + // 本月充值金额 + $order_this_month = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['this_month_start'], $ranges['this_month_end'])->sum('price'); + + // 上月充值金额 + $order_last_month = OrderModel::where('status', '=', 1)->whereNotIn('user_id', $userArray)->whereBetweenTime('addtime', $ranges['last_month_start'], $ranges['last_month_end'])->sum('price'); + + // 返回JSON数据 + return json([ + 'code' => 0, + 'msg' => '获取数据成功', + 'data' => [ + 'userCount' => $userCount, + 'user_today' => $user_today, + 'user_yesterday' => $user_yesterday, + 'user_this_week' => $user_this_week, + 'user_last_week' => $user_last_week, + 'user_this_month' => $user_this_month, + 'user_last_month' => $user_last_month, + 'order_today' => $order_today, + 'order_yesterday' => $order_yesterday, + 'order_this_week' => $order_this_week, + 'order_last_week' => $order_last_week, + 'order_this_month' => $order_this_month, + 'order_last_month' => $order_last_month + ] + ]); + } + } diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 977b981..32f3cf7 100755 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -436,7 +436,9 @@ 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::rule('Statistics/getUserStatisticsData', 'Statistics/getUserStatisticsData', 'GET'); +Route::rule('Statistics/getProfitData', 'Statistics/getProfitData', 'GET'); +Route::rule('Statistics/getUserRegisterData', 'Statistics/getUserRegisterData', 'GET'); // 盒子下架日志相关路由 Route::post('goods_offshelf_read', 'GoodsOffshelfController/read'); Route::get('goods_offshelf_unread_count', 'GoodsOffshelfController/getUnreadCount'); diff --git a/app/admin/view/Statistics/dataStand.html b/app/admin/view/Statistics/dataStand.html index b262e42..d889769 100755 --- a/app/admin/view/Statistics/dataStand.html +++ b/app/admin/view/Statistics/dataStand.html @@ -14,43 +14,45 @@
总注册人数: - - {$userCount} + + 加载中... +
-
+
+ +

正在加载数据...

+
+ -
@@ -199,6 +194,9 @@
今日收入汇总 +
@@ -238,20 +236,24 @@ - + - +
利润:{$order_lirun} +
+
+
+
利润计算方式:收入+其它收入-出货-支出=当日利润加载中...
-
+ + + +
+
+
+
+ 用户数据统计 + +
+
+
+ +

正在加载数据...

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
{include file="Public:footer"/} diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index fab8407..9e570ab 100755 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -1357,7 +1357,6 @@ class Notify extends Base $maxRand = (int) ($totalProbability * $multiple); $random = mt_rand(0, $maxRand) / $multiple; - // 查找中奖奖品 $prize_id = null; foreach ($probabilityRanges as $range) {